add a middleware, with optionnal priority.
If a class is given as third argument, the middleware will be added <i>after</i>
the middleware that has this class.
@param mixed $middleware
@param int $priority
@param string $after
@param string $before
979838
public function pipe($middleware, ?int $priority = 1, ?string $before = null)
    {
        if(is_object($middleware)) {
            $class = get_class($middleware);
        } else if(is_string($middleware) && class_exists($middleware)) {
            $class = $middleware;
        }
        if(isset($class) && ! isset($this->middlewareClasses[$class])) {
            $this->middlewareClasses[$class] = $middleware;
        }

        $this->getMiddlewareGroup()->addMiddleware($middleware, $priority, $before);
    }
586436
public function before($callback, $priority = 0)
    {
        $app = $this;

        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($callback, $app) {
            if (!$event->isMasterRequest()) {
                return;
            }

            $ret = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $app);

            if ($ret instanceof Response) {
                $event->setResponse($ret);
            }
        }, $priority);
    }
427369
public function prependInit(callable $middleware, $name = null)
    {
        $this->add(self::INIT, $name, $middleware, true);
    }
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);
        }
    }
1281071
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        $this->middlewares->insert($middleware, $priority);

        return $this;
    }
667702
public function prepend(MiddlewareInterface $middleware){
        if($this->isAlreadyRegistered($middleware)){
            throw new Exception\MiddlewareAlreadyRegisteredException(
                static::createMsgAlreadyRegisterd($middleware)
            );
        }

        $this->registerd[$middleware]   = true;

        $this->queue->unshift($middleware);

        return $this;
    }
19027
public function setPriority($priority)
    {
        if (!OptionsPriorities::isValid($priority)) {
            throw new InvalidOptionsException('priority is not valid, please refer to the documentation or use the constants of the class "OptionsPriorities"');
        }
        $this->priority = $priority;

        return $this;
    }
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;
        }
    }
618412
public function addProvider(PathProviderInterface $provider, $priority = 0)
    {
        $this->providers[$priority][] = $provider;
        $this->sorted                 = null;
    }
308486
public function after($findName, callable $middleware, $withName = '')
    {
        $this->splice($findName, $withName, $middleware, false);
    }
239491
public function addMiddleware(MiddlewareInterface $middleware, $priority = 10)
    {
        $this->stack = $this->stack->withMiddleware($middleware, $priority);
        return $this;
    }
1059495
public function listen($events, $listener, $priority = 0)
    {
        if ($priority === 0) {
            $this->events->on($events, $listener);
            return;
        }

        if ($priority > 5) {
            $this->events->onBefore($events, $listener);
            return;
        }

        $this->events->onAfter($events, $listener);

    }
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;
        }
    }
1276414
public function addEventHandler($eventName, $eventHandlerName, $priority = 50)
    {
        $this->addHandler(self::EVENT, $eventName, $eventHandlerName, $priority);
    }
1194505
public function addAction( $action, $callback, $priority = 10 )
    {
        if ( !isset( $this->actions[ $action ] ) )
        {
            $this->actions[ $action ] = array();
        }

        $this->actions[ $action ][] = array(
            'priority' => $priority,
            'callback' => $callback,
        );

        if ( 1 < count( $this->actions[ $action ] ) )
        {
            usort( $this->actions[ $action ], array( $this, '_sortByPriority' ) );
        }

        if ( $this->debug )
        {
            echo PHP_EOL . '+ACTION: ' . $action . ' -> '
                    . $this->_serializeCallback( $callback )
                    . ' + Priority: ' . $priority
                    . PHP_EOL;
        }
    }
1197256
def use(middleware, *args, &block)
      return if faraday.builder.locked?
      faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
    end
230942
public function insertAfterClass(
        string $target,
        MiddlewareInterface $middleware
    ){
        if(null === ($index = $this->getClassIndexes($target))){
            throw new Exception\ClassNotFoundInQueueException(
                static::createMsgClassNotFound($target)
            );
        }

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

        return $this;
    }