1 | <?php |
||
20 | class FileSystemLoaderFactory extends AbstractLoaderFactory |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public function create(ContainerBuilder $container, $loaderName, array $config) |
||
26 | { |
||
27 | $locatorDefinition = new ChildDefinition(sprintf('liip_imagine.binary.locator.%s', $config['locator'])); |
||
28 | $locatorDefinition->replaceArgument(0, $this->resolveDataRoots($config['data_root'], $config['bundle_resources'], $container)); |
||
29 | $locatorDefinition->replaceArgument(1, $config['allow_unresolvable_data_roots']); |
||
30 | |||
31 | $definition = $this->getChildLoaderDefinition(); |
||
32 | $definition->replaceArgument(2, $locatorDefinition); |
||
33 | |||
34 | return $this->setTaggedLoaderDefinition($loaderName, $definition, $container); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function getName() |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function addConfiguration(ArrayNodeDefinition $builder) |
||
49 | { |
||
50 | $builder |
||
|
|||
51 | ->children() |
||
52 | ->enumNode('locator') |
||
53 | ->values(['filesystem', 'filesystem_insecure']) |
||
54 | ->info('Using the "filesystem_insecure" locator is not recommended due to a less secure resolver mechanism, but is provided for those using heavily symlinked projects.') |
||
55 | ->defaultValue('filesystem') |
||
56 | ->end() |
||
57 | ->arrayNode('data_root') |
||
58 | ->beforeNormalization() |
||
59 | ->ifString() |
||
60 | ->then(function ($value) { |
||
61 | return [$value]; |
||
62 | }) |
||
63 | ->end() |
||
64 | ->treatNullLike([]) |
||
65 | ->treatFalseLike([]) |
||
66 | ->defaultValue([SymfonyFramework::getContainerResolvableRootWebPath()]) |
||
67 | ->prototype('scalar') |
||
68 | ->cannotBeEmpty() |
||
69 | ->end() |
||
70 | ->end() |
||
71 | ->booleanNode('allow_unresolvable_data_roots') |
||
72 | ->defaultFalse() |
||
73 | ->end() |
||
74 | ->arrayNode('bundle_resources') |
||
75 | ->addDefaultsIfNotSet() |
||
76 | ->children() |
||
77 | ->booleanNode('enabled') |
||
78 | ->defaultFalse() |
||
79 | ->end() |
||
80 | ->enumNode('access_control_type') |
||
81 | ->values(['blacklist', 'whitelist']) |
||
82 | ->info('Sets the access control method applied to bundle names in "access_control_list" into a blacklist or whitelist.') |
||
83 | ->defaultValue('blacklist') |
||
84 | ->end() |
||
85 | ->arrayNode('access_control_list') |
||
86 | ->defaultValue([]) |
||
87 | ->prototype('scalar') |
||
88 | ->cannotBeEmpty() |
||
89 | ->end() |
||
90 | ->end() |
||
91 | ->end() |
||
92 | ->end() |
||
93 | ->end(); |
||
94 | } |
||
95 | |||
96 | /* |
||
97 | * @param string[] $staticPaths |
||
98 | * @param array $config |
||
99 | * @param ContainerBuilder $container |
||
100 | * |
||
101 | * @return string[] |
||
102 | */ |
||
103 | private function resolveDataRoots(array $staticPaths, array $config, ContainerBuilder $container) |
||
119 | |||
120 | /** |
||
121 | * @param ContainerBuilder $container |
||
122 | * |
||
123 | * @return string[] |
||
124 | */ |
||
125 | private function getBundleResourcePaths(ContainerBuilder $container) |
||
137 | |||
138 | /** |
||
139 | * @param array[] $metadata |
||
140 | * |
||
141 | * @return string[] |
||
142 | */ |
||
143 | private function getBundlePathsUsingMetadata(array $metadata) |
||
149 | |||
150 | /** |
||
151 | * @param string[] $classes |
||
152 | * |
||
153 | * @return string[] |
||
154 | */ |
||
155 | private function getBundlePathsUsingNamedObj(array $classes) |
||
171 | } |
||
172 |
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: