/** * Adds a route applying the common attributes */ protected function _addRoute($pattern, $paths = null, $httpMethods = null) { /** * Check if the paths need to be merged with current paths */ $defaultPaths = $this->_paths; if (is_array($defaultPaths)) { if (is_string($paths)) { $processedPaths = Route::getRoutePaths($paths); } else { $processedPaths = $paths; } if (is_array($processedPaths)) { /** * Merge the paths with the default paths */ $mergedPaths = array_merge($defaultPaths, $processedPaths); } else { $mergedPaths = $defaultPaths; } } else { $mergedPaths = $paths; } /** * Every route is internally stored as a Phalcon\Mvc\Router\Route */ $route = new Route($this->_prefix . $pattern, $mergedPaths, $httpMethods); $route->setDI($this->getDI()); $this->_routes[] = $route; $route->setGroup($this); return $route; }
/** * @param string $pattern * @param null $paths * @param null $httpMethods * @param int|mixed $position * @return Route * @throws Exception */ public function add($pattern, $paths = null, $httpMethods = null, $position = parent::POSITION_LAST) { /** * Every route is internally stored as a Phalcon\Mvc\Router\Route */ $route = new Route($pattern, $paths, $httpMethods); $route->setDI($this->getDI()); switch ($position) { case parent::POSITION_LAST: $this->_routes[] = $route; break; case parent::POSITION_FIRST: $this->_routes = array_merge([$route], $this->_routes); break; default: throw new Exception("Invalid route position"); } return $route; }