CLI模式下的Bootstrap.php中找不到类(Zend)

时间:2014-04-22 09:54:27

标签: php zend-framework

尝试在CLI模式下运行应用时出错。首先,我有一个守护进程控制器,它允许使用url / daemon-cli /:Daemon_Class_To_Run运行守护进程实例(只有一个必需的方法'run'派生自我的守护进程接口的对象)。所以这方面没有什么有趣的。

此外,我还有一个简单的脚本来运行这个控制器:

# ./daemon.sh Ami_Daemon_EventParser

这会返回下一个错误:

<?
class System_Controller_Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract {
    /**
     * Array of layout paths associating modules with layouts
     */
    protected $_moduleLayouts;
    // here was the full code of this class 
}
PHP Fatal error:  Class 'System_Controller_Plugin_ModuleLayoutLoader' not found in /var/www/htdocs/application/Bootstrap.php on line 99

系统命名空间位于application / library / System中,这只是一组工具包和库。这完全是奇怪的,因为它在apache2handler模​​式下运行良好,但在cli中崩溃。如果在错误中返回“not established”类的代码,我不明白如何找不到类。我想我以错误的方式引导应用程序。

一些引导代码:

protected function _initAppModules()
{
    $modules = array();
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('System_');
    $includePath = '';
    // Add model directories to include path
    if ($dhApp = opendir(APPLICATION_PATH . '/modules')) {
        while (($dirApp = readdir($dhApp)) !== false) {
            if (substr($dirApp, 0, 1) != '.' && is_dir(APPLICATION_PATH . '/modules/' . $dirApp)) {
                $modules [] = $dirApp;
                if ($dhModule = opendir(APPLICATION_PATH . '/modules/' . $dirApp)) {
                    while (($dirModule = readdir($dhModule)) !== false) {
                        if ($dirModule == 'library' && is_dir(APPLICATION_PATH . '/modules/' . $dirApp . '/library')) {
                            $includePath .= PATH_SEPARATOR . APPLICATION_PATH . '/modules/' . $dirApp . '/library';
                            $autoloader->registerNamespace(ucfirst($dirApp));
                        }
                    }
                    closedir($dhModule);
                }
            }
        }
        closedir($dhApp);
    }
    ini_set('include_path', ini_get('include_path') . $includePath);
    return $modules;
}

protected function _initResources()
{
    Zend_Controller_Action_HelperBroker::addPrefix('System_Controller_Action_Helper');
    $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH . '/library/System', 'namespace' => ''));
    $resourceLoader->addResourceTypes(array('form' => array('path' => 'Form/Resource/', 'namespace' => 'Form'), 'model' => array('path' => 'Model/Resource/', 'namespace' => 'Model')));

    System_API_Abstract::load();

    return $resourceLoader;
}

protected function _initView(array $options = array())
{
    $this->bootstrap('AppModules');
    $this->bootstrap('FrontController');

    $view = new Zend_View();
    $view->addScriptPath(APPLICATION_PATH . '/views/scripts');
    $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'View_Helper');
    $view->addHelperPath(APPLICATION_PATH . '/modules/gui/views/helpers', 'View_Helper');
    $view->addHelperPath(APPLICATION_PATH . '/library/System/View/Helper', 'System_View_Helper');
    // next line triggers the error 
    $layoutModulePlugin = new System_Controller_Plugin_ModuleLayoutLoader();
    foreach ($this->getResource('AppModules') as $module) {
        if (is_dir(APPLICATION_PATH . '/modules/' . $module . '/views/layouts')) {
            $layoutModulePlugin->registerModuleLayout($module, APPLICATION_PATH . '/modules/' . $module . '/views/layouts');
        }
        if (is_dir(APPLICATION_PATH . '/modules/' . $module . '/views/helpers')) {
            $view->addHelperPath(APPLICATION_PATH . '/modules/' . $module . '/views/helpers', ucfirst($module) . '_View_Helper');
        }
    }

    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
    $viewRenderer->setView($view);

    Zend_Layout::startMvc(array('layoutPath' => '../application/views/layouts', 'layout' => 'layout'));
    $this->getResource('FrontController')->registerPlugin($layoutModulePlugin);
    return $view;
}

在index.php中,我引导所有模块。

if (php_sapi_name() == 'cli') {
    $_SERVER['REQUEST_URI'] = $argv[1];
    $_SERVER ['HTTP_HOST'] = 'mydomain.info';
    ini_set('session.use_cookies', false);
    $application->bootstrap()->run();// in case if I find the way to bootstrap partially
} else {
    $application->bootstrap()->run();
}

我和这个人打了几个星期,所以我希望有人得到答案或建议。任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

最后我做到了! 如您所见,我在错误输出中有一个php短标记。 Php经常使用单独的php.ini作为我的rackspace分配的cli模式。 Windows的Php发行版通常具有常见的ini文件。