class PathSubscriber in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php \Drupal\Core\EventSubscriber\PathSubscriber
Provides a path subscriber that converts path aliases.
Hierarchy
- class \Drupal\Core\EventSubscriber\PathSubscriber implements EventSubscriberInterface
Expanded class hierarchy of PathSubscriber
1 string reference to 'PathSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses PathSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ PathSubscriber.php, line 21 - Contains \Drupal\Core\EventSubscriber\PathSubscriber.
Namespace
Drupal\Core\EventSubscriberView source
class PathSubscriber implements EventSubscriberInterface {
/**
* The alias manager that caches alias lookups based on the request.
*
* @var \Drupal\Core\Path\AliasManagerInterface
*/
protected $aliasManager;
/**
* The current path.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPath;
/**
* Constructs a new PathSubscriber instance.
*
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The alias manager.
* @param \Drupal\Core\Path\CurrentPathStack $current_path
* The current path.
*/
public function __construct(AliasManagerInterface $alias_manager, CurrentPathStack $current_path) {
$this->aliasManager = $alias_manager;
$this->currentPath = $current_path;
}
/**
* Sets the cache key on the alias manager cache decorator.
*
* KernelEvents::CONTROLLER is used in order to be executed after routing.
*
* @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
* The Event to process.
*/
public function onKernelController(FilterControllerEvent $event) {
// Set the cache key on the alias manager cache decorator.
if ($event
->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
$this->aliasManager
->setCacheKey(rtrim($this->currentPath
->getPath($event
->getRequest()), '/'));
}
}
/**
* 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::CONTROLLER][] = array(
'onKernelController',
200,
);
$events[KernelEvents::TERMINATE][] = array(
'onKernelTerminate',
200,
);
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathSubscriber:: |
protected | property | The alias manager that caches alias lookups based on the request. | |
PathSubscriber:: |
protected | property | The current path. | |
PathSubscriber:: |
static | function |
Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface:: |
|
PathSubscriber:: |
public | function | Sets the cache key on the alias manager cache decorator. | |
PathSubscriber:: |
public | function | Ensures system paths for the request get cached. | |
PathSubscriber:: |
public | function | Constructs a new PathSubscriber instance. |