簡體   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