vendor/contao/core-bundle/src/DependencyInjection/Compiler/AddResourcesPathsPass.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\DependencyInjection\Compiler;
  11. use Contao\CoreBundle\HttpKernel\Bundle\ContaoModuleBundle;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\Filesystem\Path;
  15. /**
  16.  * @internal
  17.  */
  18. class AddResourcesPathsPass implements CompilerPassInterface
  19. {
  20.     public function process(ContainerBuilder $container): void
  21.     {
  22.         $container->setParameter('contao.resources_paths'$this->getResourcesPaths($container));
  23.     }
  24.     /**
  25.      * @return array<string>
  26.      */
  27.     private function getResourcesPaths(ContainerBuilder $container): array
  28.     {
  29.         $paths = [];
  30.         $projectDir $container->getParameter('kernel.project_dir');
  31.         $bundles $container->getParameter('kernel.bundles');
  32.         $meta $container->getParameter('kernel.bundles_metadata');
  33.         foreach ($bundles as $name => $class) {
  34.             if (ContaoModuleBundle::class === $class) {
  35.                 $paths[] = $meta[$name]['path'];
  36.             } elseif (is_dir($path Path::join($meta[$name]['path'], 'Resources/contao'))) {
  37.                 $paths[] = $path;
  38.             } elseif (is_dir($path Path::join($meta[$name]['path'], 'contao'))) {
  39.                 $paths[] = $path;
  40.             }
  41.         }
  42.         if (is_dir($path Path::join($projectDir'contao'))) {
  43.             $paths[] = $path;
  44.         }
  45.         if (is_dir($path Path::join($projectDir'app/Resources/contao'))) {
  46.             trigger_deprecation('contao/core-bundle''4.9''Using "app/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.');
  47.             $paths[] = $path;
  48.         }
  49.         if (is_dir($path Path::join($projectDir'src/Resources/contao'))) {
  50.             trigger_deprecation('contao/core-bundle''4.9''Using "src/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.');
  51.             $paths[] = $path;
  52.         }
  53.         return $paths;
  54.     }
  55. }