/** * * {@inheritDoc} * @see \Ignaszak\Router\Collection\IRoute::getRouteArray() */ public function getRouteArray() : array { $file = "{$this->tmpDir}/Ignaszak_Router_Tmp_Route.php"; $tmpRoute = $this->loadTmpRoute($file); if (empty($tmpRoute)) { $routeArray = $this->route->getRouteArray(); $this->saveTmpRoute($file, $routeArray); return $routeArray; } else { return $tmpRoute; } }
/** * * @param Host $host * @param string $query * @param string $httpMethod */ public function match(Host $host = null, string $query = '', string $httpMethod = '') : array { $m = []; if (!is_null($host)) { $query = $host->getQuery(); $httpMethod = $host->getHttpMethod(); } foreach ($this->route->getRouteArray() as $name => $route) { //echo $route['path'];exit; if (preg_match($route['path'], $query, $m) && $this->httpMethod($route['method'] ?? '', $httpMethod)) { $controller = $route['controller'] ?? ''; $params = $this->createParamsArray($m, $route['tokens']); $request = ['name' => $name, 'controller' => $this->matchController($controller, $params), 'callAttachment' => $route['callAttachment'] ?? false, 'attachment' => $route['attachment'] ?? '', 'params' => $params, 'group' => $route['group'] ?? '']; $this->callAttachment($request); return $request; } } return []; }
/** * * @param IRoute $route * @param Host $host */ public function __construct(Collection\IRoute $route, Host $host = null) { $this->convertedRouteArray = $route->getRouteArray(); $this->baseUrl = !is_null($host) ? $host->getBaseURL() : ''; }