1 | <?php |
||
26 | class App extends RouteCollector implements RequestHandlerInterface |
||
27 | { |
||
28 | /** |
||
29 | * 是否已经初始化 |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $booted = false; |
||
34 | |||
35 | /** |
||
36 | * @var ContainerInterface |
||
37 | */ |
||
38 | protected $container; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $providers; |
||
44 | |||
45 | public function __construct(ContainerInterface $container = null) |
||
56 | |||
57 | /** |
||
58 | * 初始化启动工作 |
||
59 | */ |
||
60 | public function boot() |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
79 | |||
80 | /** |
||
81 | * 代理http kernel |
||
82 | * |
||
83 | * @param ServerRequestInterface $request |
||
84 | * @param ResponseInterface $response |
||
85 | */ |
||
86 | public function terminate(ServerRequestInterface $request, ResponseInterface $response) |
||
90 | |||
91 | /** |
||
92 | * 开启服务, 监听请求 |
||
93 | */ |
||
94 | public function serve() |
||
103 | |||
104 | /** |
||
105 | * 注册服务提供者 |
||
106 | * |
||
107 | * @param object $provider |
||
108 | * @param array $values |
||
109 | */ |
||
110 | public function register($provider, array $values = []) |
||
123 | |||
124 | /** |
||
125 | * 获取服务容器 |
||
126 | * |
||
127 | * @return Container |
||
128 | */ |
||
129 | public function getContainer(): Container |
||
133 | |||
134 | /** |
||
135 | * 添加一个 middleware |
||
136 | * |
||
137 | * @param string|MiddlewareInterface|callable $middleware |
||
138 | * @param Route|null $route 绑定的路由 |
||
139 | */ |
||
140 | public function pipe($middleware, Route $route = null) |
||
150 | |||
151 | /** |
||
152 | * 返回全部的 provider |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | public function getProviders() |
||
160 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: