/** * Resume the session if it has been started previously or debugging is enabled * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); // because of vaious type of requests fires event (Frontend/Async/Thumbs/etc.) // we're just listening to which has page parameter if (PagerManager::isPagingRequest($request)) { /** @var $manager \Bolt\Pager\PagerManager */ $manager = $this->managerFactory->__invoke(); $manager->initialize($event->getRequest()); } }
/** * Takes a Request object and uses it to initialize settings that depend on * the request. * * @param Request $request */ public function initializeRequest(Application $app, Request $request = null) { if ($request === null) { $request = Request::createFromGlobals(); } // This is where we set the canonical. Note: The protocol (scheme) defaults to 'http', // and the path is discarded, as it makes no sense in this context: Bolt always // determines the path for a page / record. This is not the canonical's job. $canonical = $app['config']->get('general/canonical', ''); if ($canonical !== '' && strpos($canonical, 'http') !== 0) { $canonical = 'http://' . $canonical; } $canonical = parse_url($canonical); if (empty($canonical['scheme'])) { $canonical['scheme'] = 'http'; } if (empty($canonical['host'])) { $canonical['host'] = $request->server->get('HTTP_HOST'); } $this->setRequest('canonical', sprintf('%s://%s', $canonical['scheme'], $canonical['host'])); // Set the current protocol. Default to http, unless otherwise. $protocol = 'http'; if ($request->server->get('HTTPS') == 'on' || $request->server->get('SERVER_PROTOCOL') == 'https' || $request->server->get('HTTP_X_FORWARDED_PROTO') == 'https' || $request->server->get('HTTP_X_FORWARDED_SSL') == 'on') { $protocol = 'https'; } elseif ($request->server->get('SERVER_PROTOCOL') === null) { $protocol = 'cli'; } $rootUrl = rtrim($this->getUrl('root'), '/'); if ($rootUrl !== $request->getBasePath()) { $rootUrl = $request->getBasePath(); $this->setUrl('root', $rootUrl . $this->getUrl('root')); $this->setUrl('app', $rootUrl . $this->getUrl('app')); $this->setUrl('extensions', $rootUrl . $this->getUrl('extensions')); $this->setUrl('files', $rootUrl . $this->getUrl('files')); $this->setUrl('async', $rootUrl . $this->getUrl('async')); $this->setUrl('upload', $rootUrl . $this->getUrl('upload')); } $this->setRequest('protocol', $protocol); $hostname = $request->server->get('HTTP_HOST', 'localhost'); $this->setRequest('hostname', $hostname); $current = $request->getBasePath() . $request->getPathInfo(); $this->setUrl('current', $current); $this->setUrl('currenturl', sprintf('%s://%s%s', $protocol, $hostname, $current)); $this->setUrl('hosturl', sprintf('%s://%s', $protocol, $hostname)); $this->setUrl('rooturl', sprintf('%s%s/', $this->getRequest('canonical'), $rootUrl)); $url = sprintf('%s%s', $this->getRequest('canonical'), $current); if (PagerManager::isPagingRequest($request)) { $url .= '?' . http_build_query($request->query->all()); } $this->setUrl('canonicalurl', $url); }