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

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. /**
  15.  * @internal
  16.  */
  17. class AddResourcesPathsPass implements CompilerPassInterface
  18. {
  19.     public function process(ContainerBuilder $container): void
  20.     {
  21.         $container->setParameter('contao.resources_paths'$this->getResourcesPaths($container));
  22.     }
  23.     /**
  24.      * @return array<string>
  25.      */
  26.     private function getResourcesPaths(ContainerBuilder $container): array
  27.     {
  28.         $paths = [];
  29.         $projectDir $container->getParameter('kernel.project_dir');
  30.         $bundles $container->getParameter('kernel.bundles');
  31.         $meta $container->getParameter('kernel.bundles_metadata');
  32.         foreach ($bundles as $name => $class) {
  33.             if (ContaoModuleBundle::class === $class) {
  34.                 $paths[] = $meta[$name]['path'];
  35.             } elseif (is_dir($path $meta[$name]['path'].'/Resources/contao')) {
  36.                 $paths[] = $path;
  37.             } elseif (is_dir($path $meta[$name]['path'].'/contao')) {
  38.                 $paths[] = $path;
  39.             }
  40.         }
  41.         if (is_dir($projectDir.'/contao')) {
  42.             $paths[] = $projectDir.'/contao';
  43.         }
  44.         if (is_dir($projectDir.'/app/Resources/contao')) {
  45.             @trigger_error('Using "app/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.'E_USER_DEPRECATED);
  46.             $paths[] = $projectDir.'/app/Resources/contao';
  47.         }
  48.         if (is_dir($projectDir.'/src/Resources/contao')) {
  49.             @trigger_error('Using "src/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.'E_USER_DEPRECATED);
  50.             $paths[] = $projectDir.'/src/Resources/contao';
  51.         }
  52.         return $paths;
  53.     }
  54. }