vendor/symfony/routing/CompiledRoute.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Routing;
  11. /**
  12.  * CompiledRoutes are returned by the RouteCompiler class.
  13.  *
  14.  * @author Fabien Potencier <fabien@symfony.com>
  15.  */
  16. class CompiledRoute implements \Serializable
  17. {
  18.     private array $variables;
  19.     private array $tokens;
  20.     private string $staticPrefix;
  21.     private string $regex;
  22.     private array $pathVariables;
  23.     private array $hostVariables;
  24.     private ?string $hostRegex;
  25.     private array $hostTokens;
  26.     /**
  27.      * @param string      $staticPrefix  The static prefix of the compiled route
  28.      * @param string      $regex         The regular expression to use to match this route
  29.      * @param array       $tokens        An array of tokens to use to generate URL for this route
  30.      * @param array       $pathVariables An array of path variables
  31.      * @param string|null $hostRegex     Host regex
  32.      * @param array       $hostTokens    Host tokens
  33.      * @param array       $hostVariables An array of host variables
  34.      * @param array       $variables     An array of variables (variables defined in the path and in the host patterns)
  35.      */
  36.     public function __construct(string $staticPrefixstring $regex, array $tokens, array $pathVariablesstring $hostRegex null, array $hostTokens = [], array $hostVariables = [], array $variables = [])
  37.     {
  38.         $this->staticPrefix $staticPrefix;
  39.         $this->regex $regex;
  40.         $this->tokens $tokens;
  41.         $this->pathVariables $pathVariables;
  42.         $this->hostRegex $hostRegex;
  43.         $this->hostTokens $hostTokens;
  44.         $this->hostVariables $hostVariables;
  45.         $this->variables $variables;
  46.     }
  47.     public function __serialize(): array
  48.     {
  49.         return [
  50.             'vars' => $this->variables,
  51.             'path_prefix' => $this->staticPrefix,
  52.             'path_regex' => $this->regex,
  53.             'path_tokens' => $this->tokens,
  54.             'path_vars' => $this->pathVariables,
  55.             'host_regex' => $this->hostRegex,
  56.             'host_tokens' => $this->hostTokens,
  57.             'host_vars' => $this->hostVariables,
  58.         ];
  59.     }
  60.     /**
  61.      * @internal
  62.      */
  63.     final public function serialize(): string
  64.     {
  65.         throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
  66.     }
  67.     public function __unserialize(array $data): void
  68.     {
  69.         $this->variables $data['vars'];
  70.         $this->staticPrefix $data['path_prefix'];
  71.         $this->regex $data['path_regex'];
  72.         $this->tokens $data['path_tokens'];
  73.         $this->pathVariables $data['path_vars'];
  74.         $this->hostRegex $data['host_regex'];
  75.         $this->hostTokens $data['host_tokens'];
  76.         $this->hostVariables $data['host_vars'];
  77.     }
  78.     /**
  79.      * @internal
  80.      */
  81.     final public function unserialize(string $serialized)
  82.     {
  83.         $this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
  84.     }
  85.     /**
  86.      * Returns the static prefix.
  87.      */
  88.     public function getStaticPrefix(): string
  89.     {
  90.         return $this->staticPrefix;
  91.     }
  92.     /**
  93.      * Returns the regex.
  94.      */
  95.     public function getRegex(): string
  96.     {
  97.         return $this->regex;
  98.     }
  99.     /**
  100.      * Returns the host regex.
  101.      */
  102.     public function getHostRegex(): ?string
  103.     {
  104.         return $this->hostRegex;
  105.     }
  106.     /**
  107.      * Returns the tokens.
  108.      */
  109.     public function getTokens(): array
  110.     {
  111.         return $this->tokens;
  112.     }
  113.     /**
  114.      * Returns the host tokens.
  115.      */
  116.     public function getHostTokens(): array
  117.     {
  118.         return $this->hostTokens;
  119.     }
  120.     /**
  121.      * Returns the variables.
  122.      */
  123.     public function getVariables(): array
  124.     {
  125.         return $this->variables;
  126.     }
  127.     /**
  128.      * Returns the path variables.
  129.      */
  130.     public function getPathVariables(): array
  131.     {
  132.         return $this->pathVariables;
  133.     }
  134.     /**
  135.      * Returns the host variables.
  136.      */
  137.     public function getHostVariables(): array
  138.     {
  139.         return $this->hostVariables;
  140.     }
  141. }