Set middleware.

@param array $middleware

@return Middleware
328303
public function add(...$middleware) : self
    {
        foreach ($middleware as $m) {
            if ($m instanceof TusMiddleware) {
                $this->globalMiddleware[get_class($m)] = $m;
            } elseif (is_string($m)) {
                $this->globalMiddleware[$m] = new $m;
            }
        }

        return $this;
    }
474129
public function append(MiddlewareInterface $middleware): MiddlewarePipe
    {
        $stack = new MiddlewarePipe();

        /** @noinspection PhpParamsInspection */
        return $stack
            ->append($this)
            ->append($middleware);
    }
1326345
public function middleware($middleware, $name = null)
	{
        if($name)
            $this->properties['middleware'][$name] = $middleware;
        else
            $this->properties['middleware'][] = $middleware;

		return $this;
	}
682552
public function remove(callable $middleware) : self
    {
        $key = array_search($middleware, $this->middlewares, true);

        if (false === $key) {
            return $this;
        }

        unset($this->middlewares[$key]);

        return $this;
    }
658038
public function middleware($middleware) : ControllerMiddlewareOptions
    {
        if (!is_array($middleware)) {
            $middleware = [$middleware];
        }

        $options = new ControllerMiddlewareOptions;

        foreach ($middleware as $m) {
            $this->middleware[] = new ControllerMiddleware($m, $options);
        }

        return $options;
    }
691618
public function addMiddleware(string $name, string $middleware): void{
        $this->middleware[$name] = $middleware;
    }
1030732
public function use($middlewares) {
		$middlewares = (array)$middlewares;

		if ($this->namespace) {
			foreach ($middlewares as &$middleware) {
				$middleware = $this->namespace . $middleware;
			}
		}

		$this->middlewares = array_merge($this->middlewares, (array)$middlewares);

		return $this;
	}
239491
public function addMiddleware(MiddlewareInterface $middleware, $priority = 10)
    {
        $this->stack = $this->stack->withMiddleware($middleware, $priority);
        return $this;
    }
1022681
protected function resolve($middleware): callable
    {
        if (null === $middleware) {
            return function (RequestInterface $request, ResponseInterface $response, callable $next) {
                return $response;
            };
        }

        return $this->resolveMiddleware($middleware);
    }
451304
private function decorate($middleware): MiddlewareInterface
    {
        if ($middleware instanceof MiddlewareInterface) {
            return $middleware;
        } elseif ($middleware instanceof RequestHandlerInterface) {
            return new RequestHandlerMiddleware($middleware);
        } elseif ($middleware instanceof ResponseInterface) {
            return new FixedResponseMiddleware($middleware);
        } elseif (is_callable($middleware)) {
            return new CallableMiddleware($middleware);
        } elseif (is_string($middleware)) {
            return new LazyLoadingMiddleware($middleware, $this->container);
        } else {
            throw new InvalidArgumentException(sprintf(
                'Middleware "%s" is neither a string service name, an autoloadable class name, a PHP callable, or an instance of %s/%s/%s',
                is_object($middleware) ? get_class($middleware) : gettype($middleware),
                MiddlewareInterface::class, ResponseInterface::class, RequestHandlerInterface::class
            ));
        }
    }
721995
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        $this->getMiddlewares()->insert($middleware, $priority);

        return $this;
    }
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;
	}
296133
public function withoutMiddleware($middleware = null)
    {
        if (is_null($middleware)) {
            $this->app->instance('middleware.disable', true);

            return $this;
        }

        foreach ((array) $middleware as $abstract) {
            $this->app->instance($abstract, new class {
                public function handle($request, $next)
                {
                    return $next($request);
                }
            });
        }

        return $this;
    }
1285002
public function prependMiddlewareToGroup($group, $middleware)
    {
        if (isset($this->middlewareGroups[$group]) && ! in_array($middleware, $this->middlewareGroups[$group])) {
            array_unshift($this->middlewareGroups[$group], $middleware);
        }

        return $this;
    }
462715
public function compile($middleware)
    {
        if ($middleware instanceof MiddlewareFactory) {
            $subMiddlewares = $middleware->getSubMiddlewares();

            // Recursive compilation in sub-middlewares
            $subMiddlewares = array_map([$this, 'compile'], $subMiddlewares);

            $middleware = $middleware->create($this->container, $subMiddlewares);
        }

        return $middleware;
    }
605879
public function addMiddleware(callable $middleware, string $type = self::BEFORE)
  {
;    $type = self::validateMiddlewareType($type);
    $this->middlewares[$type][] = $middleware;
  }
747968
public function withMiddleware(string $alias, string $middleware)
    {
        if (! class_exists($middleware)) {
            throw new \Exception("Middleware not found. [{$middleware}]");
        }

        $reflection = new \ReflectionClass($middleware);
        $interfaces = $reflection->getInterfaceNames();

        $isFind = false;
        foreach ($interfaces as &$interface) {
            if ($interface === MiddlewareInterface::class) {
                $isFind = true;
                break;
            }
        }

        if (! $isFind) {
            throw new \Exception("Middleware must instanceof Weipaitang\Middleware\MiddlewareInterface. [{$middleware}]");
        }

        unset($reflection, $interfaces);

        $this->middlewares[$alias] = $middleware;

        return $this;
    }