Skip to content

Commit d86bff2

Browse files
Add bundle resources to safe path when requested
This change adds the functionality to add bundle public resource paths automatically when the `bundle_resources` option is set.
1 parent 30aea40 commit d86bff2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,22 @@ class FileSystemLoaderFactory extends AbstractLoaderFactory
2222
*/
2323
public function create(ContainerBuilder $container, $loaderName, array $config)
2424
{
25+
$dataRoots = $config['data_root'];
26+
27+
// Load bundle resources if requested
28+
if ($config['bundle_resources']) {
29+
foreach ($container->getParameter('kernel.bundles') as $bundle) {
30+
$refClass = new \ReflectionClass($bundle);
31+
$bundlePath = dirname($refClass->getFileName());
32+
if (!is_dir($originDir = $bundlePath . '/Resources/public')) {
33+
continue;
34+
}
35+
$dataRoots[] = realpath($originDir);
36+
}
37+
}
38+
2539
$definition = $this->getChildLoaderDefinition();
26-
$definition->replaceArgument(2, $config['data_root']);
40+
$definition->replaceArgument(2, $dataRoots);
2741
$definition->replaceArgument(3, new Reference(sprintf('liip_imagine.binary.locator.%s', $config['locator'])));
2842

2943
return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
@@ -44,6 +58,9 @@ public function addConfiguration(ArrayNodeDefinition $builder)
4458
{
4559
$builder
4660
->children()
61+
->booleanNode('bundle_resources')
62+
->defaultFalse()
63+
->end()
4764
->enumNode('locator')
4865
->values(array('filesystem', 'filesystem_insecure'))
4966
->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.')

0 commit comments

Comments
 (0)