1 | <?php |
||
19 | class ConfiguredClientsStrategy implements DiscoveryStrategy, EventSubscriberInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var HttpClient |
||
23 | */ |
||
24 | private static $client; |
||
25 | |||
26 | /** |
||
27 | * @param HttpClient $httpClient |
||
28 | */ |
||
29 | public function __construct(HttpClient $httpClient) |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public static function getCandidates($type) |
||
38 | { |
||
39 | if (static::$client !== null && $type == HttpClient::class) { |
||
40 | return [['class' => function () { |
||
41 | return static::$client; |
||
42 | }]]; |
||
43 | } |
||
44 | |||
45 | return []; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Make sure to use our custom strategy. |
||
50 | * |
||
51 | * @param Event $e |
||
52 | */ |
||
53 | public function onEvent(Event $e) |
||
57 | |||
58 | /** |
||
59 | * Whenever these events occur we make sure to add our strategy to the discovery. |
||
60 | * |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public static function getSubscribedEvents() |
||
70 | } |
||
71 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: