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\Configurator;
13
 
14
use Symfony\Component\Routing\Loader\PhpFileLoader;
15
use Symfony\Component\Routing\RouteCollection;
16
 
17
/**
18
 * @author Nicolas Grekas <p@tchwork.com>
19
 */
20
class RoutingConfigurator
21
{
22
    use Traits\AddTrait;
23
 
24
    private PhpFileLoader $loader;
25
    private string $path;
26
    private string $file;
27
    private ?string $env;
28
 
29
    public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, string $env = null)
30
    {
31
        $this->collection = $collection;
32
        $this->loader = $loader;
33
        $this->path = $path;
34
        $this->file = $file;
35
        $this->env = $env;
36
    }
37
 
38
    /**
39
     * @param string|string[]|null $exclude Glob patterns to exclude from the import
40
     */
41
    final public function import(string|array $resource, string $type = null, bool $ignoreErrors = false, string|array $exclude = null): ImportConfigurator
42
    {
43
        $this->loader->setCurrentDir(\dirname($this->path));
44
 
45
        $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude) ?: [];
46
        if (!\is_array($imported)) {
47
            return new ImportConfigurator($this->collection, $imported);
48
        }
49
 
50
        $mergedCollection = new RouteCollection();
51
        foreach ($imported as $subCollection) {
52
            $mergedCollection->addCollection($subCollection);
53
        }
54
 
55
        return new ImportConfigurator($this->collection, $mergedCollection);
56
    }
57
 
58
    final public function collection(string $name = ''): CollectionConfigurator
59
    {
60
        return new CollectionConfigurator($this->collection, $name);
61
    }
62
 
63
    /**
64
     * Get the current environment to be able to write conditional configuration.
65
     */
66
    final public function env(): ?string
67
    {
68
        return $this->env;
69
    }
70
 
71
    final public function withPath(string $path): static
72
    {
73
        $clone = clone $this;
74
        $clone->path = $clone->file = $path;
75
 
76
        return $clone;
77
    }
78
}