3 namespace Drupal\Core\Routing;
5 use Symfony\Component\Routing\CompiledRoute as SymfonyCompiledRoute;
8 * A compiled route contains derived information from a route object.
10 class CompiledRoute extends SymfonyCompiledRoute {
13 * The fitness of this route.
20 * The pattern outline of this route.
24 protected $patternOutline;
27 * The number of parts in the path of this route.
34 * Constructs a new compiled route object.
36 * This is a ridiculously long set of constructor parameters, but as this
37 * object is little more than a collection of values it's not a serious
38 * problem. The parent Symfony class does the same, as well, making it
39 * difficult to override differently.
42 * The fitness of the route.
43 * @param string $pattern_outline
44 * The pattern outline for this route.
45 * @param int $num_parts
46 * The number of parts in the path.
47 * @param string $staticPrefix
48 * The static prefix of the compiled route
49 * @param string $regex
50 * The regular expression to use to match this route
51 * @param array $tokens
52 * An array of tokens to use to generate URL for this route
53 * @param array $pathVariables
54 * An array of path variables
55 * @param string|null $hostRegex
57 * @param array $hostTokens
59 * @param array $hostVariables
60 * An array of host variables
61 * @param array $variables
62 * An array of variables (variables defined in the path and in the host patterns)
64 public function __construct($fit, $pattern_outline, $num_parts, $staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = NULL, array $hostTokens = [], array $hostVariables = [], array $variables = []) {
65 parent::__construct($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, $variables);
68 // Support case-insensitive route matching by ensuring the pattern outline
70 // @see \Drupal\Core\Routing\RouteProvider::getRoutesByPath()
71 $this->patternOutline = mb_strtolower($pattern_outline);
72 $this->numParts = $num_parts;
76 * Returns the fit of this route.
78 * See RouteCompiler for a definition of how the fit is calculated.
81 * The fit of the route.
83 public function getFit() {
88 * Returns the number of parts in this route's path.
90 * The string "foo/bar/baz" has 3 parts, regardless of how many of them are
94 * The number of parts in the path.
96 public function getNumParts() {
97 return $this->numParts;
101 * Returns the pattern outline of this route.
103 * The pattern outline of a route is the path pattern of the route, but
104 * normalized such that all placeholders are replaced with %.
107 * The normalized path pattern.
109 public function getPatternOutline() {
110 return $this->patternOutline;
114 * Returns the options.
119 public function getOptions() {
120 return $this->route->getOptions();
124 * Returns the defaults.
129 public function getDefaults() {
130 return $this->route->getDefaults();
134 * Returns the requirements.
139 public function getRequirements() {
140 return $this->route->getRequirements();
146 public function serialize() {
147 // Calling the parent method is safer than trying to optimize out the extra
149 $data = unserialize(parent::serialize());
150 $data['fit'] = $this->fit;
151 $data['patternOutline'] = $this->patternOutline;
152 $data['numParts'] = $this->numParts;
154 return serialize($data);
160 public function unserialize($serialized) {
161 parent::unserialize($serialized);
162 $data = unserialize($serialized);
164 $this->fit = $data['fit'];
165 $this->patternOutline = $data['patternOutline'];
166 $this->numParts = $data['numParts'];