/** * Add new route and append the prefix. * * @param string $name * @param Route $route * * @return Route */ public function add($name, Route $route) { // replacing route will not place the new route at end of collection // so we need to remove it first unset($this->routes[$name]); $path = '/' !== $route->getPath() ? trim($route->getPath(), '/') : ltrim($route->getPath(), '/'); $this->routes[$name] = $route; $this->routes[$name]->setPath(sprintf('%s/%s', $this->prefix, $path)); if (null !== $this->domain && !empty($this->domain)) { $this->routes[$name]->setDomain($this->domain); } if (count($this->schemas) > 0) { $this->routes[$name]->getSchema()->replace($this->schemas); } return $route->setParent($this); }