annotate core/lib/Drupal/Core/Routing/CompiledRoute.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Routing;
Chris@0 4
Chris@0 5 use Symfony\Component\Routing\CompiledRoute as SymfonyCompiledRoute;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * A compiled route contains derived information from a route object.
Chris@0 9 */
Chris@0 10 class CompiledRoute extends SymfonyCompiledRoute {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * The fitness of this route.
Chris@0 14 *
Chris@0 15 * @var int
Chris@0 16 */
Chris@0 17 protected $fit;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * The pattern outline of this route.
Chris@0 21 *
Chris@0 22 * @var string
Chris@0 23 */
Chris@0 24 protected $patternOutline;
Chris@0 25
Chris@0 26 /**
Chris@0 27 * The number of parts in the path of this route.
Chris@0 28 *
Chris@0 29 * @var int
Chris@0 30 */
Chris@0 31 protected $numParts;
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Constructs a new compiled route object.
Chris@0 35 *
Chris@0 36 * This is a ridiculously long set of constructor parameters, but as this
Chris@0 37 * object is little more than a collection of values it's not a serious
Chris@0 38 * problem. The parent Symfony class does the same, as well, making it
Chris@0 39 * difficult to override differently.
Chris@0 40 *
Chris@0 41 * @param int $fit
Chris@0 42 * The fitness of the route.
Chris@0 43 * @param string $pattern_outline
Chris@0 44 * The pattern outline for this route.
Chris@0 45 * @param int $num_parts
Chris@0 46 * The number of parts in the path.
Chris@0 47 * @param string $staticPrefix
Chris@0 48 * The static prefix of the compiled route
Chris@0 49 * @param string $regex
Chris@0 50 * The regular expression to use to match this route
Chris@0 51 * @param array $tokens
Chris@0 52 * An array of tokens to use to generate URL for this route
Chris@0 53 * @param array $pathVariables
Chris@0 54 * An array of path variables
Chris@0 55 * @param string|null $hostRegex
Chris@0 56 * Host regex
Chris@0 57 * @param array $hostTokens
Chris@0 58 * Host tokens
Chris@0 59 * @param array $hostVariables
Chris@0 60 * An array of host variables
Chris@0 61 * @param array $variables
Chris@0 62 * An array of variables (variables defined in the path and in the host patterns)
Chris@0 63 */
Chris@0 64 public function __construct($fit, $pattern_outline, $num_parts, $staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = NULL, array $hostTokens = [], array $hostVariables = [], array $variables = []) {
Chris@0 65 parent::__construct($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, $variables);
Chris@0 66
Chris@0 67 $this->fit = $fit;
Chris@0 68 // Support case-insensitive route matching by ensuring the pattern outline
Chris@0 69 // is lowercase.
Chris@0 70 // @see \Drupal\Core\Routing\RouteProvider::getRoutesByPath()
Chris@17 71 $this->patternOutline = mb_strtolower($pattern_outline);
Chris@0 72 $this->numParts = $num_parts;
Chris@0 73 }
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Returns the fit of this route.
Chris@0 77 *
Chris@0 78 * See RouteCompiler for a definition of how the fit is calculated.
Chris@0 79 *
Chris@0 80 * @return int
Chris@0 81 * The fit of the route.
Chris@0 82 */
Chris@0 83 public function getFit() {
Chris@0 84 return $this->fit;
Chris@0 85 }
Chris@0 86
Chris@0 87 /**
Chris@0 88 * Returns the number of parts in this route's path.
Chris@0 89 *
Chris@0 90 * The string "foo/bar/baz" has 3 parts, regardless of how many of them are
Chris@0 91 * placeholders.
Chris@0 92 *
Chris@0 93 * @return int
Chris@0 94 * The number of parts in the path.
Chris@0 95 */
Chris@0 96 public function getNumParts() {
Chris@0 97 return $this->numParts;
Chris@0 98 }
Chris@0 99
Chris@0 100 /**
Chris@0 101 * Returns the pattern outline of this route.
Chris@0 102 *
Chris@0 103 * The pattern outline of a route is the path pattern of the route, but
Chris@0 104 * normalized such that all placeholders are replaced with %.
Chris@0 105 *
Chris@0 106 * @return string
Chris@0 107 * The normalized path pattern.
Chris@0 108 */
Chris@0 109 public function getPatternOutline() {
Chris@0 110 return $this->patternOutline;
Chris@0 111 }
Chris@0 112
Chris@0 113 /**
Chris@0 114 * Returns the options.
Chris@0 115 *
Chris@0 116 * @return array
Chris@0 117 * The options.
Chris@0 118 */
Chris@0 119 public function getOptions() {
Chris@0 120 return $this->route->getOptions();
Chris@0 121 }
Chris@0 122
Chris@0 123 /**
Chris@0 124 * Returns the defaults.
Chris@0 125 *
Chris@0 126 * @return array
Chris@0 127 * The defaults.
Chris@0 128 */
Chris@0 129 public function getDefaults() {
Chris@0 130 return $this->route->getDefaults();
Chris@0 131 }
Chris@0 132
Chris@0 133 /**
Chris@0 134 * Returns the requirements.
Chris@0 135 *
Chris@0 136 * @return array
Chris@0 137 * The requirements.
Chris@0 138 */
Chris@0 139 public function getRequirements() {
Chris@0 140 return $this->route->getRequirements();
Chris@0 141 }
Chris@0 142
Chris@0 143 /**
Chris@0 144 * {@inheritdoc}
Chris@0 145 */
Chris@0 146 public function serialize() {
Chris@0 147 // Calling the parent method is safer than trying to optimize out the extra
Chris@0 148 // function calls.
Chris@0 149 $data = unserialize(parent::serialize());
Chris@0 150 $data['fit'] = $this->fit;
Chris@0 151 $data['patternOutline'] = $this->patternOutline;
Chris@0 152 $data['numParts'] = $this->numParts;
Chris@0 153
Chris@0 154 return serialize($data);
Chris@0 155 }
Chris@0 156
Chris@0 157 /**
Chris@0 158 * {@inheritdoc}
Chris@0 159 */
Chris@0 160 public function unserialize($serialized) {
Chris@0 161 parent::unserialize($serialized);
Chris@0 162 $data = unserialize($serialized);
Chris@0 163
Chris@0 164 $this->fit = $data['fit'];
Chris@0 165 $this->patternOutline = $data['patternOutline'];
Chris@0 166 $this->numParts = $data['numParts'];
Chris@0 167 }
Chris@0 168
Chris@0 169 }