Azalea

Azalea 是一個基于 PHP7 下的 MVC 開發框架,源于早期 BPF 項目,經優化并由 C 語言重新實現成 PHP7 下的擴展,源代碼可訪問 https://github.com/hdwong/php-azalea

目錄


Azalea\Bootstrap <small>應用啟動類</small>
Azalea\Loader <small>裝載類</small>
Azalea\Config <small>配置類</small>
Azalea\Controller <small>控制器類</small>
Azalea\Request <small>請求類</small>
Azalea\Response <small>響應類</small>
Azalea\Session <small>會話類</small>
Azalea\Model <small>模塊類</small>
Azalea\ServiceModel <small>服務模塊類</small>
Azalea\Views <small>視圖類</small>
Azalea\Exception <small>異常類</small>


Azalea\RedisModel <small>node-beauty-redis 緩存服務模塊</small>
Azalea\LocationModel <small>node-beauty-location 地區信息服務模塊</small>
Azalea\MysqlModel <small>node-beauty-mysql 數據庫服務模塊</small>

命名空間全局常量

TIME


本次請求的開始時間戳

int Azalea\TIME

VERSION


Azalea 擴展的版本號

string Azalea\VERSION

命名空間全局方法

randomString


獲取隨機字符串

string randomString ( int $len [, stirng $type = null ] )
  • 參數
    $len - 隨機字符串長度
    $type - 隨機類型
隨機類型 模式 描述
10 <small>或</small> n <small>[0-9]</small> 數字
16 <small>[0-9a-f]</small> 十六進制字符
c <small>[a-zA-Z]</small> 英文字符
l <small>[a-z]</small> 小寫英文字符
ln <small>[0-9a-z]</small> 小寫英文字符和數字
u <small>[A-Z]</small> 大寫英文字符
un <small>[0-9A-Z]</small> 大寫英文字符和數字
<small>默認值</small> <small>[0-9a-zA-Z]</small> 英文字符和數字

隨機類型不區分大小寫,即 nN 都指隨機數字,lNLn 都是相同意思,盡管如此,建議都使用全小寫

  • 返回值
    隨機字符串

  • 范例

$string = Azalea\randomString(4);  // 生成 4 位隨即字符串,包含大小寫英文字符和數字
$string = Azalea\randomString(8, 'n');  // 生成 8 位隨機數字

url


獲取絕對路徑

string url ( string $url [, bool $includeHost = false ] )
  • 參數
    $url - 路徑
    $includeHost - 是否產生包含域名的路徑,默認為 false

  • 返回值
    絕對路徑

  • 范例

// 假設當前域名為 http://www.youmaibai.com/
$href = url('foo/bar', true);  // 返回 http://www.youmaibai.com/foo/bar

timer


獲取兩次調用之間的秒數

float timer ( void )

通常用于耗時檢查

  • 參數

  • 返回值
    與上次調用之間的秒數

如果是第一次調用則返回從接受請求到當前調用的總耗時

  • 范例
Azalea\timer();
// do something...
$diff = Azalea\timer();  // 返回耗時

env


獲取當前運行環境

string env ( void )

系統初始化時,可以由配置變量設置,如果未設置默認環境為 "WEB"

  • 參數

  • 返回值
    環境字符串

  • 范例

$environ = Azalea\env();  // 返回 "WEB"

ip


獲取當前請求的 IP 地址

string ip ( void )

該方法是通過 $_SERVER 超全局數組中的值來獲取,優先次序為:"HTTP_CLIENT_IP" > "HTTP_X_FORWARDED_FOR" > "REMOTE_ADDR"

// nginx 配置
proxy_set_header Client-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  • 參數

  • 返回值
    當前請求的 IP 地址字符串

如果為 CLI (命令行) 環境 的請求,將返回 "0.0.0.0"

  • 范例
$ip = Azalea\ip();  // 127.0.0.1
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容