Beispiel #1
0
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  */
 public function register(Application $app)
 {
     // the provider
     $app['pager'] = $app->share(function () use($app) {
         $manager = new PagerManager();
         $request = $app['request_stack']->getCurrentRequest();
         if ($request) {
             $manager->initialize($request);
         }
         return $manager;
     });
 }
 /**
  * @dataProvider decodeHttpQueryProvider
  */
 public function testDecodeHttpQuery($query, $expected)
 {
     $manager = new PagerManager();
     $manager->initialize(Request::create($query));
     $mirror = new PagerManager();
     $req =& $this->getProtectedAttrRef($mirror, 'request');
     $req = Request::create($query);
     foreach ($expected as $parid => $pager) {
         if ($pager) {
             $mirror[$parid] = $this->createPager($pager);
         }
     }
     $this->assertEquals($mirror->getPagers(), $manager->getPagers());
 }
Beispiel #3
0
 /**
  * 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());
     }
 }
Beispiel #4
0
 /**
  * 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);
 }
Beispiel #5
0
 public function offsetUnset($offset)
 {
     $this->manager->offsetUnset($offset);
 }
Beispiel #6
0
 /**
  * @param string $linkFor
  *
  * @return mixed
  */
 public function makeLink($linkFor = '')
 {
     return $this->manager->makeLink($linkFor);
 }