1 | <?php |
||
15 | class App implements ContainerInterface |
||
16 | { |
||
17 | private $containers = []; |
||
18 | private $services = []; |
||
19 | private $items = []; |
||
20 | private $path; |
||
21 | private $uri; |
||
22 | |||
23 | /** |
||
24 | * Constructor. Set the base path and uri |
||
25 | * |
||
26 | * @param string $path |
||
27 | * @param UriInterface $uri |
||
28 | */ |
||
29 | public function __construct(string $path, UriInterface $uri) |
||
34 | |||
35 | /** |
||
36 | * Add new containers. |
||
37 | * |
||
38 | * @param ContainerInterface $container |
||
39 | * |
||
40 | * @return self |
||
41 | */ |
||
42 | public function addContainer(ContainerInterface $container): self |
||
48 | |||
49 | /** |
||
50 | * Add a new service provider. |
||
51 | * |
||
52 | * @param ServiceProvider $provider |
||
53 | * |
||
54 | * @return self |
||
55 | */ |
||
56 | public function addServiceProvider(ServiceProvider $provider): self |
||
64 | |||
65 | /** |
||
66 | * Add a new service. |
||
67 | * |
||
68 | * @param string|int $id |
||
69 | * @param callable $service |
||
70 | * |
||
71 | * @return self |
||
72 | */ |
||
73 | public function addService($id, callable $service): self |
||
83 | |||
84 | /** |
||
85 | * @see ContainerInterface |
||
86 | * |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public function has($id) |
||
107 | |||
108 | /** |
||
109 | * @see ContainerInterface |
||
110 | * |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function get($id) |
||
141 | |||
142 | /** |
||
143 | * Set a variable. |
||
144 | * |
||
145 | * @param string|int $id |
||
146 | * @param mixed $value |
||
147 | * |
||
148 | * @return self |
||
149 | */ |
||
150 | public function set($id, $value): self |
||
156 | |||
157 | /** |
||
158 | * Returns the absolute path of the app. |
||
159 | * |
||
160 | * @param string ...$dirs |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getPath(string ...$dirs): string |
||
172 | |||
173 | /* |
||
174 | * Returns the base uri of the app. |
||
175 | * |
||
176 | * @param string ...$dirs |
||
177 | * |
||
178 | * @return UriInterface |
||
179 | */ |
||
180 | public function getUri(string ...$dirs): UriInterface |
||
188 | |||
189 | /** |
||
190 | * helper function to fix paths '//' or '/./' or '/foo/../' in a path. |
||
191 | * |
||
192 | * @param string $base |
||
193 | * @param string[] $dirs |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | private static function canonicalize(string $base, array $dirs): string |
||
208 | } |
||
209 |