Question

I am getting an error when trying to run app in CLI mode. First of all I have daemon controller which allows to run daemon instances (objects with only one required method 'run' derived from my daemon interface) using url /daemon-cli/:Daemon_Class_To_Run. So there is nothing interesting from this side.

Also I have little sh script to run this controller in a simplified way like this:

# ./daemon.sh Ami_Daemon_EventParser

This returns me the next error:

<?
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

System namespace is located in application/library/System and this is just a set of toolkits and libraries. That is completely weird because it works well in apache2handler mode, but crashes in cli. I don't understand how the class cannot be found if the code of "not founded" class are returned in the error. I suppose I bootstrapped application in a wrong way.

Some of bootstrap code:

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;
}

And in the index.php I bootstrap all modules.

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();
}

I am fighting with this for a couple of weeks, so I hope somebody has an answer or a good advice. Any help is greatly appreciated. Thanks!

Était-ce utile?

La solution

Finally I did that! As you can see I had a php short tag in the error output. Php often uses separate php.ini for cli mode as my rackspace distributive does. Php distros for windows usually have the common ini file.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top