This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Ivory Serializer bundle package. |
||
5 | * |
||
6 | * (c) Eric GELOEN <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please read the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Ivory\SerializerBundle\DependencyInjection; |
||
13 | |||
14 | use Ivory\Serializer\Mapping\Loader\AnnotationClassMetadataLoader; |
||
15 | use Ivory\Serializer\Mapping\Loader\DirectoryClassMetadataLoader; |
||
16 | use Ivory\Serializer\Mapping\Loader\FileClassMetadataLoader; |
||
17 | use Ivory\Serializer\Mapping\Loader\ReflectionClassMetadataLoader; |
||
18 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
||
19 | use Symfony\Component\Config\FileLocator; |
||
20 | use Symfony\Component\Config\Resource\DirectoryResource; |
||
21 | use Symfony\Component\Config\Resource\FileResource; |
||
22 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
23 | use Symfony\Component\DependencyInjection\Definition; |
||
24 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
||
25 | use Symfony\Component\DependencyInjection\Reference; |
||
26 | use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
||
27 | |||
28 | /** |
||
29 | * @author GeLo <[email protected]> |
||
30 | */ |
||
31 | class IvorySerializerExtension extends ConfigurableExtension |
||
32 | { |
||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public function getConfiguration(array $config, ContainerBuilder $container) |
||
37 | { |
||
38 | return new Configuration($container->getParameter('kernel.debug')); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | protected function loadInternal(array $config, ContainerBuilder $container) |
||
45 | { |
||
46 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
47 | |||
48 | $resources = [ |
||
49 | 'cache', |
||
50 | 'common', |
||
51 | 'event', |
||
52 | 'fos', |
||
53 | 'mapping', |
||
54 | 'navigator', |
||
55 | 'registry', |
||
56 | 'serializer', |
||
57 | 'type', |
||
58 | 'visitor', |
||
59 | ]; |
||
60 | |||
61 | foreach ($resources as $resource) { |
||
62 | $loader->load($resource.'.xml'); |
||
63 | } |
||
64 | |||
65 | $this->loadEvent($config['event'], $container); |
||
66 | $this->loadMapping($config['mapping'], $container); |
||
67 | $this->loadTypes($config['types'], $container); |
||
68 | $this->loadVisitors($config['visitors'], $container); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param mixed[] $config |
||
73 | * @param ContainerBuilder $container |
||
74 | */ |
||
75 | private function loadEvent(array $config, ContainerBuilder $container) |
||
76 | { |
||
77 | if ($config['enabled']) { |
||
78 | $container |
||
79 | ->getDefinition('ivory.serializer.mapping.factory') |
||
80 | ->replaceArgument(0, new Reference('ivory.serializer.mapping.factory.event')); |
||
81 | |||
82 | $container->setAlias('ivory.serializer.navigator', 'ivory.serializer.navigator.event'); |
||
83 | |||
84 | return; |
||
85 | } |
||
86 | |||
87 | $container->removeDefinition('ivory.serializer.event.dispatcher'); |
||
88 | $container->removeDefinition('ivory.serializer.mapping.factory.event'); |
||
89 | $container->removeDefinition('ivory.serializer.navigator.event'); |
||
90 | |||
91 | $container->setAlias('ivory.serializer.navigator', 'ivory.serializer.navigator.default'); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param mixed[] $config |
||
96 | * @param ContainerBuilder $container |
||
97 | */ |
||
98 | private function loadMapping(array $config, ContainerBuilder $container) |
||
99 | { |
||
100 | $directories = $files = []; |
||
101 | |||
102 | foreach ($this->resolveMappingPaths($config, $container) as $path) { |
||
103 | if (is_dir($path)) { |
||
104 | $directories[] = $path; |
||
105 | $container->addResource(new DirectoryResource($path)); |
||
106 | } elseif (is_file($path)) { |
||
107 | $files[] = $path; |
||
108 | $container->addResource(new FileResource($path)); |
||
109 | } else { |
||
110 | throw new InvalidConfigurationException(sprintf('The path "%s" does not exist.', $path)); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | $loaders = []; |
||
115 | $typeParser = new Reference('ivory.serializer.type.parser'); |
||
116 | |||
117 | if ($config['reflection']) { |
||
118 | $loaders['reflection'] = new Definition(ReflectionClassMetadataLoader::class, [ |
||
119 | new Reference('property_info', ContainerBuilder::NULL_ON_INVALID_REFERENCE), |
||
120 | $typeParser, |
||
121 | ]); |
||
122 | } |
||
123 | |||
124 | if ($config['annotation']) { |
||
125 | $loaders['annotation'] = new Definition(AnnotationClassMetadataLoader::class, [ |
||
126 | new Reference('annotation_reader'), |
||
127 | $typeParser, |
||
128 | ]); |
||
129 | } |
||
130 | |||
131 | if (!empty($directories)) { |
||
132 | $loaders['directory'] = new Definition(DirectoryClassMetadataLoader::class, [$directories, $typeParser]); |
||
133 | } |
||
134 | |||
135 | foreach ($files as $file) { |
||
136 | $loaders['file_'.sha1($file)] = new Definition(FileClassMetadataLoader::class, [$file, $typeParser]); |
||
137 | } |
||
138 | |||
139 | foreach ($loaders as $key => $loader) { |
||
140 | $container->setDefinition( |
||
141 | 'ivory.serializer.mapping.loader.'.$key, |
||
142 | $loader->addTag('ivory.serializer.loader', ['priority' => -1000]) |
||
143 | ); |
||
144 | } |
||
145 | |||
146 | $this->loadMappingCache($config['cache'], $container); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @param mixed[] $config |
||
151 | * @param ContainerBuilder $container |
||
152 | */ |
||
153 | private function loadMappingCache(array $config, ContainerBuilder $container) |
||
154 | { |
||
155 | $cacheWarmerService = 'ivory.serializer.cache_warmer'; |
||
156 | $classMetadataFactoryService = 'ivory.serializer.mapping.factory'; |
||
157 | |||
158 | if ($config['debug']) { |
||
159 | $container->removeDefinition($cacheWarmerService); |
||
160 | $container->removeDefinition($classMetadataFactoryService); |
||
161 | |||
162 | $container->setAlias($classMetadataFactoryService, $classMetadataFactoryService.'.default'); |
||
163 | } else { |
||
164 | $container |
||
165 | ->getDefinition($cacheWarmerService) |
||
166 | ->addArgument($cachePool = new Reference($config['pool'])); |
||
167 | |||
168 | $container |
||
169 | ->getDefinition($classMetadataFactoryService) |
||
170 | ->addArgument($cachePool) |
||
171 | ->addArgument($config['prefix']); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @param mixed[] $config |
||
177 | * @param ContainerBuilder $container |
||
178 | */ |
||
179 | private function loadTypes(array $config, ContainerBuilder $container) |
||
180 | { |
||
181 | $container |
||
182 | ->getDefinition('ivory.serializer.type.date_time') |
||
183 | ->addArgument($config['date_time']['format']) |
||
184 | ->addArgument($config['date_time']['timezone']); |
||
185 | |||
186 | $container |
||
187 | ->getDefinition('ivory.serializer.type.exception') |
||
188 | ->addArgument($config['exception']['debug']); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param mixed[] $config |
||
193 | * @param ContainerBuilder $container |
||
194 | */ |
||
195 | private function loadVisitors(array $config, ContainerBuilder $container) |
||
196 | { |
||
197 | $container |
||
198 | ->getDefinition('ivory.serializer.visitor.csv.serialization') |
||
199 | ->addArgument($config['csv']['delimiter']) |
||
200 | ->addArgument($config['csv']['enclosure']) |
||
201 | ->addArgument($config['csv']['escape_char']) |
||
202 | ->addArgument($config['csv']['key_separator']); |
||
203 | |||
204 | $container |
||
205 | ->getDefinition('ivory.serializer.visitor.csv.deserialization') |
||
206 | ->addArgument($config['csv']['delimiter']) |
||
207 | ->addArgument($config['csv']['enclosure']) |
||
208 | ->addArgument($config['csv']['escape_char']) |
||
209 | ->addArgument($config['csv']['key_separator']); |
||
210 | |||
211 | $container |
||
212 | ->getDefinition('ivory.serializer.visitor.json.serialization') |
||
213 | ->addArgument($config['json']['options']); |
||
214 | |||
215 | $container |
||
216 | ->getDefinition('ivory.serializer.visitor.json.deserialization') |
||
217 | ->addArgument($config['json']['max_depth']) |
||
218 | ->addArgument($config['json']['options']); |
||
219 | |||
220 | $container |
||
221 | ->getDefinition('ivory.serializer.visitor.xml.serialization') |
||
222 | ->addArgument($config['xml']['version']) |
||
223 | ->addArgument($config['xml']['encoding']) |
||
224 | ->addArgument($config['xml']['format_output']) |
||
225 | ->addArgument($config['xml']['root']) |
||
226 | ->addArgument($config['xml']['entry']) |
||
227 | ->addArgument($config['xml']['entry_attribute']); |
||
228 | |||
229 | $container |
||
230 | ->getDefinition('ivory.serializer.visitor.xml.deserialization') |
||
231 | ->addArgument($config['xml']['entry']) |
||
232 | ->addArgument($config['xml']['entry_attribute']); |
||
233 | |||
234 | $container |
||
235 | ->getDefinition('ivory.serializer.visitor.yaml.serialization') |
||
236 | ->addArgument($config['yaml']['inline']) |
||
237 | ->addArgument($config['yaml']['indent']) |
||
238 | ->addArgument($config['yaml']['options']); |
||
239 | |||
240 | $container |
||
241 | ->getDefinition('ivory.serializer.visitor.yaml.deserialization') |
||
242 | ->addArgument($config['yaml']['options']); |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * @param mixed[] $config |
||
247 | * @param ContainerBuilder $container |
||
248 | * |
||
249 | * @return string[] |
||
250 | */ |
||
251 | private function resolveMappingPaths(array $config, ContainerBuilder $container) |
||
252 | { |
||
253 | $paths = []; |
||
254 | |||
255 | if ($config['auto']['enabled']) { |
||
256 | $bundles = $container->getParameter('kernel.bundles'); |
||
257 | |||
258 | foreach ($bundles as $bundle) { |
||
0 ignored issues
–
show
|
|||
259 | $bundlePath = dirname((new \ReflectionClass($bundle))->getFileName()); |
||
260 | |||
261 | foreach ($config['auto']['paths'] as $relativePath) { |
||
262 | $path = $bundlePath.'/'.$relativePath; |
||
263 | |||
264 | if (file_exists($path)) { |
||
265 | $paths[] = $path; |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | |||
271 | return array_merge($paths, $config['paths']); |
||
272 | } |
||
273 | } |
||
274 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.