Example #1
0
 /**
  * Processing routes
  */
 private function getRoute()
 {
     $route = array();
     include_once _SYSDIR_ . 'system/Routes.php';
     $router = null;
     $uri = mb_strtolower(trim(_URI_, '/'));
     $uriPos = mb_strpos($uri, '?');
     if ($uriPos !== false) {
         $uri = mb_substr($uri, 0, $uriPos);
     }
     // Проверка заданых путей
     foreach ($route as $value) {
         if (preg_match($value['pattern'], $uri, $matches)) {
             $router['options'] = array();
             $router['uri'] = array();
             $uri = trim(mb_substr($uri, mb_strlen($matches[0])), '/');
             unset($matches[0]);
             $router['controller'] = $value['controller'];
             $router['action'] = $value['action'];
             $router['options'] = array_values($matches);
             if (!empty($uri)) {
                 $router['uri'] = explode('/', $uri);
             }
             break;
         }
     }
     // Если нет заданых путей(Routes)
     if (!is_array($router)) {
         $uriArray = explode('/', $uri);
         $uriCount = count($uriArray);
         $router['options'] = array();
         $router['uri'] = array();
         if ($uriCount < 3) {
             if (!empty($uriArray[0])) {
                 $router['controller'] = $uriArray[0];
             } else {
                 $router['controller'] = DEFAULT_CONTROLLER;
             }
             if (!empty($uriArray[1])) {
                 $router['action'] = $uriArray[1];
             } else {
                 $router['action'] = DEFAULT_ACTION;
             }
         } else {
             $router['controller'] = $uriArray[0];
             $router['action'] = $uriArray[1];
             unset($uriArray[0]);
             unset($uriArray[1]);
             $router['uri'] = array_values($uriArray);
         }
     }
     // Delete array route
     unset($route);
     define('CONTROLLER', $router['controller']);
     define('ACTION', $router['action']);
     if (is_array($router['options'])) {
         Request::setUriOptions($router['options']);
     }
     if (is_array($router['uri'])) {
         Request::setUri($router['uri']);
     }
     $this->router = $router;
 }