本文整理汇总了PHP中Illuminate\Routing\Router::current方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::current方法的具体用法?PHP Router::current怎么用?PHP Router::current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCurrentResource
/**
* 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;
}
示例2: handle
/**
* 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);
}
示例3: getData
/**
* @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);
}
示例4: getCurrentPage
/**
* 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;
}
示例5: handle
/**
* 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);
}
示例6: alias
/**
* Match route by alias.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @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;
}
示例7: routerMatched
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();
}
}
}
示例8: routerMatched
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();
}
}
示例9: map
/**
* 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()]);
}]);
}
}
示例10: hasAccess
/**
* 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;
}
示例11: routeParam
/**
* 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;
}
示例12: extractAttributes
/**
* 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;
}
示例13: collect
/**
* {@inheritDoc}
*/
public function collect()
{
$route = $this->router->current();
return $this->getRouteInformation($route);
}
示例14: makeMenuList
/**
* 관리페이지 메뉴 목록을 생성한다. 현재 요청의 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());
}
示例15: makeMenuList
/**
* 관리페이지 메뉴 목록을 생성한다. 현재 요청의 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());
}