示例#1
0
文件: Cache.php 项目: ignaszak/router
 /**
  *
  * {@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;
     }
 }
示例#2
0
 /**
  *
  * @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 [];
 }
示例#3
0
 /**
  *
  * @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() : '';
 }