vendor/symfony/dependency-injection/Loader/DirectoryLoader.php line 42

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\DependencyInjection\Loader;
  11. /**
  12.  * DirectoryLoader is a recursive loader to go through directories.
  13.  *
  14.  * @author Sebastien Lavoie <seb@wemakecustom.com>
  15.  */
  16. class DirectoryLoader extends FileLoader
  17. {
  18.     public function load(mixed $filestring $type null): mixed
  19.     {
  20.         $file rtrim($file'/');
  21.         $path $this->locator->locate($file);
  22.         $this->container->fileExists($pathfalse);
  23.         foreach (scandir($path) as $dir) {
  24.             if ('.' !== $dir[0]) {
  25.                 if (is_dir($path.'/'.$dir)) {
  26.                     $dir .= '/'// append / to allow recursion
  27.                 }
  28.                 $this->setCurrentDir($path);
  29.                 $this->import($dirnullfalse$path);
  30.             }
  31.         }
  32.         return null;
  33.     }
  34.     public function supports(mixed $resourcestring $type null): bool
  35.     {
  36.         if ('directory' === $type) {
  37.             return true;
  38.         }
  39.         return null === $type && \is_string($resource) && str_ends_with($resource'/');
  40.     }
  41. }