指定したミドルウェアオブジェクトの前にミドルウェアを挿入する

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

@return  $this

@throws  Exception\ObjectNotFoundInQueueException
760467
public function insertBeforeObject(
        MiddlewareInterface $target,
        MiddlewareInterface $middleware
    ){
        if(null === ($index = $this->getObjectIndexes($target))){
            throw new Exception\ObjectNotFoundInQueueException(
                static::createMsgObjectNotFound($target)
            );
        }
        $this->insert($index, $middleware, self::INSERT_BEFORE);

        return $this;
    }
79183
public function setMiddlewareGroup($name)
    {
        if (!empty(self::$middleware[$name])) {
            foreach (self::$middleware[$name] as $name => $rule) {
                $this->middleware($name, $rule);
            }
        }

        return $this;
    }
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;
    }
365105
public function pushMiddleware(callable $middleware, string $name = null)
    {
        if (!is_null($name)) {
            $this->middlewares[$name] = $middleware;
        } else {
            array_push($this->middlewares, $middleware);
        }

        return $this;
    }
1175813
public function middleware($middleware, array $options = [])
    {
        foreach ((array) $middleware as $m) {
            $this->middleware[] = [
                'middleware' => $m,
                'options' => &$options,
            ];
        }

        return new ControllerMiddlewareOptions($options);
    }
256316
public static function addMiddleware($middleware)
    {
        $kernelFile = self::read();
        if (!str_contains($kernelFile, $middleware)) {
            $kernelFile = self::insertBetween($kernelFile, 'protected $middleware = [', "]", $middleware);
            self::save($kernelFile);
        }
    }
1315684
public function addMiddleware($middleware, array $properties = array())
    {
        if($this->route)
        {
            $this->route->addMiddleware($middleware, $properties);
        }
        else
        {
            $this->middlewares[] = array($middleware, $properties);
        }

        return $this;
    }
1087527
protected function runMiddleware(
        $middleware,
        RequestInterface $request,
        ResponseInterface $response
    )/*# : ResponseInterface */ {
        // instance of MiddlewareInterface
        if (is_object($middleware) && $middleware instanceof MiddlewareInterface) {
            return $middleware->process($request, $response, $this);

        // old style callable
        } elseif (is_callable($middleware)) {
            return $middleware($request, $response, $this);

        // unknown middleware type
        } else {
            throw new LogicException(
                Message::get(Message::MIDDLEWARE_INVALID, $middleware),
                Message::MIDDLEWARE_INVALID
            );
        }
    }
1342282
public function before(... $middlewares)
  {
    foreach ($middlewares as $middleware) {
      $this->currentContext->addMiddleware($middleware, RoutingContext::BEFORE);
    }

    return $this;
  }
970046
public function run(
        ServerRequestInterface $request,
        ResponseInterface $response
    )
    {

        if ($this->running)
            throw new \RuntimeException(
                "Failed to run middleware queue: Queue is already running"
            );

        $this->running = true;
        $this->save();

        $next = function (
            ServerRequestInterface $request,
            ResponseInterface $response
        ) use (&$next) {

            if (count($this->middleware) > 0) {

                $middleware = array_shift($this->middleware);
                $response = call_user_func($middleware, $request, $response, $next);

                if (!($response instanceof ResponseInterface))
                    throw new \RuntimeException(
                        "Failed to run middleware: Middleware didn't return ".
                        "a valid ".ResponseInterface::class." object"
                    );
            }

            $this->running = false;
            $this->restore();
            return $response;
        };

        return $next($request, $response);
    }
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;
    }
1281071
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        $this->middlewares->insert($middleware, $priority);

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

		return $this;
	}
1326345
public function middleware($middleware, $name = null)
	{
        if($name)
            $this->properties['middleware'][$name] = $middleware;
        else
            $this->properties['middleware'][] = $middleware;

		return $this;
	}
1016249
protected function addMiddleware($middleware)
    {
        $kernel = $this->app['Illuminate\Contracts\Http\Kernel'];

        if (is_array($middleware)) {
            foreach ($middleware as $ware) {
                $kernel->pushMiddleware($ware);
            }
        } else {
            $kernel->pushMiddleware($middleware);
        }
    }
621732
public function runMiddleware($middleware)
    {
        if ($middleware instanceof Middleware) {
            $middleware->setVitex($this);
            $middleware->call();
            return $this;
        }
        throw new Exception("中间件参数不是有效的中间件");
    }
979768
public function middleware( $middleware = null )
	{
		if ( is_null( $middleware ) )
			return (array) Arr::get( $this->action, 'middleware', [] );

		if ( is_string( $middleware ) )
			$middleware = [$middleware];

		$this->action['middleware'] = array_merge( (array) Arr::get( $this->action, 'middleware', [] ), $middleware );

		return $this;
	}