Esempio n. 1
0
 /**
  * Construct a tokens rule to split the uri into parameters after an optional prefix.
  *
  * @param string   $controller
  * @param string   $prefix          The prefix to match.
  * @param string   $tokenCharacters Separator to use to split the parts.
  * @param bool     $authoritative   Whether the rule is authoritative.
  * @throws InvalidArgumentException
  */
 public function __construct(string $controller, string $prefix, string $tokenCharacters = '/', bool $authoritative = true)
 {
     parent::__construct($authoritative);
     if (empty($tokenCharacters)) {
         throw new InvalidArgumentException('need token characters as non-empty string.');
     }
     $this->controller = $controller;
     $this->prefix = $prefix;
     $this->prefixLen = strlen($prefix);
     $this->tokenCharacters = $tokenCharacters;
 }
Esempio n. 2
0
 /**
  * Construct the Regex Rule.
  *
  * @param string  $match         The Regex to match the URI with.
  * @param string  $replacement   The controller regex replacement string.
  * @param array[] $params        Regex replacements for the parameters.
  * @param bool    $authoritative Is this always the final route?
  * @throws InvalidArgumentException If the rule is incorrectly formatted.
  */
 public function __construct(string $match, string $replacement, array $params = [], bool $authoritative = false)
 {
     parent::__construct($authoritative);
     foreach ($params as $index => $paramSpec) {
         if (!isset($paramSpec['key'], $paramSpec['value'])) {
             throw new InvalidArgumentException('param spec needs key and value at index: ' . $index);
         }
     }
     $this->match = $match;
     $this->params = $params;
     $this->replacement = $replacement;
 }
Esempio n. 3
0
 /**
  * Construct a Split object to split the uri into named parameters after an optional prefix.
  *
  * @param string   $controller
  * @param string[] $parts
  * @param string   $prefix        The prefix to match.
  * @param string   $separator     Separator to use to split the parts.
  * @param bool     $authoritative Whether the rule is authoritative.
  * @throws InvalidArgumentException
  */
 public function __construct(string $controller, array $parts, string $prefix, string $separator, bool $authoritative = true)
 {
     parent::__construct($authoritative);
     if (empty($parts)) {
         throw new InvalidArgumentException('need parts as non-empty array.');
     }
     if (empty($separator)) {
         throw new InvalidArgumentException('need separator as non-empty string.');
     }
     $this->controller = $controller;
     $this->parts = $parts;
     $this->prefix = $prefix;
     $this->prefixLen = strlen($prefix);
     $this->separator = $separator;
 }
Esempio n. 4
0
 /**
  * Construct the Regex Rule.
  *
  * @param string[] $controller    Controller regex match and replace.
  * @param string   $match         Regex to determine whether the rule matches.
  * @param array[]  $params        Parameters each with a key and value regex for match and replacement.
  * @param bool     $authoritative Whether the rule is authoritative.
  * @throws InvalidArgumentException
  */
 public function __construct(array $controller, string $match, array $params, bool $authoritative = false)
 {
     parent::__construct($authoritative);
     $invalidArgs = false;
     foreach ($params as $param) {
         if (!isset($param['key']['match'], $param['key']['replace'], $param['value']['match'], $param['value']['replace'])) {
             $invalidArgs = true;
             break;
         }
     }
     if ($invalidArgs || !isset($controller['match'], $controller['replace'])) {
         throw new InvalidArgumentException('Bad Arguments');
     }
     $this->controller = $controller;
     $this->match = $match;
     $this->params = $params;
 }