"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.4.48/core-bundle/src/DependencyInjection/Compiler/AddResourcesPathsPass.php" (2 Apr 2020, 1972 Bytes) of package /linux/www/contao-4.4.48.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddResourcesPathsPass.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.8.8_vs_4.9.0.

    1 <?php
    2 
    3 /*
    4  * This file is part of Contao.
    5  *
    6  * (c) Leo Feyer
    7  *
    8  * @license LGPL-3.0-or-later
    9  */
   10 
   11 namespace Contao\CoreBundle\DependencyInjection\Compiler;
   12 
   13 use Contao\CoreBundle\HttpKernel\Bundle\ContaoModuleBundle;
   14 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
   15 use Symfony\Component\DependencyInjection\ContainerBuilder;
   16 
   17 /**
   18  * Adds the bundle resources paths to the container.
   19  *
   20  * @author Leo Feyer <https://github.com/leofeyer>
   21  */
   22 class AddResourcesPathsPass implements CompilerPassInterface
   23 {
   24     /**
   25      * {@inheritdoc}
   26      */
   27     public function process(ContainerBuilder $container)
   28     {
   29         $container->setParameter('contao.resources_paths', $this->getResourcesPaths($container));
   30     }
   31 
   32     /**
   33      * Returns the Contao resources paths as array.
   34      *
   35      * @param ContainerBuilder $container
   36      *
   37      * @return array
   38      */
   39     private function getResourcesPaths(ContainerBuilder $container)
   40     {
   41         $paths = [];
   42         $rootDir = $container->getParameter('kernel.project_dir');
   43 
   44         foreach ($container->getParameter('kernel.bundles') as $name => $class) {
   45             if (ContaoModuleBundle::class === $class) {
   46                 $paths[] = sprintf('%s/system/modules/%s', $rootDir, $name);
   47             } elseif (null !== ($path = $this->getResourcesPathFromClassName($class))) {
   48                 $paths[] = $path;
   49             }
   50         }
   51 
   52         if (is_dir($rootDir.'/app/Resources/contao')) {
   53             $paths[] = $rootDir.'/app/Resources/contao';
   54         }
   55 
   56         return $paths;
   57     }
   58 
   59     /**
   60      * Returns the resources path from the class name.
   61      *
   62      * @param string $class
   63      *
   64      * @return string|null
   65      */
   66     private function getResourcesPathFromClassName($class)
   67     {
   68         $reflection = new \ReflectionClass($class);
   69 
   70         if (is_dir($dir = \dirname($reflection->getFileName()).'/Resources/contao')) {
   71             return $dir;
   72         }
   73 
   74         return null;
   75     }
   76 }