/**
  * @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;
     });
 }
 /**
  * Forwards request to another action and/or controller
  *
  * @param string $action     Action name as lowercase separated string
  * @param string $controller Controller name as lowercase separated string
  * @param string $module     Module name as lowercase separated string
  * @param array  $actionArgs
  * @return Response
  */
 protected function forward($action, $controller = '', $module = '', array $actionArgs = [])
 {
     // Forward inside same controller (easy)
     if (!$controller) {
         return $this->dispatch($action, $actionArgs);
         // Forward to another controller
     } else {
         $module = $module ?: $this->module;
         $controller = $controller ?: $this->controller;
         $controllerClass = $this->app->getRouter()->getControllerClass($module, $controller);
         $actualController = new $controllerClass($this->app, $this->request);
         return $actualController->dispatch($action, $actionArgs);
     }
 }
 /**
  * @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();
 }
示例#4
0
 public function testGetEnvironment()
 {
     $this->assertEquals($this->fakeEnv, $this->app->getEnvironment());
 }