Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 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 $loader;
25
    private $path;
26
    private $file;
27
 
28
    public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file)
29
    {
30
        $this->collection = $collection;
31
        $this->loader = $loader;
32
        $this->path = $path;
33
        $this->file = $file;
34
    }
35
 
36
    /**
37
     * @param string|string[]|null $exclude Glob patterns to exclude from the import
38
     */
39
    final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
40
    {
41
        $this->loader->setCurrentDir(\dirname($this->path));
42
 
43
        $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude) ?: [];
44
        if (!\is_array($imported)) {
45
            return new ImportConfigurator($this->collection, $imported);
46
        }
47
 
48
        $mergedCollection = new RouteCollection();
49
        foreach ($imported as $subCollection) {
50
            $mergedCollection->addCollection($subCollection);
51
        }
52
 
53
        return new ImportConfigurator($this->collection, $mergedCollection);
54
    }
55
 
56
    final public function collection(string $name = ''): CollectionConfigurator
57
    {
58
        return new CollectionConfigurator($this->collection, $name);
59
    }
60
 
61
    /**
62
     * @return static
63
     */
64
    final public function withPath(string $path): self
65
    {
66
        $clone = clone $this;
67
        $clone->path = $clone->file = $path;
68
 
69
        return $clone;
70
    }
71
}