current() public method

Get the currently dispatched route instance.
public current ( ) : Illuminate\Routing\Route
return Illuminate\Routing\Route
Example #1
0
 /**
  * Get the name of the resource currently being accessed.
  *
  * @return string
  */
 public function getCurrentResource()
 {
     if ($currentRoute = $this->router->current()) {
         return $currentRoute->getAction()['resource'];
     }
     return null;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $route = $this->router->current()->methods()[0] . ' /' . $this->router->current()->uri();
     $isPermissionAllRoutes = RoutePermissionModel::getRoutePermissionsRoles('*');
     if ($isPermissionAllRoutes) {
         if (($user = $this->user($request)) === 401) {
             return response()->json(null, 401);
         }
         $hasRole = $user->hasRole($isPermissionAllRoutes->roles, false);
         $hasPerms = $user->can($isPermissionAllRoutes->permissions, false);
         $hasRolePerm = $hasRole || $hasPerms || is_array($isPermissionAllRoutes->roles) && in_array('@', $isPermissionAllRoutes->roles);
         if (!$hasRolePerm) {
             return response()->json(null, 403);
         }
     }
     $routePermission = RoutePermissionModel::getRoutePermissionsRoles($route);
     if ($routePermission) {
         if (($user = $this->user($request)) === 401) {
             return response()->json(null, 401);
         }
         $hasRole = $user->hasRole($routePermission->roles, false);
         $hasPerms = $user->can($routePermission->permissions, false);
         $hasRolePerm = $hasRole || $hasPerms || is_array($routePermission->roles) && in_array('@', $routePermission->roles);
         if (!$hasRolePerm) {
             return response()->json(null, 403);
         }
     }
     return $next($request);
 }
 /**
  * @return mixed get the data to be serialized
  */
 public function getData()
 {
     $this->router = app('router');
     $this->url = app('url');
     $data = array('currentRoute' => $this->router->current());
     $routes = $this->router->getRoutes();
     $results = array();
     foreach ($routes as $name => $route) {
         $results[] = $this->getRouteInformation($route, $data['currentRoute']);
     }
     $data['routes'] = $results;
     return array('router' => $data);
 }
Example #4
0
 /**
  * Get the number of current page.
  *
  * @return integer
  */
 public function getCurrentPage()
 {
     $page = (int) $this->currentPage;
     if (true === empty($page)) {
         $page = $this->router->current()->parameter($this->pageName, null);
     }
     if (null === $page) {
         $page = $this->request->query->get($this->pageName, 1);
     }
     if ($page < 1 || false === filter_var($page, FILTER_VALIDATE_INT)) {
         return 1;
     }
     return $page;
 }
Example #5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $route['route_method'] = $this->router->current()->methods()[0];
     $route['route_name'] = '/' . $this->router->current()->uri();
     $isAllowGuest = PermissionRouteModel::isAllowGuest($route);
     if (!$isAllowGuest) {
         if (($user = $this->user($request)) === 401) {
             return response()->json(null, 401);
         }
         $isAllPermission = PermissionRouteModel::isAllPermission($user);
         if (!$isAllPermission) {
             if (!PermissionRouteModel::hasPermission($user, $route)) {
                 return response()->json(null, 403);
             }
         }
     }
     return $next($request);
 }
Example #6
0
 /**
  * Match route by alias.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  string|array $aliases
  * @return string
  */
 public function alias($aliases)
 {
     // Retrieve current request
     $currentRoute = $this->router->current();
     if (empty($currentRoute)) {
         return $this->inactiveClass;
     }
     // Make sure patterns is an array
     $aliases = !is_array($aliases) ? [$aliases] : $aliases;
     // Current route's alias
     $routeAlias = $this->router->currentRouteName();
     // Check aliases and look for matches
     foreach ($aliases as $alias) {
         if ($routeAlias == $alias) {
             return $this->activeClass;
         }
     }
     return $this->inactiveClass;
 }
Example #7
0
 public function routerMatched()
 {
     if ($this->config->get('enabled') && $this->config->get('log_routes')) {
         if ($this->dataRepositoryManager->routeIsTrackable($this->route)) {
             $this->dataRepositoryManager->updateRoute($this->getRoutePathId($this->route->current()));
         } else {
             $this->deleteCurrentLog();
         }
     }
 }
Example #8
0
 public function routerMatched($log)
 {
     if ($this->dataRepositoryManager->routeIsTrackable($this->route)) {
         if ($log) {
             $this->dataRepositoryManager->updateRoute($this->getRoutePathId($this->route->current()));
         }
     } else {
         $this->turnOff();
         $this->deleteCurrentLog();
     }
 }
Example #9
0
 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function map(Router $router)
 {
     $router->group(['namespace' => $this->namespace], function ($router) {
         require app_path('Http/routes.php');
     });
     foreach (Page::all() as $page) {
         $router->get($page->uri, ['as' => $page->name, function () use($page, $router) {
             return $this->app->call('SundaySim\\Http\\Controllers\\PageController@show', ['page' => $page, 'parameters' => $router->current()->parameters()]);
         }]);
     }
 }
 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function map(Router $router)
 {
     $router->group(['namespace' => $this->namespace], function ($router) {
         require app_path('Http/routes.php');
     });
     //trouble with artisan wrap this round the for
     //if (! app()-&gt;runningInConsole()) {
     // foreach loop over all pages...
     //}
     foreach (Page::all() as $page) {
         $router->get($page->uri, ['as' => $page->name, function () use($page, $router) {
             return $this->app->call('EddiesBlog\\Http\\Controllers\\PageController@show', ['page' => $page, 'parameters' => $router->current()->parameters()]);
         }]);
     }
 }
Example #11
0
 /**
  * Validate a current route/action against a user on top level
  * this function is used in the filter to validate
  * therefore we dont have to check if the route has role control
  *
  * @return boolean
  */
 public function hasAccess()
 {
     // If a user is not logged in then we quit
     if ($this->auth->guest()) {
         return false;
     }
     // Get an instance of the current route
     $route = $this->router->current();
     if ($access = $this->checkRouteAgainstUser($this->makeRouteCheck((string) $route->domain(), (string) head($route->methods()), 'uri', (string) $route->uri()))) {
         // Set access level on the current route
         $this->accessLevel = (int) $access->acl;
         return true;
     }
     return false;
 }
Example #12
0
 /**
  * Return 'active' class if the current route name matches a specific value, route parameters with keys defined in
  * the `$params` has the correct value.
  *
  * The `$params` is an associative array, the key is name of the route parameter, the item is the desired value of
  * that parameter.
  *
  * @param string $routeName
  * @param array  $params
  * @param string $activeClass
  * @param string $inactiveClass
  *
  * @return string
  *
  * @since 2.3.0
  */
 public function routeParam($routeName, array $params, $activeClass = 'active', $inactiveClass = '')
 {
     $route = $this->_router->current();
     if (!$route) {
         return $inactiveClass;
     }
     if ($route->getName() != $routeName) {
         return $inactiveClass;
     }
     foreach ($params as $key => $value) {
         if ($route->parameter($key) != $value) {
             return $inactiveClass;
         }
     }
     return $activeClass;
 }
 /**
  * Extract attributes for current url
  *
  * @param  string|null|false $url to extract attributes, if not present, the system will look for attributes in the current call
  *
  * @return array    Array with attributes
  *
  */
 protected function extractAttributes($url = false)
 {
     if (!empty($url)) {
         $attributes = [];
         $parse = parse_url($url);
         if (isset($parse['path'])) {
             $parse = explode("/", $parse['path']);
         } else {
             $parse = [];
         }
         $url = [];
         foreach ($parse as $segment) {
             if (!empty($segment)) {
                 $url[] = $segment;
             }
         }
         foreach ($this->router->getRoutes() as $route) {
             $path = $route->getUri();
             if (!preg_match("/{[\\w]+}/", $path)) {
                 continue;
             }
             $path = explode("/", $path);
             $i = 0;
             $match = true;
             foreach ($path as $j => $segment) {
                 if (isset($url[$i])) {
                     if ($segment === $url[$i]) {
                         $i++;
                         continue;
                     }
                     if (preg_match("/{[\\w]+}/", $segment)) {
                         // must-have parameters
                         $attribute_name = preg_replace(["/}/", "/{/", "/\\?/"], "", $segment);
                         $attributes[$attribute_name] = $url[$i];
                         $i++;
                         continue;
                     }
                     if (preg_match("/{[\\w]+\\?}/", $segment)) {
                         // optional parameters
                         if (!isset($path[$j + 1]) || $path[$j + 1] !== $url[$i]) {
                             // optional parameter taken
                             $attribute_name = preg_replace(["/}/", "/{/", "/\\?/"], "", $segment);
                             $attributes[$attribute_name] = $url[$i];
                             $i++;
                             continue;
                         }
                     }
                 } else {
                     if (!preg_match("/{[\\w]+\\?}/", $segment)) {
                         // no optional parameters but no more $url given
                         // this route does not match the url
                         $match = false;
                         break;
                     }
                 }
             }
             if (isset($url[$i + 1])) {
                 $match = false;
             }
             if ($match) {
                 return $attributes;
             }
         }
     } else {
         if (!$this->router->current()) {
             return [];
         }
         $attributes = $this->router->current()->parameters();
         $response = event('routes.translation', [$attributes]);
         if (!empty($response)) {
             $response = array_shift($response);
         }
         if (is_array($response)) {
             $attributes = array_merge($attributes, $response);
         }
     }
     return $attributes;
 }
 /**
  * {@inheritDoc}
  */
 public function collect()
 {
     $route = $this->router->current();
     return $this->getRouteInformation($route);
 }
 /**
  * 관리페이지 메뉴 목록을 생성한다. 현재 요청의 user와 route 정보를 이용하여 선택된 메뉴, 감추어야할 메뉴를 설정한다.
  *
  * @param Router  $router  router
  * @param boolean $isSuper 최고관리자 여부
  *
  * @return void
  */
 protected function makeMenuList(Router $router, $isSuper)
 {
     // 등록된 menu list를 가져온다.
     $menus = $this->getRegisteredMenus();
     // menu를 tree로 구성한다.
     $this->menuList = new Tree($menus);
     // menu가 지정된 route 목록을 가져온다.
     $routes = $router->getRoutes()->getSettingsMenuRoutes();
     // 각 메뉴에 해당되는 route를 지정한다.
     foreach ($routes as $route) {
         /** @var Route $route */
         $menuIds = array_get($route->getAction(), 'settings_menu', []);
         // 만약 route에 permission 정보가 있고, 그 permission을 현재 member가 통과하지 못하면 display=false로 지정한다.
         $permissions = array_get($route->getAction(), 'permission', []);
         $visible = false;
         if (false && !$isSuper) {
             foreach ((array) $permissions as $permissionId) {
                 // todo: implementing
                 $instance = new Instance('settings.' . $permissionId);
                 $perm = app('xe.permission')->get($instance->getName(), $instance->getSiteKey());
                 if ($perm === null) {
                     $visible = false;
                     continue;
                 }
                 if ($this->gate->allows('access', $instance)) {
                     $visible = true;
                 }
             }
         } else {
             $visible = true;
         }
         // 메뉴에 route 지정,
         foreach ((array) $menuIds as $menuId) {
             $menu = $this->menuList[$menuId];
             $menu->route = $route;
             if ($visible === false) {
                 $menu->display = false;
             }
         }
     }
     $this->setSelectedMenu($router->current());
 }
 /**
  * 관리페이지 메뉴 목록을 생성한다. 현재 요청의 user와 route 정보를 이용하여 선택된 메뉴, 감추어야할 메뉴를 설정한다.
  *
  * @param Router  $router  router
  * @param boolean $isSuper 최고관리자 여부
  *
  * @return void
  */
 protected function makeMenuList(Router $router, $isSuper)
 {
     // 등록된 menu list를 가져온다.
     $menus = $this->getRegisteredMenus();
     // menu를 tree로 구성한다.
     $this->menuList = new TreeCollection($menus);
     // menu가 지정된 route 목록을 가져온다.
     $routes = $router->getRoutes()->getSettingsMenuRoutes();
     // 각 메뉴에 해당되는 route를 지정한다.
     foreach ($routes as $route) {
         /** @var Route $route */
         $menuIds = array_get($route->getAction(), 'settings_menu', []);
         // 만약 route에 permission 정보가 있고, 그 permission을 현재 member가 통과하지 못하면 display=false로 지정한다.
         $permissions = array_get($route->getAction(), 'permission', []);
         $visible = false;
         if (!$isSuper) {
             foreach ((array) $permissions as $permissionId) {
                 $registered = $this->permissions->make('settings', $permissionId);
                 if ($registered->ables(Action::ACCESS) === true) {
                     $visible = true;
                 }
             }
         } else {
             $visible = true;
         }
         // 메뉴에 route 지정,
         foreach ((array) $menuIds as $menuId) {
             $menu = $this->menuList[$menuId];
             $menu->route = $route;
             if ($visible === false) {
                 $menu->display = false;
             }
         }
     }
     $this->setSelectedMenu($router->current());
 }
Example #17
0
 /**
  * Use current route for generating url
  *
  * @TODO $route->parameters() can throw Exception if it has no parameters defined
  *       it should be handled, but Laravel UrlGenerator can't generate urls with extra params
  *       so maybe it's better to leave it that way.
  * @return \DeSmart\Pagination\Paginator
  */
 public function useCurrentRoute()
 {
     $route = $this->router->current();
     return $this->route($route, $route->parameters());
 }
 /**
  * {@inheritDoc}
  */
 public function authorize(Router $router)
 {
     /** @noinspection PhpUndefinedFieldInspection */
     return $this->container->make(RouterAuth::class)->hasAccess($router->current()->getName()) !== false;
 }
Example #19
0
 /**
  * Map dynamic article routes using the slug.
  *
  * @param \Illuminate\Routing\Router $router
  */
 protected function mapCategoryRoutes(Router $router)
 {
     try {
         /** @var \Yajra\CMS\Repositories\Category\Repository $repository */
         $repository = app('categories');
         $repository->getAllPublished()->each(function (Category $category) use($router) {
             $middleware = ['web'];
             if ($category->requiresAuthentication()) {
                 $middleware[] = 'auth';
             }
             $router->get($category->present()->slug, function () use($category, $router) {
                 return $this->app->call(CategoryController::class . '@show', ['category' => $category, 'parameters' => $router->current()->parameters()]);
             })->middleware($middleware)->name($category->getRouteName());
             /** @var \DaveJamesMiller\Breadcrumbs\Manager $breadcrumb */
             $breadcrumb = app('breadcrumbs');
             $breadcrumb->register($category->getRouteName(), function (\DaveJamesMiller\Breadcrumbs\Generator $breadcrumbs) use($category) {
                 if ($category->isChild() && $category->depth > 1) {
                     $parent = $category->ancestors()->where('depth', '<>', 0)->first();
                     $breadcrumbs->parent($parent->getRouteName());
                 } else {
                     $breadcrumbs->parent('home');
                 }
                 $breadcrumbs->push($category->title, route($category->getRouteName()));
             });
         });
     } catch (QueryException $e) {
         // \\_(",)_//
     }
 }
Example #20
0
 /**
  * Get the currently dispatched route instance.
  *
  * @return \Illuminate\Routing\Route 
  * @static 
  */
 public static function current()
 {
     return \Illuminate\Routing\Router::current();
 }
Example #21
0
 public function routerMatched()
 {
     if ($this->config->get('enabled')) {
         $this->dataRepositoryManager->updateRoute($this->getRoutePathId($this->route->current()));
     }
 }