Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Routing/RouteMatch.php
- 9 core/lib/Drupal/Core/Routing/RouteMatch.php
Namespace
Drupal\Core\Routing
File
core/lib/Drupal/Core/Routing/RouteMatch.php
View source
<?php
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class RouteMatch implements RouteMatchInterface {
protected $routeName;
protected $route;
protected $parameters;
protected $rawParameters;
public function __construct($route_name, Route $route, array $parameters = [], array $raw_parameters = []) {
$this->routeName = $route_name;
$this->route = $route;
$route_params = $this
->getParameterNames();
$parameters = array_intersect_key($parameters, $route_params);
$raw_parameters = array_intersect_key($raw_parameters, $route_params);
$this->parameters = new ParameterBag($parameters);
$this->rawParameters = new InputBag($raw_parameters);
}
public static function createFromRequest(Request $request) {
if ($request->attributes
->get(RouteObjectInterface::ROUTE_OBJECT)) {
$raw_variables = [];
if ($raw = $request->attributes
->get('_raw_variables')) {
$raw_variables = $raw
->all();
}
return new static($request->attributes
->get(RouteObjectInterface::ROUTE_NAME), $request->attributes
->get(RouteObjectInterface::ROUTE_OBJECT), $request->attributes
->all(), $raw_variables);
}
else {
return new NullRouteMatch();
}
}
public function getRouteName() {
return $this->routeName;
}
public function getRouteObject() {
return $this->route;
}
public function getParameter($parameter_name) {
return $this->parameters
->get($parameter_name);
}
public function getParameters() {
return $this->parameters;
}
public function getRawParameter($parameter_name) {
return $this->rawParameters
->get($parameter_name);
}
public function getRawParameters() {
return $this->rawParameters;
}
protected function getParameterNames() {
$names = [];
if ($route = $this
->getRouteObject()) {
$variables = $route
->compile()
->getVariables();
$names = array_combine($variables, $variables);
foreach ($route
->getDefaults() as $name => $value) {
if (!isset($names[$name]) && !str_starts_with($name, '_')) {
$names[$name] = $name;
}
}
}
return $names;
}
}
Classes
Name |
Description |
RouteMatch |
Default object representing the results of routing. |