public function dispatch()
 {
     if ($this->router == null) {
         throw new \Exception('No valid router found', 500);
     }
     $_uri = $this->router->getURI();
     $routes = \SoftUni\FMK\App::getInstance()->getConfig()->routes;
     $_routeController = null;
     if (is_array($routes) && count($routes) > 0) {
         foreach ($routes as $key => $value) {
             if (stripos($_uri, $key) === 0 && ($_uri == $key || stripos($_uri, $key . '/') === 0) && $value['namespace']) {
                 $this->namespace = $value['namespace'];
                 $_uri = substr($_uri, strlen($key) + 1);
                 $_routeController = $value;
                 break;
             }
         }
     } else {
         throw new \Exception('Default route missing.', 500);
     }
     if ($this->namespace == null && $routes['*']['namespace']) {
         $this->namespace = $routes['*']['namespace'];
         $_routeController = $routes['*'];
     } elseif ($this->namespace == null && !$routes['*']['namespace']) {
         throw new \Exception('Default route missing', 500);
     }
     $input = \SoftUni\FMK\InputData::getInstance();
     $_params = explode('/', $_uri);
     if ($_params[0]) {
         $this->controller = strtolower(array_shift($_params));
         if ($_params[0]) {
             $this->method = strtolower(array_shift($_params));
             $input->setGet(array_values($_params));
         } else {
             $this->method = $this->getDefaultMethod();
         }
     } else {
         $this->controller = $this->getDefaultController();
         $this->method = $this->getDefaultMethod();
     }
     if (is_array($_routeController) && $_routeController['controllers']) {
         if ($_routeController['controllers'][$this->controller]['methods'][$this->method]) {
             $this->method = strtolower($_routeController['controllers'][$this->controller]['methods'][$this->method]);
         }
         if (isset($_routeController['controllers'][$this->controller]['to'])) {
             $this->controller = strtolower($_routeController['controllers'][$this->controller]['to']);
         }
     }
     $input->setPost($this->router->getPost());
     $f = $this->namespace . '\\' . ucfirst($this->controller);
     $newController = new $f();
     $newController->{$this->method}();
 }
 public function test()
 {
     $val = new \SoftUni\FMK\Validator();
     $val->setRule('minlength', 'sisi', 3);
     var_dump($val->validate());
     print_r($val->getErrors());
     $view = \SoftUni\FMK\View::getInstance();
     $view->username = '******';
     $view->appendToLayout('body', 'admin.index');
     $view->appendToLayout('body2', 'index');
     $view->display('layouts.default', ['ala', 'bala']);
     \SoftUni\FMK\InputData::getInstance()->get(0, 'int');
     \SoftUni\FMK\App::getInstance()->displayError(404);
     exit;
 }