1 | <?php |
||
9 | class RequestLauncher |
||
10 | { |
||
11 | /** |
||
12 | * The API client ID issued by EMT. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $clientId; |
||
17 | |||
18 | /** |
||
19 | * The API passkey issued by EMT. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $passkey; |
||
24 | |||
25 | /** |
||
26 | * The Guzzle HTTP client. |
||
27 | * |
||
28 | * @var \GuzzleHttp\Client |
||
29 | */ |
||
30 | protected $client; |
||
31 | |||
32 | /** |
||
33 | * Create a new RequestLauncher instance with the provided client ID and |
||
34 | * passkey. |
||
35 | * |
||
36 | * An optional Guzzle HTTP client can be provided as well. |
||
37 | * |
||
38 | * @param string $clientId |
||
39 | * @param string $passkey |
||
40 | * @param \GuzzleHttp\ClientInterface $client |
||
41 | */ |
||
42 | 12 | public function __construct($clientId, $passkey, ClientInterface $client = null) |
|
52 | |||
53 | /** |
||
54 | * Authenticate and execute an arbitrary request. |
||
55 | * |
||
56 | * This method adds the relevant authentication parameters to the request |
||
57 | * and decodes the returned response. |
||
58 | * |
||
59 | * @var string $endpoint |
||
60 | * @var array $params |
||
61 | * @return \stdClass |
||
62 | * @throws \RuntimeException |
||
63 | */ |
||
64 | 9 | public function launchRequest($endpoint, $params = []) |
|
84 | |||
85 | /** |
||
86 | * Return the HTTP client used by this instance. |
||
87 | * |
||
88 | * @return \GuzzleHttp\ClientInterface |
||
89 | */ |
||
90 | 3 | public function getHttpClient() |
|
94 | } |
||
95 |
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: