Ejemplo n.º 1
0
 public function attemptToFindRoute()
 {
     $request = Service::get('request');
     $uri = $request->getURI();
     if ($uri != '/') {
         rtrim($uri, '/');
     }
     $result = NULL;
     foreach ($this->routes as $route => $rContent) {
         $requirements = isset($rContent["_requirements"]) ? $rContent["_requirements"] : NULL;
         $pattern = preg_replace('~\\{\\w+\\}~', isset($requirements["id"]) ? '(' . $requirements["id"] . ')' : '([\\w\\d]+)', $rContent['pattern']);
         //����� �������� ���� ������� ��������� � requirements � ����������� ������������� (c)����
         if (preg_match(self::DLMTR . "^" . $pattern . "\$" . self::DLMTR, $uri, $match) && isset($requirements["_method"])) {
             if ($requirements["_method"] !== $request->getMethod()) {
                 continue;
             }
             $result = $this->routes[$route];
             $result['name'] = $route;
             if (!empty($match[1])) {
                 $result['variables'] = [$match[1]];
             }
             self::$currentRoute = $result;
             return $result;
         }
         if (preg_match(self::DLMTR . "^" . $pattern . "\$" . self::DLMTR, $uri, $match)) {
             $result = $this->routes[$route];
             $result['name'] = $route;
             if (!empty($match[1])) {
                 $result['variables'] = [$match[1]];
             }
             self::$currentRoute = $result;
             return $result;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Конструктор, принимает на вход конфиг роутера
  * @param $config_array array ассоциативный массив с роутами
  */
 public function __construct($config_array)
 {
     foreach ($config_array as $name => $config) {
         //добавить слеш в конец, если его там нет
         if (!$this->isEndsWithSlash($config["pattern"])) {
             $config_array[$name]["pattern"] = $config["pattern"] . "/";
         }
     }
     self::$logger = Service::get("logger");
     $this->config_array = $config_array;
 }
Ejemplo n.º 3
0
 /**
  * Class construct
  */
 public function __construct($routing_map = array())
 {
     self::$map = (array) $routing_map;
 }
Ejemplo n.º 4
0
 /**
  * Get array of routes
  *
  * Router constructor.
  * @param array $path_routes_map
  */
 public function __construct($path_routes_map = array())
 {
     self::$map = $path_routes_map;
 }
Ejemplo n.º 5
0
 public function __construct($route)
 {
     self::$routes1 = $route;
 }