marshalMiddleware

@param   mixed $middleware

@return  MiddlewareInterface
@throws \ReflectionException
338206
protected function marshalMiddleware($middleware)
    {
        if (!$middleware instanceof Psr7InvokableInterface) {
            $middleware = new Psr7Middleware($middleware);
        }

        return parent::marshalMiddleware($middleware);
    }
979768
public function middleware( $middleware = null )
	{
		if ( is_null( $middleware ) )
			return (array) Arr::get( $this->action, 'middleware', [] );

		if ( is_string( $middleware ) )
			$middleware = [$middleware];

		$this->action['middleware'] = array_merge( (array) Arr::get( $this->action, 'middleware', [] ), $middleware );

		return $this;
	}
424479
public function registerMiddleware(IMiddleware $middleware): IOAuthClient
    {
        $middleware->setClient($this);
        foreach ($middleware::statusCode() as $statusCode) {
            $this->postRequestMiddlewares[$statusCode][] = $middleware;
        }

        return $this;
    }
630640
public function middleware( $middleware, array $options = [] )
	{
		foreach ( (array) $middleware as $middlewareName )
			$this->middleware[$middlewareName] = &$options;

		return new ControllerMiddlewareOptions( $options );
	}
457444
public function pushMiddlewareToGroup($group, $middleware)
    {
        if (! array_key_exists($group, $this->middlewareGroups)) {
            $this->middlewareGroups[$group] = array();
        }

        if (! in_array($middleware, $this->middlewareGroups[$group])) {
            $this->middlewareGroups[$group][] = $middleware;
        }

        return $this;
    }
410256
public static function factory(array $middlewares = array())
    {
        $runner = null;
        foreach ($middlewares as $middleware) {
            $runner = $runner ? $runner->add($middleware) : new static($middleware);
        }
        return $runner;
    }
281527
protected function pushMiddleware($middleware, $force = false)
    {
        if ($this->app->runningInConsole() && $force === false) {
            return $this->getHttpKernel();
        }

        return $this->getHttpKernel()->pushMiddleware($middleware);
    }
294208
public function getMiddlewares()
    {
        $middlewares = $this->middlewares();

        foreach ($middlewares as $key => $middleware) {
            $this->middlewares[$key] = $middleware;
        }

        return $this->middlewares;
    }
408028
public function validMiddleware(array &$middlewares)
    {
        if (! $middlewares) {
            return;
        }

        foreach ($middlewares as &$middleware) {
            if ($middleware instanceof \Closure) {
                continue;
            }

            if (! $this->hasMiddleware($middleware)) {
                throw new \Exception("Middleware not found. [{$middleware}]");
            }
        }
    }
451434
public function setMiddleware($middleware)
    {
        if ($this->lock) {
            throw new Exception('Route cannot be modified');
        }

        $curMiddleware = [];
        if (is_array($middleware)) {
            $curMiddleware = $middleware;
        } else {
            $args = func_get_args();
            foreach ($args as $arg) {
                if (is_string($arg)) {
                    $curMiddleware[] = $arg;
                }
            }
        }

        //Add group middleware if any
        $this->middleware = (new Collection(Router::$groupsProps['middleware']))
                        ->flatten()->toArray();
        foreach ($curMiddleware as $value) {
            if (in_array($value, $this->middleware)) {
                continue;
            }
            $this->middleware[] = $value;
        }

        return $this;
    }
1251165
protected function newMiddleware(string $name): Middleware
    {
        try {
            $middleware = Reflection::newInstance($name);
        } catch (ReflectionException $e) {
            throw new MiddlewareException('Middleware error while retrieving "%s"', $name, 0, $e);
        }

        return $middleware;
    }
578621
public function removeMiddleware(MiddlewareInterface $middleware)
    {
        $this->stack = $this->stack->withoutMiddleware($middleware);
        return $this;
    }
770052
public static function middleware( $laravelMiddleware, $middleware = array() ) {
		$packageMiddleware = array();
		$path = base_path('config/packages.json');
		if( file_exists( $path ) ) {
			$data = json_decode( file_get_contents( $path ) );
			if( isset( $data->middleware ) ) {
				$packageMiddleware = (array)$data->middleware;
			}
		}
		return array_merge( $laravelMiddleware, $middleware, $packageMiddleware );
	}
278724
protected function parseMiddleware($middleware)
    {
        list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, array());

        if (is_string($parameters)) {
            $parameters = explode(',', $parameters);
        }

        return array($name, $parameters);
    }
1150440
public function pushMiddlewareToGroup( $group, $middleware )
	{
		if ( isset( $this->middlewareGroups[$group] ) && !in_array( $middleware, $this->middlewareGroups[$group] ) )
		{
			$this->middlewareGroups[$group][] = $middleware;
		}

		return $this;
	}
865754
private function get(ServerRequestInterface $request)
    {
        $middleware = current($this->middleware);
        next($this->middleware);

        if ($middleware === false) {
            return $middleware;
        }

        if (is_array($middleware)) {
            $conditions = $middleware;
            $middleware = array_pop($conditions);

            foreach ($conditions as $condition) {
                if ($condition === true) {
                    continue;
                }

                if ($condition === false) {
                    return $this->get($request);
                }

                if (is_string($condition)) {
                    $condition = new Matchers\Path($condition);
                } elseif (!is_callable($condition)) {
                    throw new InvalidArgumentException('Invalid matcher. Must be a boolean, string or a callable');
                }

                if (!$condition($request)) {
                    return $this->get($request);
                }
            }
        }

        if (is_string($middleware)) {
            if ($this->container === null) {
                throw new InvalidArgumentException(sprintf('No valid middleware provided (%s)', $middleware));
            }

            $middleware = $this->container->get($middleware);
        }

        if ($middleware instanceof Closure) {
            return self::createMiddlewareFromClosure($middleware);
        }

        if ($middleware instanceof MiddlewareInterface) {
            return $middleware;
        }

        throw new InvalidArgumentException(sprintf('No valid middleware provided (%s)', is_object($middleware) ? get_class($middleware) : gettype($middleware)));
    }
1097497
public function middleware(...$middleware): self
    {
        foreach ($middleware as $handler) {
            $this->chains[] = $handler;
        }

        return $this;
    }