1 | <?php |
||
19 | class IO extends AbstractParser |
||
20 | { |
||
21 | /** @var ComplexSettingParserInterface */ |
||
22 | private $complexSettingParser; |
||
23 | |||
24 | public function __construct(ComplexSettingParserInterface $complexSettingParser) |
||
28 | |||
29 | public function addSemanticConfig(NodeBuilder $nodeBuilder) |
||
30 | { |
||
31 | $nodeBuilder |
||
|
|||
32 | ->arrayNode('io') |
||
33 | ->info('Binary storage options') |
||
34 | ->children() |
||
35 | ->scalarNode('metadata_handler') |
||
36 | ->info('Handler uses to manipulate IO files metadata') |
||
37 | ->example('default') |
||
38 | ->end() |
||
39 | ->scalarNode('binarydata_handler') |
||
40 | ->info('Handler uses to manipulate IO files binarydata') |
||
41 | ->example('default') |
||
42 | ->end() |
||
43 | ->scalarNode('url_prefix') |
||
44 | ->info('Prefix added to binary files uris. A host can also be added') |
||
45 | ->example('$var_dir$/$storage_dir$, http://static.example.com/') |
||
46 | ->end() |
||
47 | ->arrayNode('permissions') |
||
48 | ->info('Permissions applied by the Local flysystem adapter when creating content files and directories in storage.') |
||
49 | ->children() |
||
50 | ->scalarNode('files') |
||
51 | ->defaultValue('0644') |
||
52 | ->end() |
||
53 | ->scalarNode('directories') |
||
54 | ->defaultValue('0755') |
||
55 | ->end() |
||
56 | ->end() |
||
57 | ->end() |
||
58 | ->end() |
||
59 | ->end(); |
||
60 | } |
||
61 | |||
62 | public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer) |
||
63 | { |
||
64 | if (!isset($scopeSettings['io'])) { |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | $settings = $scopeSettings['io']; |
||
69 | if (isset($settings['metadata_handler'])) { |
||
70 | $contextualizer->setContextualParameter('io.metadata_handler', $currentScope, $settings['metadata_handler']); |
||
71 | } |
||
72 | if (isset($settings['binarydata_handler'])) { |
||
73 | $contextualizer->setContextualParameter('io.binarydata_handler', $currentScope, $settings['binarydata_handler']); |
||
74 | } |
||
75 | if (isset($settings['url_prefix'])) { |
||
76 | $contextualizer->setContextualParameter('io.url_prefix', $currentScope, $settings['url_prefix']); |
||
77 | } |
||
78 | if (isset($settings['permissions'])) { |
||
79 | if (isset($settings['permissions']['files'])) { |
||
80 | $contextualizer->setContextualParameter('io.permissions.files', $currentScope, $settings['permissions']['files']); |
||
81 | } |
||
82 | if (isset($settings['permissions']['directories'])) { |
||
83 | $contextualizer->setContextualParameter('io.permissions.directories', $currentScope, $settings['permissions']['directories']); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Post process configuration to add io_root_dir and io_prefix. |
||
90 | */ |
||
91 | public function postMap(array $config, ContextualizerInterface $contextualizer) |
||
92 | { |
||
93 | $container = $contextualizer->getContainer(); |
||
94 | |||
95 | // complex parameters dependencies |
||
96 | foreach (array_merge($config['siteaccess']['list'], array_keys($config['siteaccess']['groups'])) as $scope) { |
||
97 | $this->addComplexParametersDependencies('io.url_prefix', $scope, $container); |
||
98 | $this->addComplexParametersDependencies('io.legacy_url_prefix', $scope, $container); |
||
99 | $this->addComplexParametersDependencies('io.root_dir', $scope, $container); |
||
100 | } |
||
101 | |||
102 | // we should only write for default, and for sa/sa groups/global IF they have a declared value |
||
103 | $scopes = array_merge( |
||
104 | array('default'), |
||
105 | $config['siteaccess']['list'], |
||
106 | array_keys($config['siteaccess']['groups']) |
||
107 | ); |
||
108 | foreach ($scopes as $scope) { |
||
109 | // post process io.url_prefix for complex settings |
||
110 | $postProcessedValue = $this->postProcessComplexSetting('io.url_prefix', $scope, $container); |
||
111 | if (is_string($postProcessedValue)) { |
||
112 | $contextualizer->setContextualParameter('io.url_prefix', $scope, $postProcessedValue); |
||
113 | } |
||
114 | |||
115 | // post process io.legacy_url_prefix for complex settings |
||
116 | $postProcessedValue = $this->postProcessComplexSetting('io.legacy_url_prefix', $scope, $container); |
||
117 | if (is_string($postProcessedValue)) { |
||
118 | $contextualizer->setContextualParameter('io.legacy_url_prefix', $scope, $postProcessedValue); |
||
119 | } |
||
120 | |||
121 | // post process io.root_dir for complex settings |
||
122 | $postProcessedValue = $this->postProcessComplexSetting('io.root_dir', $scope, $container); |
||
123 | if (is_string($postProcessedValue)) { |
||
124 | $contextualizer->setContextualParameter('io.root_dir', $scope, $postProcessedValue); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Applies dependencies of complex $parameter in $scope. |
||
131 | */ |
||
132 | private function addComplexParametersDependencies($parameter, $scope, ContainerBuilder $container) |
||
164 | |||
165 | private function postProcessComplexSetting($setting, $sa, ContainerBuilder $container) |
||
208 | } |
||
209 |
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: