4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Loader;
14 use Symfony\Component\Config\Resource\DirectoryResource;
17 * DirectoryLoader is a recursive loader to go through directories.
19 * @author Sebastien Lavoie <seb@wemakecustom.com>
21 class DirectoryLoader extends FileLoader
26 public function load($file, $type = null)
28 $file = rtrim($file, '/');
29 $path = $this->locator->locate($file);
30 $this->container->addResource(new DirectoryResource($path));
32 foreach (scandir($path) as $dir) {
33 if ('.' !== $dir[0]) {
34 if (is_dir($path.'/'.$dir)) {
35 $dir .= '/'; // append / to allow recursion
38 $this->setCurrentDir($path);
40 $this->import($dir, null, false, $path);
48 public function supports($resource, $type = null)
50 if ('directory' === $type) {
54 return null === $type && is_string($resource) && '/' === substr($resource, -1);