/**
  * @param BaseApp $app
  */
 public function register(BaseApp $app)
 {
     $app->set('sessionStorage', function (BaseApp $app) {
         if ($app->isCli()) {
             return new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage();
         } else {
             return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage();
         }
     });
     $app->set('session', function (BaseApp $app) {
         return new \Symfony\Component\HttpFoundation\Session\Session($app->getNew('sessionStorage'));
     });
     $app->set('router', function (BaseApp $app) {
         return new \Starlit\App\Router($app, $app->getConfig()->get('router', []));
     });
     $app->set('view', function (BaseApp $app) {
         return new \Starlit\App\View($app->getConfig()->get('view', []));
     });
     // Default response (force no cache)
     $app->set('response', function () {
         $response = new \Symfony\Component\HttpFoundation\Response();
         $response->headers->addCacheControlDirective('no-cache', true);
         $response->headers->addCacheControlDirective('max-age', 0);
         $response->headers->addCacheControlDirective('must-revalidate', true);
         $response->headers->addCacheControlDirective('no-store', true);
         return $response;
     });
 }
Ejemplo n.º 2
0
 /**
  * @param BaseApp $app
  */
 public function register(BaseApp $app)
 {
     $app->set('errorLogger', function (BaseApp $app) {
         $logger = new \Monolog\Logger('errorLogger');
         $handler = new \Monolog\Handler\ErrorLogHandler();
         if (!$app->isCli()) {
             $handler->pushProcessor(new \Monolog\Processor\WebProcessor());
             $format = '%level_name%: %message% %extra.server%%extra.url%';
         } else {
             $format = '%level_name%: %message%';
         }
         $handler->setFormatter(new \Monolog\Formatter\LineFormatter($format, null, true));
         $logger->pushHandler($handler);
         return $logger;
     });
     $app->set('whoopsDebugErrorPageHandler', function (BaseApp $app) {
         $prettyPageHandler = new \Whoops\Handler\PrettyPageHandler();
         if ($app->getConfig()->has('editor')) {
             $prettyPageHandler->setEditor($app->getConfig()->get('editor'));
         }
         return $prettyPageHandler;
     });
     $app->set('whoopsErrorHandler', function (BaseApp $app) {
         $plainTextHandler = new \Whoops\Handler\PlainTextHandler();
         $plainTextHandler->setLogger($app->get('errorLogger'));
         if (!$app->isCli()) {
             $plainTextHandler->loggerOnly(true);
         }
         return $plainTextHandler;
     });
     $app->set('whoops', function (BaseApp $app) {
         $whoops = new \Whoops\Run();
         if (ini_get('display_errors')) {
             $whoops->pushHandler($app->get('whoopsDebugErrorPageHandler'));
         }
         // Handles cli output and logging
         $whoops->pushHandler($app->get('whoopsErrorHandler'));
         return $whoops;
     });
     $app->get('whoops')->register();
 }
Ejemplo n.º 3
0
 public function testIsCli()
 {
     $this->assertEquals(true, $this->app->isCli());
 }