Push a middleware to the top of the stack.

@param callable $middleware Middleware function
@param string   $name       Name to register for this middleware.
188474
public function push(callable $middleware, $name = '')
    {
        $this->stack[] = [$middleware, $name];
        $this->cached = null;
    }
16779
public function add($path, $middleware = null)
    {
        if (!isset($middleware)) {
            $middleware = $path;
            $path = null;
        }

        if (!empty($path) && !ctype_digit($path) && $path[0] !== '/') {
            trigger_error("Middleware path '$path' doesn't start with a '/'", E_USER_NOTICE);
        }
        
        if (!is_callable($middleware)) {
            throw new \InvalidArgumentException("Middleware should be callable");
        }

        if (!empty($path)) {
            $middleware = $this->wrapMiddleware($path, $middleware);
        }
        
        $this->middlewares[] = $middleware;
        
        return $this;
    }
944416
public function setMiddleware($middleware)
    {
        if($this->route)
            $this->route->setMiddleware($middleware);
        else
            $this->middlewares = array(array($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);
        }
    }
446784
public function appendBuild(callable $middleware, $name = null)
    {
        $this->add(self::BUILD, $name, $middleware);
    }
338206
protected function marshalMiddleware($middleware)
    {
        if (!$middleware instanceof Psr7InvokableInterface) {
            $middleware = new Psr7Middleware($middleware);
        }

        return parent::marshalMiddleware($middleware);
    }
691477
protected function parseMiddleware($name)
    {
        list($name, $parameters) = array_pad(explode(':', $name, 2), 2, null);

        //
        $callable = isset($this->middleware[$name]) ? $this->middleware[$name] : $name;

        if (is_null($parameters)) {
            return $callable;
        }

        // When the callable is a string, we will add back the parameters before returning.
        else if (is_string($callable)) {
            return $callable .':' .$parameters;
        }

        // A callback with parameters; we should create a proper middleware closure for it.
        $parameters = explode(',', $parameters);

        return function ($passable, $stack) use ($callable, $parameters)
        {
            return call_user_func_array(
                $callable, array_merge(array($passable, $stack), $parameters)
            );
        };
    }
1044211
public static function create(array $middlewares)
    {
        if (empty($middlewares)) {
            throw new StackException('Middlewares array cannot be empty.');
        }

        $stack = new static();

        $stack->middlewares = $middlewares;

        return $stack;
    }
712137
public function startStack($name, $content = null)
    {
        if (is_null($content)) {
            ob_start();
        }

        $this->stacks[] = $name;
        
        $this->pushes[$name] = $content;
    }
21773
protected function addMiddlewareGroups($middlewareGroups)
    {
        if (is_array($middlewareGroups) && (count($middlewareGroups) > 0)) {
            foreach ($middlewareGroups as $key => $groupMiddleware) {
                foreach ($groupMiddleware as $middleware) {
                    $this->pushMiddlewareToGroup($key, $middleware);
                }
            }
        }
    }
236460
public static function resolve($name, $nameMiddleware, $middlewareGroups)
    {
        if ($name instanceof Closure) {
            return $name;
        }

        if (isset($nameMiddleware[$name]) && $nameMiddleware[$name] instanceof Closure) {
            return $nameMiddleware[$name];
        }

        if (isset($middlewareGroups[$name])) {
            return static::parseMiddlewareGroup($name, $nameMiddleware, $middlewareGroups);
        }

        [$middleware, $parameters] = array_pad(explode(':', $name, 2), 2, null);

        if (isset($nameMiddleware[$middleware])) {
            $middleware = $nameMiddleware[$middleware];
        }

        return $middleware.($parameters ? ':'.$parameters : '');
    }
598085
public function unshift(callable $middleware, $name = null)
    {
        array_unshift($this->stack, [$middleware, $name]);
        $this->cached = null;
    }
707866
private function handleRequest(array $middlewares): void
    {
        $requestHandler = new RequestHandler($this->container, $middlewares);

        $this->response = $requestHandler->handle($this->request);
    }
427369
public function prependInit(callable $middleware, $name = null)
    {
        $this->add(self::INIT, $name, $middleware, true);
    }
510933
function (name, callback) {
    var self = this;

    if (!self.callbacks[name])
      self.callbacks[name] = [callback];
    else
      self.callbacks[name].push(callback);
  }
1355740
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        if (is_array($middleware) && isset($middleware['priority'])) {
            $priority = $middleware['priority'];
        }

        $this->getMiddlewares()->insert($middleware, $priority);

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

        return $this;
    }