/** * Constructor. * * @param BaseApp $app * @param Request $request */ public final function __construct(BaseApp $app, Request $request) { $this->app = $app; $this->request = $request; $classNameParts = explode('\\', get_class($this)); $firstPart = $classNameParts[0]; $lastPart = end($classNameParts); $this->module = $firstPart == 'Controller' ? '' : $firstPart; $this->controller = Str::camelToSeparator(Str::stripRight($lastPart, 'Controller'), '-'); $this->view = $this->app->getNew('view'); $this->view->setRequest($this->request); $this->init(); }
/** * @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; }); }
public function testGetNewInvalid() { $this->app->set('someKey', 'someValue'); $this->setExpectedException('\\InvalidArgumentException'); $this->app->getNew('someKey'); }