1 | <?php |
||
25 | class HttpLoader implements LoaderInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var ValidatorInterface |
||
29 | */ |
||
30 | private $validator; |
||
31 | |||
32 | /** |
||
33 | * @var Client |
||
34 | */ |
||
35 | private $client; |
||
36 | |||
37 | /** |
||
38 | * @var LoggerInterface |
||
39 | */ |
||
40 | private $logger; |
||
41 | |||
42 | /** |
||
43 | * @var DispersalStrategyInterface |
||
44 | */ |
||
45 | private $strategy; |
||
46 | |||
47 | /** |
||
48 | * doctrine cache |
||
49 | * |
||
50 | * @var CacheProvider |
||
51 | */ |
||
52 | private $cache; |
||
53 | |||
54 | /** |
||
55 | * doctrine cache lifetime |
||
56 | * |
||
57 | * @var int |
||
58 | */ |
||
59 | private $cacheLifetime; |
||
60 | |||
61 | /** |
||
62 | * @var array curl options to apply on each request |
||
63 | */ |
||
64 | private $curlOptions = []; |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | private $options = [ |
||
70 | 'storeKey' => 'httpLoader', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | 4 | * constructor |
|
75 | * |
||
76 | 4 | * @param ValidatorInterface $validator validator |
|
77 | 4 | * @param Client $client http client |
|
78 | 4 | * @param LoggerInterface $logger Logger |
|
79 | */ |
||
80 | public function __construct(ValidatorInterface $validator, Client $client, LoggerInterface $logger) |
||
86 | |||
87 | 3 | /** |
|
88 | * @inheritDoc |
||
89 | 3 | * |
|
90 | 3 | * @param DispersalStrategyInterface $strategy dispersal strategy |
|
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function setDispersalStrategy($strategy) |
||
98 | |||
99 | /** |
||
100 | * @inheritDoc |
||
101 | 1 | * |
|
102 | * @param CacheProvider $cache doctrine cache provider |
||
103 | 1 | * @param string $cacheNamespace cache namespace |
|
104 | 1 | * @param int $cacheLifetime cache lifetime |
|
105 | 1 | * |
|
106 | 1 | * @return void |
|
107 | */ |
||
108 | public function setCache(CacheProvider $cache, $cacheNamespace, $cacheLifetime) |
||
114 | |||
115 | /** |
||
116 | * set curl options |
||
117 | * |
||
118 | * @param array $curlOptions the curl options |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | public function setCurlOptions(array $curlOptions) |
||
126 | |||
127 | 1 | /** |
|
128 | * @inheritDoc |
||
129 | 1 | * |
|
130 | 1 | * @param array $options cache strategy |
|
131 | 1 | * |
|
132 | 1 | * @return void |
|
133 | */ |
||
134 | 1 | public function setOptions($options) |
|
143 | |||
144 | 1 | /** |
|
145 | * check if the url is valid |
||
146 | 1 | * |
|
147 | * @param string $url url |
||
148 | 1 | * |
|
149 | * @return boolean |
||
150 | */ |
||
151 | public function supports($url) |
||
157 | |||
158 | 3 | /** |
|
159 | * Applies the specified curl option on a request |
||
160 | 3 | * |
|
161 | 3 | * @param RequestInterface $request request |
|
162 | * |
||
163 | * @return void |
||
164 | 3 | */ |
|
165 | 3 | protected function applyCurlOptions($request) |
|
174 | |||
175 | 3 | /** |
|
176 | * @inheritDoc |
||
177 | 3 | * |
|
178 | 3 | * @param string $input url |
|
179 | 3 | * |
|
180 | 3 | * @return ApiDefinition |
|
181 | 3 | */ |
|
182 | 1 | public function load($input) |
|
215 | |||
216 | 2 | /** |
|
217 | * fetch file from remote destination |
||
218 | * |
||
219 | 2 | * @param RequestInterface $request request |
|
220 | 2 | * |
|
221 | * @return string |
||
222 | */ |
||
223 | private function fetchFile($request) |
||
247 | } |
||
248 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: