class RouteWrapper in Drupal 7 to 8/9 Module Upgrader 8
Same name in this branch
- 8 src/Routing/Drupal7/RouteWrapper.php \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
- 8 src/Routing/Drupal8/RouteWrapper.php \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper
Wraps around a Symfony Route object, providing helper methods.
Hierarchy
- class \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper implements RouteWrapperInterface
Expanded class hierarchy of RouteWrapper
7 files declare their use of RouteWrapper
- ContentRoute.php in src/
Plugin/ DMU/ Routing/ ContentRoute.php - LinkBinding.php in src/
Routing/ LinkBinding/ LinkBinding.php - LinkBindingFactory.php in src/
Routing/ LinkBinding/ LinkBindingFactory.php - LinkBindingTest.php in tests/
src/ Unit/ Routing/ LinkBinding/ LinkBindingTest.php - LocalTaskLinkBinding.php in src/
Routing/ LinkBinding/ LocalTaskLinkBinding.php
File
- src/
Routing/ Drupal8/ RouteWrapper.php, line 14
Namespace
Drupal\drupalmoduleupgrader\Routing\Drupal8View source
class RouteWrapper implements RouteWrapperInterface {
/**
* @var string
*/
protected $name;
/**
* @var \Symfony\Component\Routing\Route
*/
protected $route;
/**
* @var \Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathUtility
*/
protected $path;
/**
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* @var \Symfony\Component\Routing\RouteCollection
*/
protected $router;
/**
* @var static
*/
protected $parent;
/**
* Constructs a Route object.
*/
public function __construct($name, Route $route, RouteProviderInterface $route_provider) {
$this->name = $name;
$this->route = $route;
$this->routeProvider = $route_provider ? $route_provider : \Drupal::service('router.route_provider');
$this->path = new PathUtility($route
->getPath());
}
/**
* Forwards unknown function calls to the wrapped Route.
*/
public function __call($method, array $arguments) {
return call_user_func_array([
$this->route,
$method,
], $arguments);
}
/**
* {@inheritdoc}
*/
public function getIdentifier() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getPath() {
return $this->path;
}
/**
* {@inheritdoc}
*/
public function hasParent() {
return isset($this->parent);
}
/**
* {@inheritdoc}
*/
public function getParent() {
return $this->parent;
}
/**
* {@inheritdoc}
*/
public function unwrap() {
return $this->route;
}
/**
* {@inheritdoc}
*/
public function onRouterBuilt(RouterBuiltEvent $event) {
$this->router = $event
->getRouter();
try {
$parent = $this
->getPath()
->getParent()
->__toString();
} catch (\LengthException $e) {
return;
}
// First, search the injected router for the parent route.
foreach ($this->router as $route) {
if ($route
->getPath() == $parent) {
$this->parent = $route;
}
}
// Next, search the core route provider if no parent was found.
if (empty($this->parent)) {
$parents = $this->routeProvider
->getRoutesByPattern($parent)
->getIterator();
if (sizeof($parents) > 0) {
$this->parent = new static($parents
->key(), $parents
->current(), $this->routeProvider);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
protected | property | ||
RouteWrapper:: |
public | function |
Returns an identifier for this route. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function |
Gets the parent route, if there is one. The parent should also be wrapped. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function |
Returns a PathUtilityInterface implementation for the route. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function |
Returns if this route has a parent. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function |
React to the router (i.e., the collection of routes defined by the
module) being completely built. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function |
Returns the original, unwrapped route. Overrides RouteWrapperInterface:: |
|
RouteWrapper:: |
public | function | Forwards unknown function calls to the wrapped Route. | |
RouteWrapper:: |
public | function | Constructs a Route object. |