/** * Adds a route to the collection. * * The syntax used in the $route string depends on the used route parser. * * @param string|string[] $methods * @param string $route * @param mixed $handler * @return self */ public function add($name, $methods, $pattern, $handler) { $route = new Route(); if (!empty($name)) { $names = array_merge($this->groupNames, [$name]); $route->setName($names); $name = $route->getName(); if (array_key_exists($name, $this->nameToRoute)) { throw new Exception("Route with name \"{$name}\" already exists"); } $this->nameToRoute[$name] = $route; } $patterns = array_merge($this->groupPatterns, [$pattern]); $route->setPath($patterns); $route->setMethod($methods); $route->setHandler($handler); $routeDatas = $this->parse($route->getPath()); foreach ($routeDatas as $routeData) { if ($this->isStaticRoute($routeData)) { $this->addStaticRoute($routeData, $route); } else { $this->addVariableRoute($routeData, $route); } } return $this; }
public static function build($name = null, $pattern, array $parameters = null) { $route = new Route(); $route->setName($name); $route->setPattern($pattern); $route->setParameters($parameters); return $route; }
public function map($routeUrl, $target = '', array $args = array()) { $route = new Route(); $route->setUrl($this->basePath . $routeUrl); $route->setTarget($target); if (isset($args['methods'])) { $methods = explode(',', $args['methods']); $route->setMethods($methods); } if (isset($args['filters'])) { $route->setFilters($args['filters']); } if (isset($args['name'])) { $route->setName($args['name']); if (!isset($this->namedRoutes[$route->getName()])) { $this->namedRoutes[$route->getName()] = $route; } } $this->routes[] = $route; }
/** * @param SimpleXMLElement $xml * @return Route * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $route = new Route(); if (!empty($xml->name)) { $route->setName((string) $xml->name[0]); } if (!empty($xml->cmt)) { $route->setComment((string) $xml->cmt[0]); } if (!empty($xml->desc)) { $route->setDescription((string) $xml->desc[0]); } if (!empty($xml->src)) { $route->setSource((string) $xml->src[0]); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $route->setLinks($links); } if (!empty($xml->number)) { $route->setNumber((int) $xml->number[0]); } if (!empty($xml->type)) { $route->setType((string) $xml->type[0]); } if (!empty($xml->extensions)) { $route->setExtensions(Extensions::fromXML($xml->extensions[0])); } if (!empty($xml->rtept)) { $routePoints = []; foreach ($xml->rtept as $routePoint) { array_push($routePoints, Waypoint::fromXML($routePoint)); } $route->setRoutePoints($routePoints); } return $route; }