Chris@0: specs = new \SplStack(); Chris@0: } Chris@0: Chris@0: public function unshift(/*$kernelClass, $args...*/) Chris@0: { Chris@0: if (func_num_args() === 0) { Chris@0: throw new \InvalidArgumentException("Missing argument(s) when calling unshift"); Chris@0: } Chris@0: Chris@0: $spec = func_get_args(); Chris@0: $this->specs->unshift($spec); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: public function push(/*$kernelClass, $args...*/) Chris@0: { Chris@0: if (func_num_args() === 0) { Chris@0: throw new \InvalidArgumentException("Missing argument(s) when calling push"); Chris@0: } Chris@0: Chris@0: $spec = func_get_args(); Chris@0: $this->specs->push($spec); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: public function resolve(HttpKernelInterface $app) Chris@0: { Chris@0: $middlewares = array($app); Chris@0: Chris@0: foreach ($this->specs as $spec) { Chris@0: $args = $spec; Chris@0: $firstArg = array_shift($args); Chris@0: Chris@0: if (is_callable($firstArg)) { Chris@0: $app = $firstArg($app); Chris@0: } else { Chris@0: $kernelClass = $firstArg; Chris@0: array_unshift($args, $app); Chris@0: Chris@0: $reflection = new \ReflectionClass($kernelClass); Chris@0: $app = $reflection->newInstanceArgs($args); Chris@0: } Chris@0: Chris@0: array_unshift($middlewares, $app); Chris@0: } Chris@0: Chris@0: return new StackedHttpKernel($app, $middlewares); Chris@0: } Chris@0: }