Zend Framework教程之Application用法实例详解,zendframework_PHP教程
Zend Framework教程之Application用法实例详解,zendframework
本文实例讲述了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 |
|
构造函数。 用于初始化配置对象。 实例化Zend_Loader_Autoloader。 通过传递给构造函数选项然后传递给setOptions()方法。 |
getEnvironment() | String | N/A |
获取环境配置 |
getAutoloader() | Zend_Loader_Autoloader | N/A |
获取Zend_Loader_Autoloader实例 |
setOptions(array $options) | Zend_Application |
|
所有选项都存储在引用内部,并多次调用该方法来合并选项。 会根据选项生产对于的setter方法。 例如,选项“phpSettings”对应setPhpSettings()。 (选项名称不区分大小写。) |
getOptions() | Array | N/A |
|
hasOption($key) | Boolean |
|
key不区分大小写。 |
getOption($key) | Mixed |
|
key不区分大小写。如果不存在返回 NULL |
setPhpSettings(array $settings, $prefix = '') | Zend_Application |
|
|
setAutoloaderNamespaces(array $namespaces) | Zend_Application |
|
|
setBootstrap($path, $class = null) | Zend_Application |
|
|
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();
源代码
<?php 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(); } }
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- Zend Framework自定义Helper类相关注意事项总结
- Zend Framework教程之Bootstrap类用法概述
- Zend Framework教程之资源(Resources)用法实例详解
- Zend Framework教程之Application和Bootstrap用法详解
- Zend Framework教程之配置文件application.ini解析
- Zend Framework教程之Loader以及PluginLoader用法详解
- Zend Framework教程之Autoloading用法详解
- Zend Framework教程之Resource Autoloading用法实例
- Zend Framework教程之MVC框架的Controller用法分析
- Zend Framework教程之路由功能Zend_Controller_Router详解
- Zend Framework教程之Zend_Controller_Plugin插件用法详解
- Zend Framework教程之响应对象的封装Zend_Controller_Response实例详解
- Zend Framework教程之动作的基类Zend_Controller_Action详解
- Zend Framework教程之前端控制器Zend_Controller_Front用法详解

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

.NET Framework 4 est requis par les développeurs et les utilisateurs finaux pour exécuter les dernières versions des applications sous Windows. Cependant, lors du téléchargement et de l'installation de .NET Framework 4, de nombreux utilisateurs se sont plaints de l'arrêt du programme d'installation à mi-chemin, affichant le message d'erreur suivant : « .NET Framework 4 n'a pas été installé car le téléchargement a échoué avec le code d'erreur 0x800c0006 ». Si vous le rencontrez également lors de l'installation de .NETFramework4 sur votre appareil, vous êtes au bon endroit

Chaque fois que votre PC Windows 11 ou Windows 10 rencontre un problème de mise à niveau ou de mise à jour, vous verrez généralement un code d'erreur indiquant la raison réelle de l'échec. Cependant, une confusion peut parfois survenir lorsqu'une mise à niveau ou une mise à jour échoue sans qu'un code d'erreur ne s'affiche. Grâce à des codes d'erreur pratiques, vous savez exactement où se situe le problème afin que vous puissiez essayer de le résoudre. Mais comme aucun code d’erreur n’apparaît, il devient difficile d’identifier le problème et de le résoudre. Cela prendra beaucoup de temps pour simplement découvrir la raison de l'erreur. Dans ce cas, vous pouvez essayer d'utiliser un outil dédié appelé SetupDiag fourni par Microsoft qui vous aide à identifier facilement la véritable raison de l'erreur.
![SCNotification a cessé de fonctionner [5 étapes pour y remédier]](https://img.php.cn/upload/article/000/887/227/168433050522031.png?x-oss-process=image/resize,m_fill,h_207,w_330)
En tant qu'utilisateur Windows, vous rencontrerez probablement une erreur SCNotification a cessé de fonctionner à chaque démarrage de votre ordinateur. SCNotification.exe est un fichier de notification système Microsoft qui plante à chaque démarrage de votre PC en raison d'erreurs d'autorisation et de pannes de réseau. Cette erreur est également connue sous son nom d’événement problématique. Vous ne verrez donc peut-être pas cela comme un arrêt de SCNotification, mais comme un bug clr20r3. Dans cet article, nous explorerons toutes les étapes à suivre pour réparer SCNotification a cessé de fonctionner afin qu'il ne vous dérange plus. Qu'est-ce que SCNotification.e

Les utilisateurs de Microsoft Windows qui ont installé Microsoft.NET version 4.5.2, 4.6 ou 4.6.1 doivent installer une version plus récente de Microsoft Framework s'ils souhaitent que Microsoft prenne en charge le framework via de futures mises à jour de produit. Selon Microsoft, les trois frameworks cesseront de prendre en charge le 26 avril 2022. Une fois la date de support terminée, le produit ne recevra plus de « correctifs de sécurité ni de support technique ». La plupart des appareils domestiques sont tenus à jour grâce aux mises à jour Windows. Ces appareils disposent déjà de versions plus récentes de frameworks, telles que .NET Framework 4.8. Les appareils qui ne se mettent pas à jour automatiquement peuvent

Cela fait une semaine que nous parlions du nouveau bug du mode sans échec affectant les utilisateurs ayant installé KB5012643 pour Windows 11. Ce problème embêtant n'apparaissait pas sur la liste des problèmes connus publiée par Microsoft le jour du lancement, prenant ainsi tout le monde par surprise. Eh bien, juste au moment où vous pensiez que les choses ne pourraient pas empirer, Microsoft lâche une autre bombe pour les utilisateurs qui ont installé cette mise à jour cumulative. Windows 11 Build 22000.652 pose davantage de problèmes. La société de technologie avertit donc les utilisateurs de Windows 11 qu'ils pourraient rencontrer des problèmes lors du lancement et de l'utilisation de certaines applications .NET Framework 3.5. Cela vous semble familier ? Mais s'il te plaît, ne sois pas surpris

Comment utiliser l'ACL (AccessControlList) pour le contrôle des autorisations dans Zend Framework Introduction : Dans une application Web, le contrôle des autorisations est une fonction cruciale. Il garantit que les utilisateurs ne peuvent accéder qu'aux pages et fonctionnalités auxquelles ils sont autorisés à accéder et empêche tout accès non autorisé. Le framework Zend fournit un moyen pratique d'implémenter le contrôle des autorisations, en utilisant le composant ACL (AccessControlList). Cet article explique comment utiliser l'ACL dans Zend Framework.

Framework d'implémentation PHP : tutoriel d'introduction à ZendFramework ZendFramework est un framework de site Web open source développé par PHP et actuellement maintenu par ZendTechnologies. ZendFramework adopte le modèle de conception MVC et fournit une série de bibliothèques de code réutilisables pour servir l'implémentation d'applications Web2.0 et Web Serve. ZendFramework est très populaire et respecté par les développeurs PHP et propose une large gamme de

Selon les informations du 9 décembre, Cooler Master a récemment présenté un mini kit de châssis en coopération avec le fournisseur de solutions modulaires pour ordinateurs portables Framework lors d'un événement de démonstration au Taipei Compute Show. La particularité de ce kit est qu'il peut être compatible et installer la carte mère. à partir du cahier-cadre. Actuellement, ce produit a commencé à être vendu sur le marché, au prix de 39 dollars américains, ce qui équivaut à environ 279 yuans au taux de change actuel. Le numéro de modèle de ce kit de châssis est nommé « frameWORKMAINBOARDCASE ». En termes de design, il incarne le summum de la compacité et de la praticité, mesurant seulement 297x133x15 mm. Sa conception originale est de pouvoir se connecter de manière transparente aux notebooks framework
