Illuminate\Routing\Router::resolveMiddlewareClassName PHP Method

resolveMiddlewareClassName() public method

Resolve the middleware name to a class name(s) preserving passed parameters.
public resolveMiddlewareClassName ( string $name ) : string | array
$name string
return string | array
    public function resolveMiddlewareClassName($name)
    {
        $map = $this->middleware;
        // When the middleware is simply a Closure, we will return this Closure instance
        // directly so that Closures can be registered as middleware inline, which is
        // convenient on occasions when the developers are experimenting with them.
        if ($name instanceof Closure) {
            return $name;
        } elseif (isset($map[$name]) && $map[$name] instanceof Closure) {
            return $map[$name];
            // If the middleware is the name of a middleware group, we will return the array
            // of middlewares that belong to the group. This allows developers to group a
            // set of middleware under single keys that can be conveniently referenced.
        } elseif (isset($this->middlewareGroups[$name])) {
            return $this->parseMiddlewareGroup($name);
            // Finally, when the middleware is simply a string mapped to a class name the
            // middleware name will get parsed into the full class name and parameters
            // which may be run using the Pipeline which accepts this string format.
        } else {
            list($name, $parameters) = array_pad(explode(':', $name, 2), 2, null);
            return (isset($map[$name]) ? $map[$name] : $name) . (!is_null($parameters) ? ':' . $parameters : '');
        }
    }

Usage Example

 /**
  * Get the middleware for the controller instance.
  *
  * @param  \Illuminate\Routing\Controller  $instance
  * @param  string  $method
  * @return array
  */
 protected function getMiddleware($instance, $method)
 {
     $results = new Collection();
     foreach ($instance->getMiddleware() as $name => $options) {
         if (!$this->methodExcludedByOptions($method, $options)) {
             $results[] = $this->router->resolveMiddlewareClassName($name);
         }
     }
     return $results->flatten()->all();
 }
All Usage Examples Of Illuminate\Routing\Router::resolveMiddlewareClassName