/**
  * @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;
 }
示例#3
0
 /**
  * @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');
 }
示例#5
0
文件: PDOHelper.php 项目: pozitim/ci
 /**
  * @return \PDO
  * @throws \Exception
  */
 protected function getPDO()
 {
     return $this->di->get('pdo');
 }
示例#6
0
 /**
  * @return mixed
  * @throws \Exception
  */
 protected function getLogger()
 {
     return $this->di->get('logger_helper')->getLogger();
 }