Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Routing\Loader;
13
 
14
use Symfony\Component\Config\Loader\FileLoader;
15
use Symfony\Component\Config\Resource\DirectoryResource;
16
use Symfony\Component\Routing\RouteCollection;
17
 
18
class DirectoryLoader extends FileLoader
19
{
20
    public function load(mixed $file, string $type = null): mixed
21
    {
22
        $path = $this->locator->locate($file);
23
 
24
        $collection = new RouteCollection();
25
        $collection->addResource(new DirectoryResource($path));
26
 
27
        foreach (scandir($path) as $dir) {
28
            if ('.' !== $dir[0]) {
29
                $this->setCurrentDir($path);
30
                $subPath = $path.'/'.$dir;
31
                $subType = null;
32
 
33
                if (is_dir($subPath)) {
34
                    $subPath .= '/';
35
                    $subType = 'directory';
36
                }
37
 
38
                $subCollection = $this->import($subPath, $subType, false, $path);
39
                $collection->addCollection($subCollection);
40
            }
41
        }
42
 
43
        return $collection;
44
    }
45
 
46
    public function supports(mixed $resource, string $type = null): bool
47
    {
48
        // only when type is forced to directory, not to conflict with AnnotationLoader
49
 
50
        return 'directory' === $type;
51
    }
52
}