예제 #1
0
 public function parseUrl()
 {
     $routes = $this->loadAllRoutes();
     $valid = false;
     $requestUrl = $_GET['url'];
     if ($requestUrl[strlen($requestUrl) - 1] === '/' && substr_count($requestUrl, '/') > 1) {
         $requestUrl = substr($requestUrl, 0, strlen($requestUrl) - 1);
     }
     foreach ($routes as $routeInfo) {
         $routeString = $routeInfo['methodPattern'];
         preg_match("/\\A{$routeString}\\z/", $requestUrl, $test);
         if (count($test) > 0 && $_SERVER['REQUEST_METHOD'] === $routeInfo['requestType']) {
             $this->routeInfo = $routeInfo;
             $this->controller = $routeInfo['controller'];
             $this->action = $routeInfo['action'];
             $valid = true;
             if (count($test) > 1) {
                 for ($i = 1; $i < count($routeInfo['parameters']) + 1; $i++) {
                     $this->routeParams[] = $test[$i];
                 }
             }
             break;
         }
     }
     if ($valid === false) {
         RouteService::redirect('home', '404', [], true);
     }
 }
 public function register()
 {
     if ($this->isLogged()) {
         RouteService::redirect('account', 'profile', true);
     }
     return new View("user\\register", []);
 }
 /**
  * @Roles(Administrator, Editor)
  * @Route("{id:num}/delete")
  */
 public function delete($id)
 {
     $isDeleted = $this->eshopData->getCategoriesRepository()->remove($id);
     if ($isDeleted) {
         RouteService::redirect('categories', '', true);
     } else {
         echo 'Error during delete category';
     }
 }
 public function dispatch()
 {
     if (!isset($_GET['url'])) {
         RouteService::redirect('home', '', [], true);
     }
     try {
         $this->initRequest();
         $this->getRouter()->parseUrl();
         $this->initController();
         $this->invokeTheRoute();
     } catch (\Exception $e) {
         echo $e->getMessage();
         return false;
     }
 }
 /**
  * @POST
  * @Roles(Administrator, Editor)
  * @Route("{id:num}")
  */
 public function changeCategory($id, ChangeProductCategoryBindingModel $model)
 {
     $result = $this->eshopData->getProductsRepository()->changeCategory($id, $model->getCategoryId());
     RouteService::redirect('products', '', [$id], true);
 }
 /**
  * @Authorize
  */
 public function logout()
 {
     if ($this->isLogged()) {
         Session::emptyUserRelated();
         RouteService::redirect('home', '', true);
     }
 }
 /**
  * @POST
  * @Roles(Administrator)
  */
 public function banip(BanIpBindingModel $model)
 {
     $this->eshopData->getUsersRepository()->banIP($model->getIpAddress());
     RouteService::redirect('admin', 'ban', [], true);
 }