. * * @author Julien Fontanet * @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3 * * @package Xen Orchestra Server */ /** * Dependency injector. */ final class DI extends Base { function __construct() { parent::__construct(); } function get($id) { if (isset($this->_entries[$id]) || array_key_exists($id, $this->_entries)) { return $this->_entries[$id]; } $tmp = str_replace(array('_', '.'), array('', '_'), $id); if (method_exists($this, '_get_'.$tmp)) { return $this->{'_get_'.$tmp}(); } if (method_exists($this, '_init_'.$tmp)) { $value = $this->{'_init_'.$tmp}(); $this->set($id, $value); return $value; } throw new Exception('no such entry: '.$id); } function set($id, $value) { $this->_entries[$id] = $value; } private $_entries = array(); //////////////////////////////////////// private function _init_application() { return new Application($this); } private function _init_errorLogger() { return new ErrorLogger($this->get('logger')); } private function _init_logger() { $logger = new \Monolog\Logger('main'); $config = $this->get('config'); if ($email = $config->get('log.email', false)) { $logger->pushHandler( new \Monolog\Handler\FingersCrossedHandler( new \Monolog\Handler\NativeMailerHandler( $email, '[XO Server]', 'no-reply@vates.fr', \Monolog\Logger::DEBUG ), \Monolog\Logger::WARNING ) ); } if ($file = $config->get('log.file', false)) { $logger->pushHandler( new \Monolog\Handler\StreamHandler($file) ); } return $logger; } private function _init_loop() { return new Loop; } }