public static function toRoute($name)
 {
     if (!isset(Route::getRouters()[$name])) {
         throw new \Exception('Not found route with that name', 500);
     }
     $route = Route::getRouters()[$name]['url'];
     self::to($route);
 }
 public function dispatch()
 {
     $uri = $this->request->getURI();
     $uriParams = array_filter(explode('/', $uri), 'strlen');
     $controllerName = '';
     $controllerMethod = '';
     $paramsFromGET = array();
     foreach (Route::getRouters() as $route) {
         $paramsFromGET = array();
         if ($route['method'] != $_SERVER['REQUEST_METHOD']) {
             continue;
         }
         if (in_array('auth', explode('|', $route['details']['before']))) {
             if (!Auth::isAuth()) {
                 continue;
             }
         }
         if (!Auth::isUserInRole(array_filter(explode('|', $route['details']['roles']), 'strlen'))) {
             continue;
         }
         $routeParams = array_filter(explode('/', $route['url']), 'strlen');
         $nonRequiredFieldsForRoute = $this->getNonRequiredFieldsCount($routeParams);
         if (count($uriParams) < count($routeParams) - $nonRequiredFieldsForRoute || count($uriParams) > count($routeParams)) {
             continue;
         }
         for ($i = 0; $i < count($uriParams); $i++) {
             if (!Common::startsWith($routeParams[$i], '{') && !Common::endsWith($routeParams[$i], '}')) {
                 if ($uriParams[$i] != $routeParams[$i]) {
                     continue 2;
                 }
             } else {
                 if (!$this->isParameterValid($uriParams[$i], $routeParams[$i])) {
                     continue 2;
                 }
                 $paramName = $this->getParameterName($routeParams[$i]);
                 $paramsFromGET[$paramName] = $uriParams[$i];
             }
             if (count($uriParams) - 1 == $i) {
                 $controllerData = explode('@', $route['details']['use']);
                 $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $controllerData[0];
                 $controllerMethod = $controllerData[1];
                 break 2;
             }
         }
         $paramsFromGET = array();
         if (in_array('csrf', explode('|', $route['details']['before']))) {
             if (!CSRF::validateToken()) {
                 continue;
             }
         }
     }
     if ($controllerMethod === '') {
         if (App::getInstance()->getConfig()->app['enable_default_routing']) {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $uriParams[0] . 'Controller';
             $controllerMethod = $uriParams[1];
             $r = new \ReflectionMethod($controllerName, $controllerMethod);
             $params = $r->getParameters();
             $index = 2;
             foreach ($params as $param) {
                 $paramsFromGET[$param->name] = $uriParams[$index];
                 $index++;
             }
             for ($i = $index; $i < count($uriParams); $i++) {
                 $paramsFromGET[$i] = $uriParams[$i];
             }
         } else {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . App::getInstance()->getConfig()->app['default_controller'];
             $controllerMethod = App::getInstance()->getConfig()->app['default_method'];
         }
     }
     $requestInput = $this->bindDataToControllerMethod($paramsFromGET, $controllerName, $controllerMethod);
     $controller = new $controllerName();
     $controller = DependencyProvider::injectDependenciesToController($controller);
     call_user_func_array(array($controller, $controllerMethod), $requestInput);
     Session::setOldInput(InputData::getInstance()->getPost());
 }
 public function getItem($index)
 {
     $help = new HelpPage(Route::getRouters());
     $helpData = $help->getByIndex($index);
     View::make('Help/itemPage', array('title' => $helpData['url'], 'data' => $helpData))->render();
 }