Ejemplo n.º 1
0
 /**
  * Adds a new route.
  *
  * @param string $identifier     A string declaring an unique identifier for the route.
  * @param string $pattern        A string declaring the URL pattern the route responds to. This
  *                               can also contain dynamic groups.
  * @param array  $resources      An associative array of resource handlers. The array key specifies one
  *                               or more (separated by a pipe character) HTTP request methods the handler
  *                               is capable of processing. The array value can be any arbitrary resource.
  * @param array  $constraints    An optional associative array of additional configurations. The only reserved
  *                               key is 'constraints' which is used to extract specific constraints out of the
  *                               URL pattern.
  */
 public function add(string $identifier, string $pattern, array $resources, array $constraints = [])
 {
     if (!$resources) {
         throw new \LogicException('Resource array cannot be empty.');
     }
     $variables = [];
     if (strpos($pattern, '{') !== false) {
         list($pattern, $variables) = $this->interpolation->interpolate($pattern, $constraints);
     }
     $this->collection->add(new Route($identifier, $pattern, $resources, $variables));
 }