/** * * @param string $file * @throws RouterException */ private function saveTmpRoute(string $file, array $routes) { $data = "<?php\n\nreturn [\n'checksum' => '" . $this->route->getChecksum() . "',\n'routes' => " . var_export($routes, true) . "\n];\n\n"; if (!@file_put_contents($file, $data)) { throw new RouterException("Unable to save {$file}"); } }
/** * * @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() : ''; }