Get or set middleware.

@param array|string|null $middleware

@return array|\SwooleTW\Http\Websocket\Websocket
423769
public function middleware($middleware = null)
    {
        if (is_null($middleware)) {
            return $this->middleware;
        }

        if (is_string($middleware)) {
            $middleware = func_get_args();
        }

        $this->middleware = array_unique(array_merge($this->middleware, $middleware));

        return $this;
    }
1325298
public function nextClosure($middleWares, $callback)
    {
        return function () use ($middleWares, $callback) {
            $middleWares->next();
            if ($middleWares->valid()) {
                $args = $middleWares->getNextArgs();
                $response = $this->injectionClass($middleWares->current(), 'handle', $args);
            } else {
                $response = $callback();
            }

            if ($response instanceof Response) {
                $this->sendByResponse($response);
            }
        };
    }
721246
public function prependMiddleware($middleware)
    {
        if (array_search($middleware, $this->middleware) === false) {
            array_unshift($this->middleware, $middleware);
        }

        return $this;
    }
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;
    }
1084349
public function middleware($middleware)
    {
        $key = Configure::read('Security.cookieKey', md5(Configure::read('Security.salt')));

        return $middleware->add(new EncryptedCookieMiddleware(['login'], $key));
    }
554281
protected static function middleware()
    {
        foreach (self::fetch('http/middleware') as $file) {
            Bus::need($file);
        }

        Middleware::ini();
    }
781005
public function add($middleware)
    {
        if (is_array($middleware)) {
            $this->queue = array_merge($this->queue, $middleware);

            return $this;
        }
        $this->queue[] = $middleware;

        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;
    }
431654
public function sortMiddleware( $middleware ) {
		$sorted = $middleware;

		usort( $sorted, function ( $a, $b ) use ( $middleware ) {
			$a_priority = $this->getMiddlewarePriorityForMiddleware( $a );
			$b_priority = $this->getMiddlewarePriorityForMiddleware( $b );
			$priority = $b_priority - $a_priority;

			if ( $priority !== 0 ) {
				return $priority;
			}

			// Keep relative order from original array.
			return array_search( $a, $middleware ) - array_search( $b, $middleware );
		} );

		return array_values( $sorted );
	}
845982
public function setEndMiddleware($middleware)
    {
        $object = $this->marshalMiddleware($middleware);

        $this->endMiddleware = $object;

        return $this;
    }
221864
public function middleware($middleware): Route
	{
		$this->middleware = array_merge($this->middleware, (array) $middleware);

		return $this;
	}
1097497
public function middleware(...$middleware): self
    {
        foreach ($middleware as $handler) {
            $this->chains[] = $handler;
        }

        return $this;
    }
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
            ));
        }
    }
674733
protected function routeMiddleware($key, $middleware = null, $force = false)
    {
        if ($this->app->runningInConsole() && $force === false) {
            return $this->getRouter();
        }
        if (is_array($key)) {
            foreach ($key as $k => $m) {
                $this->routeMiddleware($k, $m);
            }

            return $this->getRouter();
        } else {
            $this->getRouter()->middleware($key, $middleware);
        }
    }
476911
public function getMiddlewareForMethod($method)
    {
        $middleware = [];

        foreach ($this->middleware as $name => $options) {
            if (isset($options['only']) && ! \in_array($method, (array) $options['only'])) {
                continue;
            }

            if (isset($options['except']) && \in_array($method, (array) $options['except'])) {
                continue;
            }

            $middleware[] = $name;
        }

        return $middleware;
    }
1098161
public function middleware(...$middlewares) 
	{
		foreach ($middlewares as $middleware) {
			$this->currentContext->addMiddleware($middleware);
		}

		return $this;
	}
65627
public function skip(...$middleware) : self
    {
        foreach ($middleware as $m) {
            unset($this->globalMiddleware[$m]);
        }

        return $this;
    }