Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * @param array $configs
  */
 public function __construct(array $configs = array())
 {
     $this->di = new DI();
     $this->errorCatcher = new ErrorCatcher();
     $this->errorCatcher->register();
     $this->config = json_decode(json_encode($configs));
     $this->di->setShared('config', $this->config);
     $this->di->setShared('app', $this);
 }
Ejemplo n.º 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'));
 }
Ejemplo n.º 4
0
 /**
  * @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);
 }
 /**
  * @return \stdClass
  * @throws \Exception
  */
 public function getConfig()
 {
     return $this->di->get('config');
 }
Ejemplo n.º 6
0
 /**
  * @return \PDO
  * @throws \Exception
  */
 protected function getPDO()
 {
     return $this->di->get('pdo');
 }
Ejemplo n.º 7
0
 /**
  * @return mixed
  * @throws \Exception
  */
 protected function getLogger()
 {
     return $this->di->get('logger_helper')->getLogger();
 }