Append a middleware to the validate step.

@param callable $middleware Middleware function to add.
@param string   $name       Name of the middleware.
3856
public function appendValidate(callable $middleware, $name = null)
    {
        $this->add(self::VALIDATE, $name, $middleware);
    }
334937
public function prependSign(callable $middleware, $name = null)
    {
        $this->add(self::SIGN, $name, $middleware, true);
    }
694109
public function addMiddleware(callable $middleware)
    {
        if (!is_callable($middleware)) {
            throw new \InvalidArgumentException(sprintf(
                'Expected callable, received %s',
                gettype($middleware)
            ));
        }

        $this->middleware[] = $middleware;

        return $this;
    }
157062
private function add($step, $name, callable $middleware, $prepend = false)
    {
        $this->sorted = null;

        if ($prepend) {
            $this->steps[$step][] = [$middleware, $name];
        } else {
            array_unshift($this->steps[$step], [$middleware, $name]);
        }

        if ($name) {
            $this->named[$name] = $step;
        }
    }
1007736
public function middleware($request, &$response)
    {
        $that = $this;
        if ($middleware = current($this->middleware)) {
            next($this->middleware);
            $middleware->next($request, $response, function ($request, $response) use ($that) {
                $that->middleware($request, $response);
            });
        }
    }
1351327
public function add(MiddlewareInterface $middleware): self
    {
        $pipe = clone $this;
        array_push($pipe->middlewares, $middleware);
        return $pipe;
    }
292634
public static function RoutesMiddleware($name)
    {
        if (!self::existsRoutesMiddleware($name)) {
            throw new MiddlewareNotFoundException($name);
        }
        $middleware = self::allRoutesMiddleware();

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

        return $this;
    }
238279
private function pushMiddlewaresInDefinition($alias_namespace, $middlewares_directory, &$default_definitions)
    {
        $middleware_files = get_files($middlewares_directory);
        if (!empty($middleware_files))
        {
            $middlewares = array_map(function($middleware) use($middlewares_directory) {
                $new_middleware = str_replace("{$middlewares_directory}/", "", $middleware);
                return basename(str_replace("/", "\\", $new_middleware), ".php");
            }, $middleware_files);

            $errors = [];

            foreach ($middlewares as $middleware) {
                if ($alias_namespace === "\\")
                {
                    $middleware_definition = $middleware;
                    $middleware_definition_value = get_app_namespace() . "Middlewares\\{$middleware}";
                }
                else
                {
                    $module_name = str_replace("App\\", "", $alias_namespace);

                    $middleware_sub_namespace = str_replace(app_path() . "/{$module_name}/Middlewares", "", $middlewares_directory);
                    $middleware_sub_namespace = str_replace("/", "\\", $middleware_sub_namespace);

                    $middleware_definition = "{$alias_namespace}{$middleware}";
                    $middleware_definition_value = "{$alias_namespace}Middlewares\\{$middleware}";
                }

                if (!array_key_exists("{$middleware_definition}", $default_definitions))
                {
                    $default_definitions["{$middleware_definition}"] = function(ContainerInterface $c) use ($middleware_definition_value)
                    {
                        return new $middleware_definition_value($c);
                    };
                }
                else
                {
                    $errors[] = "{$middleware} is already exist inside of definitions.";
                }
            }

            if (!empty($errors))
            {
                exit("Error: Please fix the ff. before run the application: <li>" . implode("</li><li>", $errors));
            }
        }
        else
        {
            exit("Error: No middleware found in {$middlewares_directory} path.");
        }
    }
691618
public function addMiddleware(string $name, string $middleware): void{
        $this->middleware[$name] = $middleware;
    }
15141
def add_middleware(middleware: EFBMiddleware):
    
    global middlewares
    if isinstance(middleware, EFBMiddleware):
        middlewares.append(middleware)
    else:
        raise TypeError("Middleware instance is expected")
141124
protected function addRouteMiddleware($routeMiddleware)
    {
        if (is_array($routeMiddleware) && (count($routeMiddleware) > 0)) {
            foreach ($routeMiddleware as $key => $middleware) {
                $this->middleware($key, $middleware);
            }
        }
    }
1315433
private function addMiddleware($middleware, $args, $push = true)
    {
        $instance = $this->resolve($middleware);

        $types = $this->getTypes($instance);

        if (!count($types)) {
            throw new InvalidArgumentException('The first argument must be an instance of PrepareableInterface, RespondableInterface or CloseableInterface.');
        }

        //Replace middleware definition with instance
        $args[0] = $instance;

        foreach ($types as $type) {
            if ($push) {
                array_push($this->{$type . 'Middlewares'}, $args);
            } else {
                array_unshift($this->{$type . 'Middlewares'}, $args);
            }
        }

    }
446784
public function appendBuild(callable $middleware, $name = null)
    {
        $this->add(self::BUILD, $name, $middleware);
    }
680763
public function prependBuild(callable $middleware, $name = null)
    {
        $this->add(self::BUILD, $name, $middleware, true);
    }
1269605
public function appendInit(callable $middleware, $name = null)
    {
        $this->add(self::INIT, $name, $middleware);
    }
277926
protected function middleware($name, $except = [])
    {
        $args = (array) $name;
        if (empty($args)) {
            return;
        }

        if (!empty($except)) {
            $route = request()->getRoute();
            $targetMethod = $route->getTargetMethod();

            foreach ($except as $method) {
                if ($targetMethod === $method) {
                    return;
                }
            }
        }

        foreach ($args as $name) {
            $this->middlewares[] = config("middlewares.$name");
        }
    }