Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Routing\Loader; Chris@0: Chris@0: use Symfony\Component\Config\Loader\FileLoader; Chris@17: use Symfony\Component\Config\Resource\DirectoryResource; Chris@0: use Symfony\Component\Routing\RouteCollection; Chris@0: Chris@0: class DirectoryLoader extends FileLoader Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function load($file, $type = null) Chris@0: { Chris@0: $path = $this->locator->locate($file); Chris@0: Chris@0: $collection = new RouteCollection(); Chris@0: $collection->addResource(new DirectoryResource($path)); Chris@0: Chris@0: foreach (scandir($path) as $dir) { Chris@0: if ('.' !== $dir[0]) { Chris@0: $this->setCurrentDir($path); Chris@0: $subPath = $path.'/'.$dir; Chris@0: $subType = null; Chris@0: Chris@0: if (is_dir($subPath)) { Chris@0: $subPath .= '/'; Chris@0: $subType = 'directory'; Chris@0: } Chris@0: Chris@0: $subCollection = $this->import($subPath, $subType, false, $path); Chris@0: $collection->addCollection($subCollection); Chris@0: } Chris@0: } Chris@0: Chris@0: return $collection; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supports($resource, $type = null) Chris@0: { Chris@0: // only when type is forced to directory, not to conflict with AnnotationLoader Chris@0: Chris@0: return 'directory' === $type; Chris@0: } Chris@0: }