1 | <?php |
||
20 | class Api |
||
21 | { |
||
22 | protected $cache; |
||
23 | protected $http; |
||
24 | |||
25 | protected $url; |
||
26 | protected $username; |
||
27 | protected $password; |
||
28 | |||
29 | public function __construct(Cache $cache, Client $http) |
||
34 | |||
35 | public function setUrl(string $url): self |
||
41 | |||
42 | public function setUsername(string $username): self |
||
48 | |||
49 | public function setPassword(string $password): self |
||
55 | |||
56 | /** |
||
57 | * @param string $service |
||
58 | * @param string $method |
||
59 | * @param string $endpoint |
||
60 | * @param array|null $parameters |
||
61 | * |
||
62 | * @param array $headers |
||
63 | * @return mixed|string |
||
64 | * |
||
65 | * @throws BaseException |
||
66 | * @throws ForbiddenException |
||
67 | * @throws GuzzleException |
||
68 | * @throws NotFoundException |
||
69 | */ |
||
70 | public function callService(string $service, string $method, string $endpoint, array $parameters = null, array $headers = []) |
||
76 | |||
77 | /** |
||
78 | * @param string $method |
||
79 | * @param string $endpoint |
||
80 | * @param array $headers |
||
81 | * @param array|null $parameters |
||
82 | * |
||
83 | * @return mixed|string |
||
84 | * |
||
85 | * @throws ForbiddenException |
||
86 | * @throws NotFoundException |
||
87 | * @throws BaseException |
||
88 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
89 | */ |
||
90 | public function call(string $method, string $endpoint, array $headers = [], array $parameters = null) |
||
101 | |||
102 | /** |
||
103 | * @param string $method |
||
104 | * @param string $endpoint |
||
105 | * @param array $headers |
||
106 | * @param array|null $parameters |
||
107 | * @param bool $retry |
||
108 | * |
||
109 | * @return StreamInterface |
||
110 | * |
||
111 | * @throws ForbiddenException |
||
112 | * @throws NotFoundException |
||
113 | * @throws BaseException |
||
114 | * @throws GuzzleException |
||
115 | */ |
||
116 | public function makeCallRequest( |
||
163 | |||
164 | /** |
||
165 | * Authorize token for performing request. |
||
166 | * |
||
167 | * @param string $token |
||
168 | * @param string $service |
||
169 | * @param string $method |
||
170 | * @param string $endpoint |
||
171 | * |
||
172 | * @return Consumer |
||
173 | * |
||
174 | * @throws UnauthorizedException |
||
175 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
176 | */ |
||
177 | public function authorize(string $token, string $service, string $method, string $endpoint): Consumer |
||
199 | |||
200 | protected function token(): ?string |
||
211 | } |
||
212 |
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: