繁体   English   中英

Zend Framework项目不使用Zend_Application

[英]Zend Framework project without using Zend_Application

我一直在阅读上的许多网站 ,甚至在这里 ,为了提高Zend Framework的应用程序的性能是不使用Zend_Application的引导,但一直没能找到有此表现出了现场。

你们知道有一个地方有这个方法描述,可能会提供一些代码示例吗?

谢谢

我把它扔到了一起:

https://gist.github.com/2822456

转载如下以完成。 没有经过测试,只是我认为它(!)的一些想法可能会起作用。 现在我已经了解了一下,我对Zend_Application,它的引导类以及可配置/可重用的应用程序资源有了更多的了解。 ;-)

// Do your PHP settings like timezone, error reporting
// ..

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/_zf/application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

// Get autoloading in place
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// Any additional configs to autoloader, like custom autoloaders

// Read config
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);

// bootstrap resources manually:
// * create db adapter
// * create resource autoloaders with the mappings you need
// * etc

// Get the singleton front controller
$front = Zend_Controller_Front::getInstance();

// Set controller directory
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');

// Or set module directory
$front->setModuleDirectory(APPLICATION_PATH . '/modules');

// Other front config, like throw exceptions, etc.
// ...
// 
// Create a router
$router = new Zend_Controller_Router_Rewrite();

// Add routes to the router
$router->addRoute('myRoute', new Zend_Controller_Router_Route(array(
    // your routing params
)));
// More routes...
// Alternatively, the routes can all be in an xml or ini file and you can add 
// them all at once.

// Tell front to use our configured router
$front->setRouter($router);

// Add an plugins to your $front
$front->registerPlugin(new My_Plugin());
// other plugins...

// Dispatch the request
$front->dispatch();

可能还有一些View / ViewRenderer要做的事情。 但正如其他地方所指出的那样,ViewRenderer会带来非常重要的性能影响。 如果性能是问题,那么你将要使用$this->view->render('my/view-script.phtml')禁用ViewRenderer并让你的动作控制器调用自己的渲染。

当您调用$front->dispatch() ,将自动创建$request$response对象。 如果你想在bootstrap上做一些特定的事情 - 比如在响应的Content-Type标题中设置charset - 那么你可以自己创建你的请求/响应对象,做你想做的事,然后将它附加到前面with $front->setResponse($response); 对于请求对象也是如此。

虽然我看到我的示例使用Zend_Loader_AutoloaderZend_config_Ini ,但Padraic指出这会导致性能Zend_config_Ini 下一步是通过使用数组进行配置,从框架中剥离require_once调用,注册不同的自动加载器等来解决这些问题,为读者留下一个练习...... ;-)

嗨我不同意在bootstrap中没有使用Zend_Application,我还没有看到这个技术的具体例子。

我个人认为没有使用Zend_app引导你的应用程序的好处,假设a)你做的事情是“Zend方式”和b)你的项目要么足够大,要么只是保证使用Zend框架(或任何为此物)。

虽然Zend_App非常适合在标准化结构中创建一致的复杂引导,但它并没有在基线性能方面受到显着性能影响。 更直接的引导程序(ZF的典型特征直到Zend_App到达)要快得多,也可以在没有配置文件的情况下完成。

取自PádraicBrady链接。

对我来说上面的内容没有意义,他基本上只是说Zend_App非常适合复杂的bootstraps,但是增加了性能。 但这不是任何框架/框架组件的前提吗? 我知道Padraic是一个非常聪明的人,我确信他有他的推理,但我也很乐意看到这个建议的例子/证据。

也许在回答你的问题时,你可以使用最新的Zend框架对基本应用程序进行基准测试,然后使用旧的非Zend_App方式使用<1.10的Zend框架,但我会说明显不完美Zend_App显然更快获得大多数应用程序并且运行,所以这是否值得'性能打击'是我想由开发人员。

这是一个链接,它有点涉及到你可能会追求但是参考模块化方法(仍然有趣,但同时):

http://www.osebboy.com/blog/zend-framework-modules/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM