1 | <?php |
||
23 | abstract class AbstractRequest implements RequestInterface |
||
24 | { |
||
25 | /** |
||
26 | * The request parameters |
||
27 | * |
||
28 | * @var \Symfony\Component\HttpFoundation\ParameterBag |
||
29 | */ |
||
30 | protected $parameters; |
||
31 | |||
32 | /** |
||
33 | * The request client |
||
34 | * |
||
35 | * @var \Guzzle\Http\ClientInterface |
||
36 | */ |
||
37 | protected $httpClient; |
||
38 | |||
39 | /** |
||
40 | * The HTTP request object |
||
41 | * |
||
42 | * @var \Symfony\Component\HttpFoundation\Request |
||
43 | */ |
||
44 | protected $httpRequest; |
||
45 | |||
46 | /** |
||
47 | * An associated ResponseInterface |
||
48 | * |
||
49 | * @var ResponseInterface |
||
50 | */ |
||
51 | protected $response; |
||
52 | |||
53 | /** |
||
54 | * Create a new Request |
||
55 | * |
||
56 | * @param ClientInterface $httpClient A Guzzle client to make API calls with |
||
57 | * @param Request $httpRequest A Symfony HTTP requet object |
||
58 | */ |
||
59 | 18 | public function __construct(ClientInterface $httpClient, Request $httpRequest) |
|
65 | |||
66 | /** |
||
67 | * Initialize the request with parameters |
||
68 | * |
||
69 | * @param array $parameters Associative array of parameters |
||
70 | * |
||
71 | * @return $this |
||
72 | * @throws RuntimeException |
||
73 | */ |
||
74 | 21 | public function initialize(array $parameters = []) |
|
86 | |||
87 | /** |
||
88 | * Get all parameters |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 6 | public function getParameters() |
|
96 | |||
97 | /** |
||
98 | * Get a parameter |
||
99 | * |
||
100 | * @param string $key The parameter key |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 3 | public function getParameter($key) |
|
107 | |||
108 | /** |
||
109 | * Get the API username |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 3 | public function getUsername() |
|
117 | |||
118 | /** |
||
119 | * Set the API username |
||
120 | * |
||
121 | * @param string $value |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | 9 | public function setUsername($value) |
|
129 | |||
130 | /** |
||
131 | * Get the API password |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 3 | public function getPassword() |
|
139 | |||
140 | /** |
||
141 | * Set the API password |
||
142 | * |
||
143 | * @param string $value |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | 6 | public function setPassword($value) |
|
151 | |||
152 | /** |
||
153 | * Get the associated Response |
||
154 | * |
||
155 | * @return ResponseInterface |
||
156 | * @throws RuntimeException |
||
157 | */ |
||
158 | 6 | public function getResponse() |
|
166 | |||
167 | /** |
||
168 | * Send the request |
||
169 | * |
||
170 | * @return ResponseInterface |
||
171 | */ |
||
172 | 9 | public function send() |
|
178 | |||
179 | /** |
||
180 | * Set a parameter on the request |
||
181 | * |
||
182 | * @param string $key |
||
183 | * @param mixed $value |
||
184 | * @return $this |
||
185 | * @throws RuntimeException |
||
186 | */ |
||
187 | 9 | protected function setParameter($key, $value) |
|
197 | } |
||
198 |
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: