Prepend a middleware to the init step.

@param callable $middleware Middleware function to add.
@param string   $name       Name of the middleware.
427369
public function prependInit(callable $middleware, $name = null)
    {
        $this->add(self::INIT, $name, $middleware, true);
    }
1231809
protected function prependMiddleware($middleware, $force = false)
    {
        if (PHP_SAPI !== 'cli' && $force === false) {
            $this->getHttpKernel();
        }

        $this->getHttpKernel()->prependMiddleware($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
            ));
        }
    }
15141
def add_middleware(middleware: EFBMiddleware):
    
    global middlewares
    if isinstance(middleware, EFBMiddleware):
        middlewares.append(middleware)
    else:
        raise TypeError("Middleware instance is expected")
1037244
protected function setNotFoundDecoratorMiddleware() : void
    {
        $middleware = $this->getStrategy()->getNotFoundDecorator(new NotFoundException);
        $this->prependMiddleware($middleware);
    }
1206879
public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
    {
        $stack = new MiddlewarePipe();

        /** @noinspection PhpParamsInspection */
        return $stack
            ->prepend($this)
            ->prepend($middleware);
    }
292634
public static function RoutesMiddleware($name)
    {
        if (!self::existsRoutesMiddleware($name)) {
            throw new MiddlewareNotFoundException($name);
        }
        $middleware = self::allRoutesMiddleware();

        return array_get($middleware, $name);
    }
514346
public function make($name, callable $callback) {
        $blueprint = new Blueprint($name, $this->config->getAdminURIPrefix());
        $callback($blueprint);
        $this->blueprints[$blueprint->getName()] = $blueprint;

        if($blueprint->hasPrimaryToolbarItem()) {
            $this->navigation->add($blueprint->getPrimaryToolbarItem());
        }
    }
848005
public function prepend($middleware)
        {
            if (!is_string($middleware) && !$middleware instanceof MiddlewareInterface) {
                throw new \InvalidArgumentException('Middleware must be a string or an instance of MiddlewareInterface');
            }

            $class = is_string($middleware) ? new $middleware : $middleware;
            array_unshift($this->middleware, $class);
        }
256316
public static function addMiddleware($middleware)
    {
        $kernelFile = self::read();
        if (!str_contains($kernelFile, $middleware)) {
            $kernelFile = self::insertBetween($kernelFile, 'protected $middleware = [', "]", $middleware);
            self::save($kernelFile);
        }
    }
918079
public function prependAttempt(callable $middleware, $name = null)
    {
        $this->add(self::ATTEMPT, $name, $middleware, true);
    }
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;
    }
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;
    }
415629
public function add(string $name, callable $callback): \IvoPetkov\BearFrameworkAddons\ServerRequests
    {
        $this->callbacks[$name] = $callback;
        return $this;
    }
1266600
public function addUserCallback ($name, callable $callback)
	{
		if (isset ($this->usercallback[$name]))
			throw new InvalidParameter ("A usercallback with name " . $name . " is already set. Each callback must have a unique name.");

		$this->usercallback[$name] = $callback;

		return $this;
	}
1051552
public function middleware($definition, $prepend = false)
    {
        if ($this->freezed) {
            throw new InvalidCallException('The middleware stack is already called, no middleware can be added');
        }

        if ($prepend) {
            array_unshift($this->middleware, $definition);
        } else {
            $this->middleware[] = $definition;
        }
    }
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);
            }
        }

    }