public function testAutoSetInjector() { $injector = new NovemberInjector(dirname(dirname(__FILE__)) . '/services'); $injector->addAutoProperty('auto', 'somevalue'); $injector->loadServices(); $this->assertTrue($injector->hasService('SampleService')); // We expect a false because the 'AnotherService' is actually // just a replacement of the SampleService $myObject = new TestObject(); $injector->inject($myObject); $this->assertEqual(get_class($myObject->sampleService), 'SampleService'); $this->assertEqual($myObject->auto, 'somevalue'); }
/** * Initialises the application * */ public function init() { $__start = getmicrotime(); if (isset($this->config['log_file'])) { $writer = new Zend_Log_Writer_Stream($this->config['log_file']); $this->logger = new Zend_Log($writer); if (isset($this->config['log_format'])) { $formatter = new Zend_Log_Formatter_Simple($this->config['log_format']); $writer->setFormatter($formatter); } // If not in debug mode, hide debug log messages if (!ifset($this->config, 'debug', false)) { $this->logger->addFilter(Zend_Log::NOTICE); } } $this->recordStat('za::initlog', getmicrotime() - $__start); $__start = getmicrotime(); $mailServer = $this->getConfig('smtp_server'); if (mb_strlen($mailServer)) { ini_set('SMTP', $mailServer); } // Create a new view object. $view = new CompositeView(); Zend_Registry::set(self::$ZEND_VIEW, $view); /* @var Zend_Controller_Front $controller */ $this->frontController = Zend_Controller_Front::getInstance(); $this->frontController->setDispatcher(new InjectingDispatcher()); $this->frontController->addControllerDirectory($this->getConfig('controller_dir', 'controllers'), 'default'); $modules = ifset($this->config, 'modules', array()); foreach ($modules as $module) { if (is_dir(APP_DIR . '/modules/' . $module)) { $this->frontController->addControllerDirectory('modules/' . $module, $module); } } $this->recordStat('za::initmodules', getmicrotime() - $__start); $__start = getmicrotime(); $this->frontController->throwExceptions(ifset($this->config, 'debug', false) ? true : false); if (isset($this->config['route_config']) && php_sapi_name() != 'cli') { $router = $this->frontController->getRouter(); /* @var $router Zend_Controller_Router_Rewrite */ $config = new Zend_Config_Ini($this->config['route_config'], 'routes'); $router->addConfig($config, 'routes'); } Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->frontController->setParam('noViewRenderer', true); /** * Set the session */ $session_name = str_replace(' ', '_', $this->config['name']); Zend_Session::start(array('name' => $session_name)); $this->injector->addAutoProperty('log', $this->logger); $__start = getmicrotime(); // $services = $this->loadDefaultServices(); $this->injector->addServiceDirectory(NOVEMBER_APP_DIR . '/services'); // $this->injector->loadServices($this->config['services']); $this->recordStat('za::initdefaultservices', getmicrotime() - $__start); $__start = getmicrotime(); // // foreach ($services as $defaultService) { // $this->injector->inject($defaultService); // } // $this->recordStat('za::initinjectdefaultservices', getmicrotime() - $__start); $__start = getmicrotime(); // Load extensions $this->loadExtensions(); $this->injector->addServiceDirectory(ifset($this->config, 'services_dir', APP_DIR . '/services')); $this->recordStat('za::initloadext', getmicrotime() - $__start); $__start = getmicrotime(); $this->injector->loadServices($this->config['services']); $this->recordStat('za::initloadservices', getmicrotime() - $__start); $__start = getmicrotime(); // We know that there's definitely going to be an AuthService, // so we can now go and load the user if there was one in // the session. $auth = $this->injector->getService('AuthService'); if (isset($this->getSession()->CURRENT_USER_TICKET) && mb_strlen($this->getSession()->CURRENT_USER_TICKET)) { $auth->validateTicket($this->getSession()->CURRENT_USER_NAME, $this->getSession()->CURRENT_USER_TICKET); } $this->recordStat('za::initvalidateauth', getmicrotime() - $__start); }