Skip to content
Snippets Groups Projects
Select Git revision
  • e79c3feef9eb00d4b5bbab92ecb4749c6de58ab8
  • 3.x default
  • 3.0.x
  • 7.x-1.x
  • 8.x-2.x
  • order-comments
  • 3.1.0
  • 3.0.2
  • 3.0.1
  • 3.0.0
  • 3.0.0-beta2
  • 3.0.0-beta1
  • 3.0.0-alpha1
  • 8.x-2.40
  • 8.x-2.39
  • 8.x-2.38
  • 8.x-2.37
  • 8.x-2.36
  • 8.x-2.35
  • 8.x-2.34
  • 8.x-2.33
  • 8.x-2.32
  • 8.x-2.31
  • 8.x-2.30
  • 7.x-1.17
  • 8.x-2.29
26 results

commerce.module

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PathSubscriber.php 2.68 KiB
    <?php
    
    /**
     * @file
     * Definition of Drupal\Core\EventSubscriber\PathSubscriber.
     */
    
    namespace Drupal\Core\EventSubscriber;
    
    use Drupal\Core\CacheDecorator\AliasManagerCacheDecorator;
    use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
    use Symfony\Component\HttpKernel\HttpKernelInterface;
    use Symfony\Component\HttpKernel\KernelEvents;
    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    use Symfony\Component\HttpKernel\Event\PostResponseEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Access subscriber for controller requests.
     */
    class PathSubscriber extends PathListenerBase implements EventSubscriberInterface {
    
      /**
       * The alias manager that caches alias lookups based on the request.
       *
       * @var \Drupal\Core\CacheDecorator\AliasManagerCacheDecorator
       */
      protected $aliasManager;
    
      /**
       * A path processor manager for resolving the system path.
       *
       * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface
       */
      protected $pathProcessor;
    
      public function __construct(AliasManagerCacheDecorator $alias_manager, InboundPathProcessorInterface $path_processor) {
        $this->aliasManager = $alias_manager;
        $this->pathProcessor = $path_processor;
      }
    
      /**
       * Converts the request path to a system path.
       *
       * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
       *   The Event to process.
       */
      public function onKernelRequestConvertPath(GetResponseEvent $event) {
        $request = $event->getRequest();
        $path = trim($request->getPathInfo(), '/');
        $path = $this->pathProcessor->processInbound($path, $request);
        $request->attributes->set('_system_path', $path);
        // Also set an attribute that indicates whether we are using clean URLs.
        $clean_urls = TRUE;
        $base_url = $request->getBaseUrl();
        if (!empty($base_url) && strpos($base_url, $request->getScriptName()) !== FALSE) {
          $clean_urls = FALSE;
        }
        $request->attributes->set('clean_urls', $clean_urls);
        // Set the cache key on the alias manager cache decorator.
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
          $this->aliasManager->setCacheKey($path);
        }
      }
    
      /**
       * Ensures system paths for the request get cached.
       */
      public function onKernelTerminate(PostResponseEvent $event) {
        $this->aliasManager->writeCache();
      }
    
      /**
       * Registers the methods in this class that should be listeners.
       *
       * @return array
       *   An array of event listener definitions.
       */
      static function getSubscribedEvents() {
        $events[KernelEvents::REQUEST][] = array('onKernelRequestConvertPath', 200);
        $events[KernelEvents::TERMINATE][] = array('onKernelTerminate', 200);
        return $events;
      }
    }