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()); }
Route::GET('/edit/{id:int}', array('use' => 'CategoryController@getEdit', 'before' => 'auth', 'roles' => 'editor|admin')); Route::POST('/edit/{id:int}', array('use' => 'CategoryController@postEdit', 'before' => 'auth', 'roles' => 'editor|admin')); }); Route::Group('product', array(), function () { Route::GET('/{id:int}', array('use' => 'ProductController@getProduct')); Route::GET('/delete/{id:int}', array('use' => 'ProductController@delete', 'before' => 'auth', 'roles' => 'editor|admin')); Route::GET('/add', array('use' => 'ProductController@getAdd', 'before' => 'auth', 'roles' => 'editor|admin')); Route::POST('/add', array('use' => 'ProductController@postAdd', 'before' => 'auth', 'roles' => 'editor|admin')); Route::GET('/edit/{id:int}', array('use' => 'ProductController@getEdit', 'before' => 'auth', 'roles' => 'editor|admin')); Route::POST('/edit/{id:int}', array('use' => 'ProductController@postEdit', 'before' => 'auth', 'roles' => 'editor|admin')); Route::POST('/{id:int}/add/comment', array('use' => 'CommentController@post', 'before' => 'auth|csrf')); }); Route::Group('promotion', array(), function () { Route::GET('', array('use' => 'PromotionController@getAll', 'before' => 'auth', 'roles' => 'editor|admin')); Route::GET('/delete/{id:int}', array('use' => 'PromotionController@delete', 'before' => 'auth', 'roles' => 'editor|admin')); Route::GET('/add', array('use' => 'PromotionController@getAdd', 'before' => 'auth', 'roles' => 'editor|admin')); Route::POST('/add', array('use' => 'PromotionController@postAdd', 'before' => 'auth', 'roles' => 'editor|admin')); //Route::GET('/edit/{id:int}', array('use' => 'PromotionController@getEdit', 'before' => 'auth', 'roles' => 'editor|admin')); //Route::POST('/edit/{id:int}', array('use' => 'PromotionController@postEdit', 'before' => 'auth', 'roles' => 'editor|admin')); }); Route::Group('admin', array('roles' => 'admin', 'before' => 'auth'), function () { Route::GET('/users', array('use' => 'AdminController@getUsers')); Route::GET('/make/{id:int}/{role}', array('use' => 'AdminController@setRole')); Route::GET('/ban/{id:int}', array('use' => 'AdminController@banUser')); }); Route::GET('comment/delete/{id:int}', array('use' => 'CommentController@delete', 'before' => 'auth')); Route::GET('test', array('use' => 'testController@EditUser3')); ////Route::GET('users/edit/{id?}', array('use'=>'UsersController@EditUser','before'=>'csrf|auth')); ////Route::GET('users/edit', array('use'=>'UsersController@EditUser','before'=>'csrf|auth')); //Route::GET('users/delete/{sas:int}/{sss}', array('use'=>'UsersController@EditUser2','before'=>'csrf','roles'=>'admin|edit')); //Route::POST('users/test/{test1}', array('use'=>'UsersController@testmethod','before'=>'csrf'));
public function getItem($index) { $help = new HelpPage(Route::getRouters()); $helpData = $help->getByIndex($index); View::make('Help/itemPage', array('title' => $helpData['url'], 'data' => $helpData))->render(); }
Route::POST('/add', array('use' => 'CategoryController@postAdd')); Route::GET('/{id:int}/edit', array('use' => 'CategoryController@getEdit')); Route::POST('/{id:int}/edit', array('use' => 'CategoryController@postEdit')); }); Route::Group('/city', array(), function () { Route::GET('/', array('use' => 'CityController@index')); Route::GET('/{id:int}/delete', array('use' => 'CityController@deleteCity')); Route::GET('/add', array('use' => 'CityController@getAdd')); Route::POST('/add', array('use' => 'CityController@postAdd')); Route::GET('/{id:int}/edit', array('use' => 'CityController@getEdit')); Route::POST('/{id:int}/edit', array('use' => 'CityController@postEdit')); }); Route::Group('/estate', array(), function () { Route::GET('/add', array('use' => 'EstateController@getAdd')); Route::POST('/add', array('use' => 'EstateController@postAdd')); Route::GET('/{id:int}/edit', array('use' => 'EstateController@getEdit')); Route::POST('/{id:int}/edit', array('use' => 'EstateController@postEdit')); Route::GET('/{id:int}/delete', array('use' => 'EstateController@delete')); }); Route::GET('/image/delete/{id:int}', array('use' => 'ImageController@delete')); Route::GET('/messages/{orderBy?}/{type?}', array('use' => 'MessageController@index')); Route::GET('/message/{id:int}', array('use' => 'MessageController@get')); }); Route::Group('estate', array(), function () { Route::GET('/{id:int}/message', array('use' => 'MessageController@getAdd')); Route::POST('/{id:int}/message', array('use' => 'MessageController@postAdd')); Route::GET('/favorites/{id:int}/add', array('use' => 'UserController@addToFavourites')); Route::GET('/favorites/{id:int}/remove', array('use' => 'UserController@removeFromFavourites')); }); Route::GET('favorites', array('use' => 'UserController@getFavourites'));