/** * Set offset * @param mixed $index * @param IResourceRouter $route * * @throws InvalidStateException */ public function offsetSet($index, $route) { if (!$route instanceof IResourceRouter && !$route instanceof ResourceRouteList) { throw new InvalidStateException('ResourceRouteList expects IResourceRoute, ' . get_class($route) . ' given.'); } parent::offsetSet($index, $route); }
/** * @param string[][] $routes */ public function __construct(array $routes) { parent::__construct(); foreach ($routes as $mask => $parameters) { $this[] = new Route($mask, array_key_exists('defaults', $parameters) ? $parameters['defaults'] : []); } }
public function __construct(Container $context) { parent::__construct(); $secured = NULL; if ($context->getParameters()['tls']) { Route::$defaultFlags |= Route::SECURED; $secured = Route::SECURED; } $this[] = new StaticRouter(['Homepage:default' => 'index.php'], StaticRouter::ONE_WAY | $secured); $this[] = new StaticRouter(['Homepage:default' => '', 'Homepage:marathon' => 'maraton', 'Homepage:preklad' => 'preklad', 'Profile:default' => 'profil', 'Auth:in' => 'prihlaseni', 'Auth:out' => 'odhlaseni', 'Auth:registration' => 'registrace', 'Auth:resetPassword' => 'heslo', 'Text:about' => 'o-skole', 'Text:team' => 'o-skole/tym', 'Subjects:default' => 'predmety', 'File:opensearch' => 'opensearch.xml', 'File:robots' => 'robots.txt', 'Sitemap:default' => 'sitemap.xml', 'Text:tos' => 'podminky', 'Text:privacy' => 'soukromi'], $secured); $this[] = new Route('vyhledavani/?hledat=<query>', 'Search:results'); $this[] = new Route('vyhledavani/cviceni', 'Search:blueprints'); $this[] = new Route('schema/[<action \\D+>/]<schemaId \\d+>[-<slug>]', 'Schema:default'); $this[] = new Route('blok/[<action \\D+>/][<schemaId \\d+>/]<blockId \\d+>[-<slug>]', 'Block:default'); $this[] = new Route('video/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<videoId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Video:default'); $this[] = new Route('cviceni/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blueprintId \\d+>[-<slug>]', 'Blueprint:default'); $this[] = new Route('tabule/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blackboardId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Blackboard:default'); // old links $this[] = new Route('video/<youtubeId>', 'Video:youtube'); $this[] = new Redirect('dobrovolnici', 'https://wiki.khanovaskola.cz/doku.php?id=dobrovolnici'); $this[] = new Redirect('dobrovolnici/preklad', 'https://wiki.khanovaskola.cz/doku.php?id=jaknato'); $this[] = new Redirect('dobrovolnici/pravidla-prekladu', 'https://wiki.khanovaskola.cz/doku.php?id=pravidla'); $this[] = new Redirect('o-skole/projekty', 'https://wiki.khanovaskola.cz/doku.php?id=start'); $this[] = new Redirect('kontakt', 'https://wiki.khanovaskola.cz/doku.php?id=tym'); $this[] = $context->createInstance(Routers\OldVideo::class); $this[] = $context->createInstance(Routers\OldCategory::class); $this[] = $context->createInstance(Routers\OldBlog::class); $this[] = new Route('<presenter>/<action \\D+>[/<id>]', 'Homepage:default'); }
public function __construct(string $wwwDir, Ytnuk\Web\Domain\Repository $repository, VitKutny\Version\Filter $versionFilter, Tracy\ILogger $logger, Nette\Caching\IStorage $storage) { parent::__construct(); $this->wwwDir = $wwwDir; $this->repository = $repository; $this->logger = $logger; $this->cache = new Nette\Caching\Cache($storage, strtr(self::class, '\\', Nette\Caching\Cache::NAMESPACE_SEPARATOR)); $this->filterInCache = $this->cache->derive('filterIn'); $this->filterOutCache = $this->cache->derive('filterOut'); $this->versionFilter = $versionFilter; }
/** * @param $name * @param $args * * @return mixed|Router * @throws \InvalidArgumentException */ public function __call($name, $args) { if (in_array($name, ['get', 'post', 'put', 'delete'])) { if (count($args) < 1) { throw new \InvalidArgumentException('Mask has to be set.'); } $metadata = isset($args[1]) ? $args[1] : []; $flags = isset($args[2]) ? $args[2] : 0; $this[] = new Route($name, $args[0], $metadata, $flags); return $this; } return parent::__call($name, $args); }
/** * @return RouteList * @throws RouterException */ public function createRouter() { foreach ($this->routers as $router) { if (array_search($this->getClass($router), $this->forbiddenRouters) !== FALSE) { continue; } if (!is_object($router)) { $router = new $router(); } if (!$router instanceof IRouter) { throw new RouterException('Class ' . get_class($router) . ' must implements ' . IRouter::class); } $router->createRouter($this); $this->isMain = FALSE; if ($this->finished) { break; } } $return = new RouteList(); foreach ($this->modules as $module => $values) { $routeList = new RouteList($module); /** @var RouteList $list */ foreach ($values as $list) { if ($list) { foreach ($list->getIterator() as $route) { $routeList[] = $route; } } } $routeList->warmupCache(); $return[] = $routeList; } return $return; }