Skip to content

Commit

Permalink
bug #23870 [DI] Use GlobResource for non-tracked directories (vudaltsov)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Use GlobResource for non-tracked directories

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

I noticed that some of my excluded directories are still tracked by the container and changes to files inside them make it recompile. This brought me to the `$trackContents || is_dir($path)` line introduced in #21505.

Commits
-------

048eb18 [DI] Use GlobResource for non-tracked directories
  • Loading branch information
nicolas-grekas committed Aug 22, 2017
2 parents f335451 + 048eb18 commit 9810018
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Expand Up @@ -1346,7 +1346,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$fileRecorder('yml', $file);
}

if ($container->fileExists($dir = $dirname.'/Resources/config/serialization')) {
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization', '/^$/')) {
$this->registerMappingFilesFromDir($dir, $fileRecorder);
}
}
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bridge\Twig\Extension\WebLinkExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileExistenceResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -118,9 +119,10 @@ public function load(array $configs, ContainerBuilder $container)
}
}

if ($container->fileExists($dir = $container->getParameter('kernel.root_dir').'/Resources/views', false)) {
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
}
$container->addResource(new FileExistenceResource($dir));

if (!empty($config['globals'])) {
$def = $container->getDefinition('twig');
Expand Down Expand Up @@ -178,13 +180,15 @@ private function getBundleHierarchy(ContainerBuilder $container)
);
}

if ($container->fileExists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views', false)) {
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) {
$bundleHierarchy[$name]['paths'][] = $dir;
}
$container->addResource(new FileExistenceResource($dir));

if ($container->fileExists($dir = $bundle['path'].'/Resources/views', false)) {
if (file_exists($dir = $bundle['path'].'/Resources/views')) {
$bundleHierarchy[$name]['paths'][] = $dir;
}
$container->addResource(new FileExistenceResource($dir));

if (null === $bundle['parent']) {
continue;
Expand Down
10 changes: 7 additions & 3 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -408,9 +408,13 @@ public function fileExists($path, $trackContents = true)
return $exists;
}

if ($trackContents && is_dir($path)) {
$this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
} elseif ($trackContents || is_dir($path)) {
if (is_dir($path)) {
if ($trackContents) {
$this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
} else {
$this->addResource(new GlobResource($path, '/*', false));
}
} elseif ($trackContents) {
$this->addResource(new FileResource($path));
}

Expand Down

0 comments on commit 9810018

Please sign in to comment.