/** * Constructor * Checks for the required gearman extension, * fetches the bootstrap and loads in the gearman worker * * @param Zend_Application_Bootstrap_BootstrapAbstract $bootstrap * @return Zend_Gearman_Worker */ public function __construct(Zend_Application_Bootstrap_BootstrapAbstract $bootstrap) { if (!extension_loaded('gearman')) { throw new RuntimeException('The PECL::gearman extension is required.'); } $this->_bootstrap = $bootstrap; $this->_worker = $this->_bootstrap->bootstrap('gearmanworker')->getResource('gearmanworker'); if (empty($this->_registerFunction)) { throw new InvalidArgumentException(get_class($this) . ' must implement a registerFunction'); } // allow for a small memory gap: $memoryLimit = ($this->_memory + 128) * 1024 * 1024; ini_set('memory_limit', $memoryLimit); $this->_worker->addFunction($this->_registerFunction, array(&$this, 'work')); $this->_worker->setTimeout($this->_timeout); $this->init(); $check = 10; $c = 0; while (@$this->_worker->work() || $this->_worker->returnCode() == GEARMAN_TIMEOUT) { $c++; if ($this->_worker->returnCode() == GEARMAN_TIMEOUT) { $this->timeout(); continue; } if ($this->_worker->returnCode() != GEARMAN_SUCCESS) { $this->setError($this->_worker->returnCode() . ': ' . $this->_worker->getErrno() . ': ' . $this->_worker->error()); break; } if ($c % $check === 0 && $this->isMemoryOverflow()) { break; // we've consumed our memory and the worker needs to be restarted } } $this->shutdown(); }
/** * (non-PHPdoc) * @see Tudu_Model_ResourceManager_Abstract::hasResource() */ public function hasResource($name) { $bool = $this->_bootstrap->hasResource($name); if (!$bool) { try { $this->_bootstrap->bootstrap($name); $bool = true; } catch (Zend_Application_Bootstrap_Exception $e) { return false; } } return $bool; }
/** * Load the configuration file that define the configurations of the module * and return the content into an array. * INI is the expected file format. * * @param string $relativePath Relative path from module root to the directory * where the configuraton file is locatedfrom module * root directory * @param string $fileName The filename of the configuration file * @param string $section The section of the file to load * @return null|array */ protected function _loadModuleConfigurationsFile($relativePath, $fileName, $section) { $moduleDir = $this->getFrontController()->getModuleDirectory($this->getRequest()->getModuleName()); try { $configFile = new \Zend_Config_Ini($moduleDir . DIRECTORY_SEPARATOR . $relativePath . DIRECTORY_SEPARATOR . $fileName, $section); } catch (\Zend_Config_Exception $e) { if ($this->_bootstrap->hasResource('log')) { $logger = $this->_bootstrap->getResource('log'); $logger->notice('Imposible to load module configuration file ; exception message: ' . $e->getMessage()); } return null; } return count($configFile) == 0 ? null : $configFile->toArray(); }
/** * Constructor * * Ensure FrontController resource is registered * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application * @return void */ public function __construct($application) { parent::__construct($application); if (!$this->hasPluginResource('FrontController')) { $this->registerPluginResource('FrontController'); } }
/** * Constructor * * Ensure FrontController resource is registered * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application * @return void */ public function __construct($application) { parent::__construct($application); if ($application->hasOption('resourceloader')) { $this->setOptions(array('resourceloader' => $application->getOption('resourceloader'))); } $this->getResourceLoader(); if (!$this->hasPluginResource('FrontController')) { $this->registerPluginResource('FrontController'); } }
public function getContainer() { if (null === $this->_container) { if (empty($this->_containerFactory)) { $this->_container = parent::getContainer(); } else { $this->_container = $this->_containerFactory->makeContainer(); } } return $this->_container; }
/** * (non-PHPdoc) * @see Zend_Controller_Action::init() */ public function init() { $this->_bootstrap = $this->getInvokeArg('bootstrap'); $this->_multidb = $this->_bootstrap->getResource('multidb'); $this->_options = $this->_bootstrap->getOptions(); $this->_session = $this->_bootstrap->getResource('session'); $this->_user = Tudu_User::getInstance(); $this->_timestamp = time(); if (Zend_Session::sessionExists() || $this->_sessionId) { if (null !== $this->_sessionId) { Zend_Session::setId($this->_sessionId); } $this->initUser(); } }
/** * Creates the bootstrapper. * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application */ public function __construct($application) { parent::__construct($application); // Uses a simple container that is not global. $this->setContainer(new stdClass()); }