亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > PHP > 正文

Zend Framework教程之Application用法實例詳解

2024-05-04 23:43:50
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了Zend Framework教程之Application用法,詳細分析了Zend_Application的功能,定義,參數含義及相關使用技巧,需要的朋友可以參考下

本文實例講述了Zend Framework教程之Application用法。分享給大家供大家參考,具體如下:

Zend_Application是Zend Framework的核心組件。Zend_Application為Zend Framework應用程序提供基本功能,是程序的入口點。它的主要功能有兩個:裝載配置PHP環境(包括自動加載),并引導應用程序。

通常情況下,通過配置選項配置Zend_Application構造器,但也可以完全使用自定義方法配置。以下是兩個使用用例。

Zend_Application配置選項

構造函數:

/**

* Constructor

*

* Initialize application. Potentially initializes include_paths, PHP

* settings, and bootstrap class.

*

* @param string $environment

* @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options

* @throws Zend_Application_Exception When invalid options are provided

* @return void

*/

public function __construct($environment, $options = null)

{

$this->_environment = (string) $environment;

require_once 'Zend/Loader/Autoloader.php';

$this->_autoloader = Zend_Loader_Autoloader::getInstance();

if (null !== $options) {

if (is_string($options)) {

$options = $this->_loadConfig($options);

} elseif ($options instanceof Zend_Config) {

$options = $options->toArray();

} elseif (!is_array($options)) {

throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');

}

$this->setOptions($options);

}

}

Zend_Application配置方法

1.使用配置文件

2.使用配置數組

常見配置選項

Option Description
phpSettings
用于配置php.ini選項,要求是數組,數組的鍵應該是選項的的key.

includePaths
把附加的路徑加入到include_path,要求是數組

autoloaderNamespaces
給Zend_Loader_Autoloader注冊附加命名空間,為數組

bootstrap
可以是設置bootstrap引導類的路徑的字符串,也可以是數組,數組元素要求為 'path' 和 'class'

注意:

選項名稱不區分大小寫。

Zend_Application的方法

Method Return Value Parameters Description
__construct(
$environment,
$options = null) Void
$environment:必填。 表示當前應用環境的String。

典型的字符串可能包括 "development", "testing", "qa", or "production",他們必須已經被定義。

對應于配置文件文件中相關章節。

$options:可選的,參數類型可能是:

String: 指定Zend_Config文件的配置路徑.$environment用于指定配置文件的哪一個章節

從1.10開始,可以設置多個配置文件路徑,然后會被合并成一個單一的配置文件。

這樣更靈活,便于重用。

在這種情況下的key是"config",其值是文件路徑數組。

注:可以是路徑字符串,或 array("config"=>array("/path1","/path2"[,...]));.

Array: 配置應用的關聯數組

Zend_Config:配置對象的實例

構造函數。 用于初始化配置對象。 實例化Zend_Loader_Autoloader。

通過傳遞給構造函數選項然后傳遞給setOptions()方法。

getEnvironment() String N/A
獲取環境配置

getAutoloader() Zend_Loader_Autoloader N/A
獲取Zend_Loader_Autoloader實例

setOptions(array $options) Zend_Application
$options:必填,要求是數組

所有選項都存儲在引用內部,并多次調用該方法來合并選項。

會根據選項生產對于的setter方法。

例如,選項“phpSettings”對應setPhpSettings()。

(選項名稱不區分大小寫。)

getOptions() Array N/A


hasOption($key) Boolean
$key: 判斷是發有指定的配置

key不區分大小寫。

getOption($key) Mixed
$key: 獲取指定的配置選項的值

key不區分大小寫。如果不存在返回NULL

setPhpSettings(array $settings, $prefix = '') Zend_Application
$settings:比填.PHPINI 的配置關聯數組.

$prefix:可選. 為選項添加前綴



setAutoloaderNamespaces(array $namespaces) Zend_Application
$namespaces:必填.

傳遞命名空間字符串數組,通過Zend_Loader_Autoloader實例注冊



setBootstrap($path, $class = null) Zend_Application
$path:必填.

可能是Zend_Application_Bootstrap_Bootstrapper實例,

自舉類路徑字符串,

格式為classname => filename的關聯數組,

或key為“class”和value為“path”的關聯數組。

$class:可選. 如果$path是字符串,$class 類名稱

getBootstrap() NULL|Zend_Application_Bootstrap_Bootstrapper N/A
獲取注冊的bootstrap實例.

bootstrap() Void N/A
調用 bootstrap的bootstrap()引導應用.

run() Void N/A
調用bootstrap的run()運行應用

配置舉例:

默認:

// Create application, bootstrap, and run

$application = new Zend_Application(

APPLICATION_ENV,

APPLICATION_PATH . '/configs/application.ini'

);

$application->bootstrap()

->run();

源代碼

class Zend_Application

{ /**

* Constructor

*

* Initialize application. Potentially initializes include_paths, PHP

* settings, and bootstrap class.

*

* @param string $environment

* @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options

* @throws Zend_Application_Exception When invalid options are provided

* @return void

*/

public function __construct($environment, $options = null)

{

$this->_environment = (string) $environment;

require_once 'Zend/Loader/Autoloader.php';

$this->_autoloader = Zend_Loader_Autoloader::getInstance();

if (null !== $options) {

if (is_string($options)) {

$options = $this->_loadConfig($options);

} elseif ($options instanceof Zend_Config) {

$options = $options->toArray();

} elseif (!is_array($options)) {

throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');

}

$this->setOptions($options);

}

}

/**

* Retrieve current environment

*

* @return string

*/

public function getEnvironment()

{

return $this->_environment;

}

/**

* Retrieve autoloader instance

*

* @return Zend_Loader_Autoloader

*/

public function getAutoloader()

{

return $this->_autoloader;

}

/**

* Set application options

*

* @param array $options

* @throws Zend_Application_Exception When no bootstrap path is provided

* @throws Zend_Application_Exception When invalid bootstrap information are provided

* @return Zend_Application

*/

public function setOptions(array $options)

{

if (!empty($options['config'])) {

if (is_array($options['config'])) {

$_options = array();

foreach ($options['config'] as $tmp) {

$_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));

}

$options = $this->mergeOptions($_options, $options);

} else {

$options = $this->mergeOptions($this->_loadConfig($options['config']), $options);

}

}

$this->_options = $options;

$options = array_change_key_case($options, CASE_LOWER);

$this->_optionKeys = array_keys($options);

if (!empty($options['phpsettings'])) {

$this->setPhpSettings($options['phpsettings']);

}

if (!empty($options['includepaths'])) {

$this->setIncludePaths($options['includepaths']);

}

if (!empty($options['autoloadernamespaces'])) {

$this->setAutoloaderNamespaces($options['autoloadernamespaces']);

}

if (!empty($options['autoloaderzfpath'])) {

$autoloader = $this->getAutoloader();

if (method_exists($autoloader, 'setZfPath')) {

$zfPath = $options['autoloaderzfpath'];

$zfVersion = !empty($options['autoloaderzfversion'])

? $options['autoloaderzfversion']

: 'latest';

$autoloader->setZfPath($zfPath, $zfVersion);

}

}

if (!empty($options['bootstrap'])) {

$bootstrap = $options['bootstrap'];

if (is_string($bootstrap)) {

$this->setBootstrap($bootstrap);

} elseif (is_array($bootstrap)) {

if (empty($bootstrap['path'])) {

throw new Zend_Application_Exception('No bootstrap path provided');

}

$path = $bootstrap['path'];

$class = null;

if (!empty($bootstrap['class'])) {

$class = $bootstrap['class'];

}

$this->setBootstrap($path, $class);

} else {

throw new Zend_Application_Exception('Invalid bootstrap information provided');

}

}

return $this;

}

/**

* Retrieve application options (for caching)

*

* @return array

*/

public function getOptions()

{

return $this->_options;

}

/**

* Is an option present?

*

* @param string $key

* @return bool

*/

public function hasOption($key)

{

return in_array(strtolower($key), $this->_optionKeys);

}

/**

* Retrieve a single option

*

* @param string $key

* @return mixed

*/

public function getOption($key)

{

}

/**

* Merge options recursively

*

* @param array $array1

* @param mixed $array2

* @return array

*/

public function mergeOptions(array $array1, $array2 = null)

{

if (is_array($array2)) {

foreach ($array2 as $key => $val) {

if (is_array($array2[$key])) {

$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))

? $this->mergeOptions($array1[$key], $array2[$key])

: $array2[$key];

} else {

$array1[$key] = $val;

}

}

}

return $array1;

}

/**

* Set PHP configuration settings

*

* @param array $settings

* @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)

* @return Zend_Application

*/

public function setPhpSettings(array $settings, $prefix = '')

{

foreach ($settings as $key => $value) {

$key = empty($prefix) ? $key : $prefix . $key;

if (is_scalar($value)) {

ini_set($key, $value);

} elseif (is_array($value)) {

$this->setPhpSettings($value, $key . '.');

}

}

return $this;

}

/**

* Set include path

*

* @param array $paths

* @return Zend_Application

*/

public function setIncludePaths(array $paths)

{

$path = implode(PATH_SEPARATOR, $paths);

set_include_path($path . PATH_SEPARATOR . get_include_path());

return $this;

}

/**

* Set autoloader namespaces

*

* @param array $namespaces

* @return Zend_Application

*/

public function setAutoloaderNamespaces(array $namespaces)

{

$autoloader = $this->getAutoloader();

foreach ($namespaces as $namespace) {

$autoloader->registerNamespace($namespace);

}

return $this;

}

/**

* Set bootstrap path/class

*

* @param string $path

* @param string $class

* @return Zend_Application

*/

public function setBootstrap($path, $class = null)

{

// setOptions() can potentially send a null value; specify default

// here

if (null === $class) {

$class = 'Bootstrap';

}

if (!class_exists($class, false)) {

require_once $path;

if (!class_exists($class, false)) {

throw new Zend_Application_Exception('Bootstrap class not found');

}

}

$this->_bootstrap = new $class($this);

if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {

throw new Zend_Application_Exception('Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper');

}

return $this;

}

/**

* Get bootstrap object

*

* @return Zend_Application_Bootstrap_BootstrapAbstract

*/

public function getBootstrap()

{

if (null === $this->_bootstrap) {

$this->_bootstrap = new Zend_Application_Bootstrap_Bootstrap($this);

}

return $this->_bootstrap;

}

/**

* Bootstrap application

*

* @param null|string|array $resource

* @return Zend_Application

*/

public function bootstrap($resource = null)

{

$this->getBootstrap()->bootstrap($resource);

return $this;

}

/**

* Run the application

*

* @return void

*/

public function run()

{

$this->getBootstrap()->run();

}

/**

* Load configuration file of options

*

* @param string $file

* @throws Zend_Application_Exception When invalid configuration file is provided

* @return array

*/

protected function _loadConfig($file)

{

$environment = $this->getEnvironment();

$suffix = pathinfo($file, PATHINFO_EXTENSION);

$suffix = ($suffix === 'dist')

? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)

: $suffix;

switch (strtolower($suffix)) {

case 'ini':

$config = new Zend_Config_Ini($file, $environment);

break;

case 'xml':

$config = new Zend_Config_Xml($file, $environment);

break;

case 'json':

$config = new Zend_Config_Json($file, $environment);

break;

case 'yaml':

case 'yml':

$config = new Zend_Config_Yaml($file, $environment);

break;

case 'php':

case 'inc':

$config = include $file;

if (!is_array($config)) {

throw new Zend_Application_Exception('Invalid configuration file provided; PHP file does not return array value');

}

return $config;

break;

default:

throw new Zend_Application_Exception('Invalid configuration file provided; unknown config type');

}

return $config->toArray();

}

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲精品乱码久久久久久金桔影视| 欧美成人免费va影院高清| 欧美一区二区三区图| 欧美成人免费va影院高清| 亚洲天堂av在线免费| 欧美日韩第一视频| 亚洲国产女人aaa毛片在线| 日韩不卡在线观看| 亚洲欧美日韩图片| 日韩在线观看免费全集电视剧网站| 国产美女久久久| 成人夜晚看av| 26uuu日韩精品一区二区| 97婷婷涩涩精品一区| 色婷婷综合成人av| 国产91对白在线播放| 91在线高清视频| 国产成人精品久久久| 国产精品99久久久久久白浆小说| 日本国产欧美一区二区三区| 欧美成年人视频网站欧美| 精品亚洲夜色av98在线观看| 亚洲精品乱码久久久久久金桔影视| 欧美老妇交乱视频| 亚洲网站在线观看| 欧美性猛交xxxx偷拍洗澡| 亚洲少妇中文在线| 亚洲性69xxxbbb| 日韩成人av在线| 国产一区二区三区在线播放免费观看| 在线视频欧美日韩精品| 日韩中文字幕免费看| 日韩av在线网| 日韩专区中文字幕| 亚洲高清在线观看| 欧美理论电影网| 少妇高潮 亚洲精品| 欧洲亚洲妇女av| 久久久av一区| xvideos成人免费中文版| 亚洲毛片一区二区| 岛国av午夜精品| 欧美日韩国产二区| 亚洲人成在线免费观看| 亚洲精品国产品国语在线| 欧美在线视频观看| 4388成人网| 欧美人与性动交a欧美精品| 这里只有精品久久| 国产精品视频公开费视频| 国产精品免费福利| 亚洲精品美女久久久| 日韩在线视频一区| 性日韩欧美在线视频| 国产精品丝袜一区二区三区| 黑人精品xxx一区一二区| 91热福利电影| 国产精品成人av性教育| 大胆欧美人体视频| 永久免费毛片在线播放不卡| 91wwwcom在线观看| 国产女人精品视频| 日本高清久久天堂| 中文字幕日韩免费视频| 久久精品91久久久久久再现| 久久精品中文字幕免费mv| 亚州国产精品久久久| 色婷婷av一区二区三区在线观看| 8x拔播拔播x8国产精品| 亚洲一区二区中文字幕| 欧美中文字幕精品| 色天天综合狠狠色| 亚洲欧美在线第一页| 久久久久久伊人| 欧美成人精品一区| 亚洲天堂精品在线| 欧美日韩国产精品一区二区不卡中文| 26uuu另类亚洲欧美日本老年| 亚洲女同性videos| 亚洲天堂男人天堂| 精品欧美一区二区三区| 97视频网站入口| 91精品国产九九九久久久亚洲| 亚洲欧美国产精品专区久久| 亚洲男人av电影| 北条麻妃久久精品| 欧美激情亚洲精品| 中文字幕av一区二区| 国产精品高潮呻吟久久av黑人| 久久久久久久电影一区| 欧美电影在线免费观看网站| 日韩电影免费观看在线观看| 欧美精品久久久久a| 国产精品久久久久久亚洲影视| 欧美高清在线播放| 国产一区二区三区丝袜| 亚洲欧美激情四射在线日| 成人精品一区二区三区电影免费| 疯狂做受xxxx高潮欧美日本| 美女视频黄免费的亚洲男人天堂| 日本道色综合久久影院| 国产免费久久av| 久久影院在线观看| 亚洲www在线| 亚洲精品一区中文| 亚洲一区二区久久久久久久| 91久久久久久久久久久| 欧美激情影音先锋| 性金发美女69hd大尺寸| 欧美激情在线观看视频| 国外成人在线直播| 日韩国产在线看| 久久久久国产一区二区三区| 少妇av一区二区三区| 亚洲香蕉伊综合在人在线视看| 日韩av片免费在线观看| 国产精品99导航| 欧美精品第一页在线播放| 日韩亚洲综合在线| 国产精品自拍偷拍| 精品电影在线观看| 91久久国产综合久久91精品网站| 国产成人激情小视频| 色噜噜狠狠狠综合曰曰曰88av| 日韩一级黄色av| 欧美成人免费全部| 日韩av电影免费观看高清| 亚洲精品av在线| 欧美激情一区二区三区久久久| 2020久久国产精品| 97在线看免费观看视频在线观看| 国产成人久久久| 亚洲男女自偷自拍图片另类| 亚洲在线免费视频| 欧美国产精品人人做人人爱| 亚洲电影免费观看高清完整版在线观看| 一区二区三区在线播放欧美| 日韩欧美视频一区二区三区| 亚洲欧美一区二区精品久久久| 亚洲欧美精品伊人久久| 亚洲一区二区三区sesese| 久久久久久久久久久久av| 欧美专区中文字幕| 国产丝袜一区二区| 亚洲国产精品99| 亚洲国产美女精品久久久久∴| 欧美日韩亚洲激情| 国产精品久久久久久久久久三级| 久久久久久亚洲精品中文字幕| 亚洲综合色激情五月| 日韩av一区在线| 国产精品偷伦视频免费观看国产| 日韩视频免费观看| 国产亚洲精品久久久久久牛牛| 国产精品久久久久久久久久小说| 国产精品视频一区二区三区四| 日韩精品日韩在线观看| 久久精品国产一区| 热久久这里只有精品| 亚洲国产精品成人精品| 欧美国产日韩一区二区三区| 午夜免费日韩视频| 国产精品一区久久| 在线成人免费网站|