添加中间件

@param array $middlewares ...
@return array
498598
public function addMiddlewares(...$middlewares): array
    {
        $stack = $this->getMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
1299728
public function expandMiddlewareAtom( $middleware ) {
		if ( isset( $this->middleware[ $middleware ] ) ) {
			return $this->middleware[ $middleware ];
		}

		if ( class_exists( $middleware ) ) {
			return $middleware;
		}

		throw new ConfigurationException( 'Unknown middleware "' . $middleware . '" used.' );
	}
419286
public static function addStaticMiddlewares(...$middlewares): array
    {
        $stack = static::getStaticMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
630640
public function middleware( $middleware, array $options = [] )
	{
		foreach ( (array) $middleware as $middlewareName )
			$this->middleware[$middlewareName] = &$options;

		return new ControllerMiddlewareOptions( $options );
	}
1281071
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        $this->middlewares->insert($middleware, $priority);

        return $this;
    }
588876
public function get($uri, $handler, $middlewares = array())
    {
        return $this->add($this->route('GET', $uri, $handler, $middlewares));
    }
1364559
public function withMiddleware($middleware = null)
    {
        if (is_null($middleware)) {
            unset($this->app['middleware.disable']);

            return $this;
        }

        foreach ((array) $middleware as $abstract) {
            unset($this->app[$abstract]);
        }

        return $this;
    }
522256
protected function executeMiddlewares($middlewares){
        //Analizo los filtros y los aplico en caso de que corresponda
        $middlewaresDefinition = $this->app->context->getMiddlewaresDefinition();
        foreach ($middlewares as $middlewareName) {
            if (! isset($middlewaresDefinition[$middlewareName])) {
                Error::general_error('Middleware Error', 'The middleware ' . $middlewareName . ' dont exists');
            }
            
            $middleware = $middlewaresDefinition[$middlewareName];
            
            $dir = $this->buildDir($middleware, 'middlewares');
            $class = $this->buildClass($middleware);
            if(!class_exists($class)){
                //Si la clase no existe intento cargarla
                if(file_exists($dir)){
                    require_once $dir;
                }else{
                    //Avisa que el archivo no existe
                    Error::general_error('Middleware Error', 'The middleware ' . $middleware['class'] . ' dont exists');
                } 
            }
            $middlewareIns= new $class();
            //Analizo si hay parametros en la configuracion
            if(isset($middleware['properties'])){
                $this->app->dependenciesEngine->injectProperties($middlewareIns, $middleware['properties']);
            }
            //Analiza si existe el metodo filtrar
            if(method_exists($middlewareIns, 'handle')){
                $rta= $middlewareIns->handle($this->httpRequest, $this->httpResponse);
                if($rta === false){
                    return false;
                }
            }
            else{
                Error::general_error('Middleware Error', 'The middleware ' . $middleware['class'] . ' dont implement the method handle()');
            }
        }
    }
91285
protected function orderMiddlewareByPriority(array $middleware): array
	{
		if(empty($this->middlewarePriority))
		{
			return $middleware;
		}

		$priority = array_intersect_key($this->middlewarePriority, $middleware) + array_fill_keys(array_keys(array_diff_key($middleware, $this->middlewarePriority)), static::MIDDLEWARE_DEFAULT_PRIORITY);

		// Sort the priority map using stable sorting

		$position = 0;

		foreach($priority as $key => $value)
		{
			$priority[$key] = [$position++, $value];
		}

		uasort($priority, function($a, $b)
		{
			return $a[1] === $b[1] ? ($a[0] > $b[0] ? 1 : -1) : ($a[1] > $b[1] ? 1 : -1);
		});

		foreach($priority as $key => $value)
		{
			$priority[$key] = $value[1];
		}

		// Return sorted middleware list

		return array_merge($priority, $middleware);
	}
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}]");
            }
        }
    }
420502
protected function parseMiddlewareToPipelines(array $middlewares) : array
    {
        $pipes = [];
        // check all types and store value into pipes array
        foreach ($middlewares as $middleware) {
            if (is_object($middleware)) {
                $pipes[] = $middleware;
            } elseif (string_has($middleware, ':')) {
                $pipes[] = $middleware;
            } else {
                $pipes[] = $this->container->make($middleware);
            }
        }

        return $pipes;
    }
1361704
public function expandMiddleware( $middleware ) {
		$classes = [];

		foreach ( $middleware as $item ) {
			$classes = array_merge(
				$classes,
				$this->expandMiddlewareMolecule( $item )
			);
		}

		return $classes;
	}
1180012
public static function factory(array $middlewares = array())
    {
        $stack = new static;
        foreach ($middlewares as $middleware) {
            $stack = $stack->add($middleware);
        }
        return $stack;
    }
843830
public function middleware(...$middlewares): void
    {
        foreach ($middlewares as $middleware) {
            if (!$middleware instanceof MiddlewareInterface && !\is_string($middleware)) {
                $type = \is_object($middleware) ? \get_class($middleware) : \gettype($middleware);
                
                throw new \InvalidArgumentException(\sprintf('Unsupported middleware type: %s', $type));
            }
            
            $this->middlewares[] = $middleware;
        }
    }
1315684
public function addMiddleware($middleware, array $properties = array())
    {
        if($this->route)
        {
            $this->route->addMiddleware($middleware, $properties);
        }
        else
        {
            $this->middlewares[] = array($middleware, $properties);
        }

        return $this;
    }
944416
public function setMiddleware($middleware)
    {
        if($this->route)
            $this->route->setMiddleware($middleware);
        else
            $this->middlewares = array(array($middleware));

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

		return $this;
	}