/** * Gets csrf token from Request headers|body * * @param Request $request * @return array|\Core\Reactor\DataCollection */ private function getCsrfFromRequest(Request $request) { $token = $request->headers('X-CSRF-TOKEN'); if (empty($token)) { $body = $request->body(); if (isset($body->csrfToken)) { $token = $body->csrfToken; } } return $token; }
/** * BaseController constructor. * @param Application $application */ public function __construct(Application $application) { $this->application = $application; $this->setPathBound($application->basePath()); $this->router = $application->getRouter(); $this->request = $application->getRequest(); $this->POST = $this->request->POST(); $this->GET = $this->request->GET(); $this->method = $this->request->getHttpMethod(); $this->baseInit(); }
/** * Caches the current Route * * @param Router $router */ public function cacheRoute(Router $router) { $route = $router->getCurrentRoute(); if (!is_null($route) && !$this->request->isAjax() && $route->isCacheable()) { $this->getCache()->put($this->getCacheKey('route'), $route, $this->getConfig()->get('ttl')); } }
/** * Find matching Route from Route(s) * * @param array $routes * @param RequestInterface $request * @return mixed|null * @throws PageNotFoundException */ protected function findRoute(array $routes, RequestInterface $request) { $path = $request->getPath(); if (isset($routes[$path])) { $route = $routes[$path]; } else { $route = DataCollection::find($routes, function ($key, $value) use($request) { return $value->isMatch($request); }); } if (!$route instanceof Route) { throw new PageNotFoundException(); } else { $this->dispatch('core.router.matched', $this); } return $route; }