1 | <?php |
||
19 | class Response |
||
20 | { |
||
21 | /** |
||
22 | * @var int Response status code |
||
23 | */ |
||
24 | private $code; |
||
25 | |||
26 | /** |
||
27 | * @var string status message |
||
28 | */ |
||
29 | private $message; |
||
30 | |||
31 | /** |
||
32 | * @var ResponseDataInterface data to be returned |
||
33 | */ |
||
34 | private $data; |
||
35 | |||
36 | /** |
||
37 | * Response constructor. |
||
38 | */ |
||
39 | 4 | public function __construct() |
|
40 | { |
||
41 | 4 | $this->code = 200; |
|
42 | 4 | $this->message = "OK"; |
|
43 | 4 | } |
|
44 | |||
45 | /** |
||
46 | * Set status code |
||
47 | * |
||
48 | * @param int $code |
||
49 | */ |
||
50 | public function setCode(int $code) |
||
54 | |||
55 | /** |
||
56 | * Set response message |
||
57 | * |
||
58 | * @param string $message |
||
59 | */ |
||
60 | public function setMessage(string $message) |
||
64 | |||
65 | /** |
||
66 | * Set response data object |
||
67 | * |
||
68 | * @param ResponseDataInterface $data |
||
69 | */ |
||
70 | public function setData(ResponseDataInterface $data) |
||
74 | |||
75 | /** |
||
76 | * Handle Options request |
||
77 | * |
||
78 | * @param Headers $headers |
||
79 | */ |
||
80 | public function options(Headers $headers) |
||
93 | |||
94 | /** |
||
95 | * Handle requests |
||
96 | * |
||
97 | * @param Request $request |
||
98 | * @param Header $headers |
||
99 | */ |
||
100 | public function handle(Request &$request, Headers $headers) |
||
112 | |||
113 | /** |
||
114 | * Return Output object |
||
115 | * |
||
116 | * @return \stdClass |
||
117 | */ |
||
118 | public function output() |
||
130 | } |
||
131 |
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: