3 namespace Drupal\Core\Routing;
5 use Drupal\Component\Utility\Unicode;
6 use Symfony\Component\Routing\CompiledRoute as SymfonyCompiledRoute;
9 * A compiled route contains derived information from a route object.
11 class CompiledRoute extends SymfonyCompiledRoute {
14 * The fitness of this route.
21 * The pattern outline of this route.
25 protected $patternOutline;
28 * The number of parts in the path of this route.
35 * Constructs a new compiled route object.
37 * This is a ridiculously long set of constructor parameters, but as this
38 * object is little more than a collection of values it's not a serious
39 * problem. The parent Symfony class does the same, as well, making it
40 * difficult to override differently.
43 * The fitness of the route.
44 * @param string $pattern_outline
45 * The pattern outline for this route.
46 * @param int $num_parts
47 * The number of parts in the path.
48 * @param string $staticPrefix
49 * The static prefix of the compiled route
50 * @param string $regex
51 * The regular expression to use to match this route
52 * @param array $tokens
53 * An array of tokens to use to generate URL for this route
54 * @param array $pathVariables
55 * An array of path variables
56 * @param string|null $hostRegex
58 * @param array $hostTokens
60 * @param array $hostVariables
61 * An array of host variables
62 * @param array $variables
63 * An array of variables (variables defined in the path and in the host patterns)
65 public function __construct($fit, $pattern_outline, $num_parts, $staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = NULL, array $hostTokens = [], array $hostVariables = [], array $variables = []) {
66 parent::__construct($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, $variables);
69 // Support case-insensitive route matching by ensuring the pattern outline
71 // @see \Drupal\Core\Routing\RouteProvider::getRoutesByPath()
72 $this->patternOutline = Unicode::strtolower($pattern_outline);
73 $this->numParts = $num_parts;
77 * Returns the fit of this route.
79 * See RouteCompiler for a definition of how the fit is calculated.
82 * The fit of the route.
84 public function getFit() {
89 * Returns the number of parts in this route's path.
91 * The string "foo/bar/baz" has 3 parts, regardless of how many of them are
95 * The number of parts in the path.
97 public function getNumParts() {
98 return $this->numParts;
102 * Returns the pattern outline of this route.
104 * The pattern outline of a route is the path pattern of the route, but
105 * normalized such that all placeholders are replaced with %.
108 * The normalized path pattern.
110 public function getPatternOutline() {
111 return $this->patternOutline;
115 * Returns the options.
120 public function getOptions() {
121 return $this->route->getOptions();
125 * Returns the defaults.
130 public function getDefaults() {
131 return $this->route->getDefaults();
135 * Returns the requirements.
140 public function getRequirements() {
141 return $this->route->getRequirements();
147 public function serialize() {
148 // Calling the parent method is safer than trying to optimize out the extra
150 $data = unserialize(parent::serialize());
151 $data['fit'] = $this->fit;
152 $data['patternOutline'] = $this->patternOutline;
153 $data['numParts'] = $this->numParts;
155 return serialize($data);
161 public function unserialize($serialized) {
162 parent::unserialize($serialized);
163 $data = unserialize($serialized);
165 $this->fit = $data['fit'];
166 $this->patternOutline = $data['patternOutline'];
167 $this->numParts = $data['numParts'];