| 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\Traits;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\Routing\Loader\Configurator\CollectionConfigurator;
|
|
|
15 |
use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;
|
|
|
16 |
use Symfony\Component\Routing\RouteCollection;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
20 |
*/
|
|
|
21 |
trait AddTrait
|
|
|
22 |
{
|
|
|
23 |
use LocalizedRouteTrait;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @var RouteCollection
|
|
|
27 |
*/
|
|
|
28 |
protected $collection;
|
|
|
29 |
protected $name = '';
|
|
|
30 |
protected $prefixes;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Adds a route.
|
|
|
34 |
*
|
|
|
35 |
* @param string|array $path the path, or the localized paths of the route
|
|
|
36 |
*/
|
|
|
37 |
public function add(string $name, $path): RouteConfigurator
|
|
|
38 |
{
|
|
|
39 |
$parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
|
|
|
40 |
$route = $this->createLocalizedRoute($this->collection, $name, $path, $this->name, $this->prefixes);
|
|
|
41 |
|
|
|
42 |
return new RouteConfigurator($this->collection, $route, $this->name, $parentConfigurator, $this->prefixes);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Adds a route.
|
|
|
47 |
*
|
|
|
48 |
* @param string|array $path the path, or the localized paths of the route
|
|
|
49 |
*/
|
|
|
50 |
public function __invoke(string $name, $path): RouteConfigurator
|
|
|
51 |
{
|
|
|
52 |
return $this->add($name, $path);
|
|
|
53 |
}
|
|
|
54 |
}
|