Skip to content
Snippets Groups Projects
Select Git revision
  • f6312b85d2509bd4fa3e10f17db2b145a3ac4781
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

UserRoleAdminTest.php

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;
      }
    }