Mercurial > hg > cmmr2012-drupal-site
comparison vendor/stack/builder/src/Stack/Builder.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Stack; | |
4 | |
5 use Symfony\Component\HttpKernel\HttpKernelInterface; | |
6 | |
7 class Builder | |
8 { | |
9 private $specs; | |
10 | |
11 public function __construct() | |
12 { | |
13 $this->specs = new \SplStack(); | |
14 } | |
15 | |
16 public function unshift(/*$kernelClass, $args...*/) | |
17 { | |
18 if (func_num_args() === 0) { | |
19 throw new \InvalidArgumentException("Missing argument(s) when calling unshift"); | |
20 } | |
21 | |
22 $spec = func_get_args(); | |
23 $this->specs->unshift($spec); | |
24 | |
25 return $this; | |
26 } | |
27 | |
28 public function push(/*$kernelClass, $args...*/) | |
29 { | |
30 if (func_num_args() === 0) { | |
31 throw new \InvalidArgumentException("Missing argument(s) when calling push"); | |
32 } | |
33 | |
34 $spec = func_get_args(); | |
35 $this->specs->push($spec); | |
36 | |
37 return $this; | |
38 } | |
39 | |
40 public function resolve(HttpKernelInterface $app) | |
41 { | |
42 $middlewares = array($app); | |
43 | |
44 foreach ($this->specs as $spec) { | |
45 $args = $spec; | |
46 $firstArg = array_shift($args); | |
47 | |
48 if (is_callable($firstArg)) { | |
49 $app = $firstArg($app); | |
50 } else { | |
51 $kernelClass = $firstArg; | |
52 array_unshift($args, $app); | |
53 | |
54 $reflection = new \ReflectionClass($kernelClass); | |
55 $app = $reflection->newInstanceArgs($args); | |
56 } | |
57 | |
58 array_unshift($middlewares, $app); | |
59 } | |
60 | |
61 return new StackedHttpKernel($app, $middlewares); | |
62 } | |
63 } |