/** * @param DI $di * @return Wrapper * @throws \Exception */ public function getService(DI $di) { $config = $di->get('config'); try { $pdo = new \PDO($config->pdo->dsn, $config->pdo->username, $config->pdo->password); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (\PDOException $exception) { /** * @var \Monolog\Logger $logger */ $logger = $di->get('logger_helper')->getLogger(); $logger->critical($exception); throw $exception; } return new Wrapper($pdo); }
/** * @param DI $di * @return \Twig_Environment * @throws \Exception */ public function getService(DI $di) { $config = $di->get('config'); $loader = new \Twig_Loader_Filesystem($config->twig->templates_path); $twig = new \Twig_Environment($loader, json_decode(json_encode($config->twig), true)); return $twig; }
/** * @param DI $di */ public function __construct(DI $di) { $this->di = $di; /** * @var ErrorCatcher $errorCatcher */ $errorCatcher = $di->get('error_catcher'); $errorCatcher->register(); $errorCatcher->setExceptionCallback(array($this, 'handleException')); $errorCatcher->setFatalCallback(array($this, 'handleFatalError')); }
/** * @return \stdClass * @throws \Exception */ public function getConfig() { return $this->di->get('config'); }
/** * @return \PDO * @throws \Exception */ protected function getPDO() { return $this->di->get('pdo'); }
/** * @return mixed * @throws \Exception */ protected function getLogger() { return $this->di->get('logger_helper')->getLogger(); }