1 | <?php |
||
19 | final class JWKSetSource implements SourceInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var null|\SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource\JWKSetSourceInterface[] |
||
23 | */ |
||
24 | private $jwkset_sources = null; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $bundle_path = null; |
||
30 | |||
31 | /** |
||
32 | * JWKSetSource constructor. |
||
33 | * |
||
34 | * @param string $bundle_path |
||
35 | */ |
||
36 | public function __construct($bundle_path) |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function getName() |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function createService($name, array $config, ContainerBuilder $container) |
||
53 | { |
||
54 | foreach ($config as $key => $adapter) { |
||
55 | if (array_key_exists($key, $this->getJWKSetSources())) { |
||
56 | $this->getJWKSetSources()[$key]->create($container, 'key_set', $name, $adapter); |
||
57 | |||
58 | return; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | throw new \LogicException(sprintf('The JWKSet definition "%s" is not configured.', $name)); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | public function getNodeDefinition(ArrayNodeDefinition $node) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function prepend(ContainerBuilder $container, array $config) |
||
89 | |||
90 | /** |
||
91 | * @return array|\SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource\JWKSetSourceInterface[] |
||
92 | */ |
||
93 | private function getJWKSetSources() |
||
113 | } |
||
114 |
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: