ding callback for a given binding. * * @param string $key * @return \Closure|null */ public function getBindingCallback($key) { if (isset($this->binders[$key = str_replace('-', '_', $key)])) { return $this->binders[$key]; } } /** * Get the global "where" patterns. * * @return array */ public function getPatterns() { return $this->patterns; } /** * Set a global where pattern on all routes. * * @param string $key * @param string $pattern * @return void */ public function pattern($key, $pattern) { $this->patterns[$key] = $pattern; } /** * Set a group of global where patterns on all routes. * * @param array $patterns * @return void */ public function patterns($patterns) { foreach ($patterns as $key => $pattern) { $this->pattern($key, $pattern); } } /** * Determine if the router currently has a group stack. * * @return bool */ public function hasGroupStack() { return ! empty($this->groupStack); } /** * Get the current group stack for the router. * * @return array */ public function getGroupStack() { return $this->groupStack; } /** * Get a route parameter for the current route. * * @param string $key * @param string|null $default * @return mixed */ public function input($key, $default = null) { return $this->current()->parameter($key, $default); } /** * Get the request currently being dispatched. * * @return \Illuminate\Http\Request */ public function getCurrentRequest() { return $this->currentRequest; } /** * Get the currently dispatched route instance. * * @return \Illuminate\Routing\Route|null */ public function getCurrentRoute() { return $this->current(); } /** * Get the currently dispatched route instance. * * @return \Illuminate\Routing\Route|null */ public function current() { return $this->current; } /** * Check if a route with the given name exists. * * @param string $name * @return bool */ public function has($name) { $names = is_array($name) ? $name : func_get_args(); foreach ($names as $value) { if (! $this->routes->hasNamedRoute($value)) { return false; } } return true; } /** * Get the current route name. * * @return string|null */ public function currentRouteName() { return $this->current() ? $this->current()->getName() : null; } /** * Alias for the "currentRouteNamed" method. * * @param mixed ...$patterns * @return bool */ public function is(...$patterns) { return $this->currentRouteNamed(...$patterns); } /** * Determine if the current route matches a pattern. * * @param mixed ...$patterns * @return bool */ public function currentRouteNamed(...$patterns) { return $this->current() && $this->current()->named(...$patterns); } /** * Get the current route action. * * @return string|null */ public function currentRouteAction() { if ($this->current()) { return $this->current()->getAction()['controller'] ?? null; } } /** * Alias for the "currentRouteUses" method. * * @param array ...$patterns * @return bool */ public function uses(...$patterns) { foreach ($patterns as $pattern) { if (Str::is($pattern, $this->currentRouteAction())) { return true; } } return false; } /** * Determine if the current route action matches a given action. * * @param string $action * @return bool */ public function currentRouteUses($action) { return $this->currentRouteAction() == $action; } /** * Set the unmapped global resource parameters to singular. * * @param bool $singular * @return void */ public function singularResourceParameters($singular = true) { ResourceRegistrar::singularParameters($singular); } /** * Set the global resource parameter mapping. * * @param array $parameters * @return void */ public function resourceParameters(array $parameters = []) { ResourceRegistrar::setParameters($parameters); } /** * Get or set the verbs used in the resource URIs. * * @param array $verbs * @return array|null */ public function resourceVerbs(array $verbs = []) { return ResourceRegistrar::verbs($verbs); } /** * Get the underlying route collection. * * @return \Illuminate\Routing\RouteCollectionInterface */ public function getRoutes() { return $this->routes; } /** * Set the route collection instance. * * @param \Illuminate\Routing\RouteCollection $routes * @return void */ public function setRoutes(RouteCollection $routes) { foreach ($routes as $route) { $route->setRouter($this)->setContainer($this->container); } $this->routes = $routes; $this->container->instance('routes', $this->routes); } /** * Set the compiled route collection instance. * * @param array $routes * @return void */ public function setCompiledRoutes(array $routes) { $this->routes = (new CompiledRouteCollection($routes['compiled'], $routes['attributes'])) ->setRouter($this) ->setContainer($this->container); $this->container->instance('routes', $this->routes); } /** * Remove any duplicate middleware from the given array. * * @param array $middleware * @return array */ public static function uniqueMiddleware(array $middleware) { $seen = []; $result = []; foreach ($middleware as $value) { $key = \is_object($value) ? \spl_object_id($value) : $value; if (! isset($seen[$key])) { $seen[$key] = true; $result[] = $value; } } return $result; } /** * Set the container instance used by the router. * * @param \Illuminate\Container\Container $container * @return $this */ public function setContainer(Container $container) { $this->container = $container; return $this; } /** * Dynamically handle calls into the router instance. * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { if (static::hasMacro($method)) { return $this->macroCall($method, $parameters); } if ($method === 'middleware') { return (new RouteRegistrar($this))->attribute($method, is_array($parameters[0]) ? $parameters[0] : $parameters); } return (new RouteRegistrar($this))->attribute($method, array_key_exists(0, $parameters) ? $parameters[0] : true); } }