/** * constructor * * @param \Naquadria\Components\Routing\Route $route * @param array $routeData * @param array $replacer */ public function __construct(Route $route, array $routeData, array $replacer) { $this->name = $route->getName(); $this->abstraction = $route->getAbstraction(); $this->data = $routeData; $this->replacer = $replacer; $this->route = $route; }
/** * @param Route $route The unparsed route whose properties we are copying */ public function __construct(Route $route) { parent::__construct($route->getMethods(), $route->getRawPath(), $route->getController()); $this->setName($route->getName()); $this->setRawHost($route->getRawHost()); $this->addMiddleware($route->getMiddleware()); $this->setSecure($route->isSecure()); $this->setVarRegexes($route->varRegexes); }
public function go($path) { $asset = \Route::getName(); $inputfile = HOME_DIR . '/templates/' . \App::get('template') . '/' . $asset . '/' . $path; $file = new \File($inputfile); if ($file->exists()) { $this->response->setMIME($file->detectMime())->out($file->get()); } }
/** * RouteLink constructor. * * @param $params * @param \HBM\DatagridBundle\Model\Route $route */ public function __construct($params, Route $route) { parent::__construct(); $this->params = $params; if ($route !== NULL) { $this->name = $route->getName(); $this->defaults = $route->getDefaults(); } }
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; }
/** * {@inheritDoc} * * @throws RuntimeException */ protected function compileRoute(Route $route) { $parameters = $this->processPathParameters($route->getPath()); $regexp = $route->getPath(); foreach ($parameters as $parameter) { if (substr_count($route->getPath(), '{' . $parameter . '}') > 1) { throw new \RuntimeException(sprintf('Route name "%s" cannot reference variable "%s" more than once.', $route->getName(), $parameter)); } $regexp = str_replace('{' . $parameter . '}', '(?<' . $parameter . '>[A-z0-9_-]+)', $regexp); } $regexp = "#^{$regexp}\$#"; return ['parameters' => $parameters, 'regexp' => $regexp]; }
/** * @param array $routeConfig * @param Route|null $parentRoute * * @return Route */ private function processRoute(array $routeConfig, Route $parentRoute = null) { $name = $routeConfig['name']; $url = isset($routeConfig['options']['route']) ? $routeConfig['options']['route'] : ''; $controller = isset($routeConfig['options']['defaults']['controller']) ? $routeConfig['options']['defaults']['controller'] : null; $action = isset($routeConfig['options']['defaults']['action']) ? $routeConfig['options']['defaults']['action'] : null; if (null !== $parentRoute) { $name = $parentRoute->getName() . '/' . $name; $url = $parentRoute->getUrl() . $url; if (null === $controller) { $controller = $parentRoute->getController(); } } if (null === $action) { $action = 'index'; } $action .= 'Action'; return new Route($name, $url, $controller, $action); }
public function add(Route $route) { $path = $route->getParsed()->getPathPattern(); $method = $route->getMethod(); if (!isset($this->pathMethodMap[$path])) { $this->pathMethodMap[$path] = []; } else { if (in_array($method, $this->pathMethodMap[$path])) { throw new \InvalidArgumentException("Method {$method} is already defined for {$path}"); } } $name = $route->getName(); if ($name !== null) { if (isset($this->routeNames[$name])) { throw new \InvalidArgumentException("Route {$name} is already defined"); } $this->routeNames[$name] = $route; } $this->pathMethodMap[$path][] = $method; $this->routes[] = $route; }
public function setRoute(Route $route) { $this->add($route->getName(), $route->getMethod(), $route->getPath(), $route->getHandler()); }
/** * @param Route $route */ public function addRoute(Route $route) { $this->routes[$route->getName()] = $route; }
public function testGetName() { $route = new Route("herp", "derp", "target"); self::assertEquals("herp", $route->getName()); }
/** * Добавление роута в список роутов * @param Route $route */ protected static function addRoute(Route $route) { static::$_routes[$route->getName()] = $route; }
/** * @param Route $route * @param array $params * @return string */ protected function buildUrl(Route $route, array $params) { $targets = []; $replacements = []; foreach ($route->getVariableNames() as $key) { if (!isset($params[$key])) { throw new \InvalidArgumentException("Variable '{$key}' not found or null for route '{$route->getName()}'"); } $targets[] = ":" . $key; $replacements[] = $params[$key]; } return str_replace($targets, $replacements, $route->getUri()); }