指定したミドルウェアクラスの前にミドルウェアを挿入する

@param   string  $target
検索対象ミドルウェアクラス名
@param   MiddlewareInterface $middleware
追加するミドルウェアインスタンス

@return  $this

@throws  Exception\ClassNotFoundInQueueException
@throws  Exception\MiddlewareAlreadyRegisteredException
435318
public function insertBeforeClass(
        string $target,
        MiddlewareInterface $middleware
    ){
        if(null === ($index = $this->getClassIndexes($target))){
            throw new Exception\ClassNotFoundInQueueException(
                static::createMsgClassNotFound($target)
            );
        }

        $this->insert($index, $middleware, self::INSERT_BEFORE);

        return $this;
    }
316108
protected function pushMiddleware($middleware, $force = false)
    {
        if (PHP_SAPI !== 'cli' && $force === false && $this->app->runningUnitTests() === false) {
            return $this->getHttpKernel();
        }

        $this->getHttpKernel()->pushMiddleware($middleware);
    }
871902
public function middleware($middleware)
    {
        $middleWarePath = APPPATH . '/middleware/' . $middleware . '.php';

        if (file_exists($middleWarePath)) {
            require_once($middleWarePath);

            $middleware();
        } else {
            throw new RuntimeException('Unable to load middleware file: ' . $middleWarePath);
        }
    }
221299
protected function registerMiddleware() {
    $middleware = $this->app['config']['app.middleware'];

    foreach ($middleware as $class_name) {
      $filter = app($class_name);
      if ($filter instanceof BeforeInterface) {
        array_push($this->before, $filter);
      }
      if ($filter instanceof AfterInterface) {
        array_push($this->after, $filter);
      }
    }
  }
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}]");
            }
        }
    }
475973
public function addMiddleware(MiddlewareInterface ...$middlewares) : self
    {
        foreach ($middlewares as $middleware) {
            $this->stack->push($middleware);
        }

        return $this;
    }
273158
public static function add(DispatcherAwareInterface $target)
    {
        if (!$target instanceof DispatcherAwareInterface) {
            return false;
        }

        $targetClass = strtolower(get_class($target));

        if (empty(static::$maps[$targetClass])) {
            return false;
        }

        $listeners = static::$maps[$targetClass];

        $dispatcher = $target->getDispatcher();

        foreach ($listeners as $listener) {
            $dispatcher->addListener($listener);
        }

        return true;
    }
1288999
public function addMiddleware(string $name, MiddlewareInterface $middleware): self
    {
        $this->container[$name] = $middleware;
        array_unshift($this->middleware, $name);

        return $this;
    }
1170997
public function insertMiddlewares(array $middlewares, $offset = null)
    {
        null === $offset && $offset = $this->offset;
        $chunkArray = array_chunk($this->middlewares, $offset);
        $after = [];
        $before = $chunkArray[0];
        if (isset($chunkArray[1])) {
            $after = $chunkArray[1];
        }
        $middlewares = array_merge((array)$before, $middlewares, (array)$after);
        $this->middlewares = $middlewares;
        return $this;
    }
481018
protected function mergeMiddlewareGroup(array $action, $middleware = null)
    {
        if (isset($middleware)) {
            if (isset($action['middleware'])) {
                $action['middleware'] = array_merge($middleware, $action['middleware']);
            } else {
                $action['middleware'] = $middleware;
            }
        }

        return $action;
    }
256316
public static function addMiddleware($middleware)
    {
        $kernelFile = self::read();
        if (!str_contains($kernelFile, $middleware)) {
            $kernelFile = self::insertBetween($kernelFile, 'protected $middleware = [', "]", $middleware);
            self::save($kernelFile);
        }
    }
621732
public function runMiddleware($middleware)
    {
        if ($middleware instanceof Middleware) {
            $middleware->setVitex($this);
            $middleware->call();
            return $this;
        }
        throw new Exception("中间件参数不是有效的中间件");
    }
721246
public function prependMiddleware($middleware)
    {
        if (array_search($middleware, $this->middleware) === false) {
            array_unshift($this->middleware, $middleware);
        }

        return $this;
    }
725549
protected function throwThrowableMiddleware(Throwable $error) : MiddlewareInterface
    {
        return new class($error) implements MiddlewareInterface
        {
            protected $error;

            public function __construct(Throwable $error)
            {
                $this->error = $error;
            }

            public function process(
                ServerRequestInterface $request,
                RequestHandlerInterface $requestHandler
            ) : ResponseInterface {
                throw $this->error;
            }
        };
    }
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);
        }
781005
public function add($middleware)
    {
        if (is_array($middleware)) {
            $this->queue = array_merge($this->queue, $middleware);

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

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

        return $this;
    }