|
0
|
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\Bundle\FrameworkBundle\Routing; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Routing\Router as BaseRouter; |
|
|
15 |
use Symfony\Component\Routing\RequestContext; |
|
|
16 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
17 |
|
|
|
18 |
/** |
|
|
19 |
* This Router only creates the Loader only when the cache is empty. |
|
|
20 |
* |
|
|
21 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
22 |
*/ |
|
|
23 |
class Router extends BaseRouter |
|
|
24 |
{ |
|
|
25 |
private $container; |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* Constructor. |
|
|
29 |
* |
|
|
30 |
* @param ContainerInterface $container A ContainerInterface instance |
|
|
31 |
* @param mixed $resource The main resource to load |
|
|
32 |
* @param array $options An array of options |
|
|
33 |
* @param RequestContext $context The context |
|
|
34 |
* @param array $defaults The default values |
|
|
35 |
*/ |
|
|
36 |
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, array $defaults = array()) |
|
|
37 |
{ |
|
|
38 |
$this->container = $container; |
|
|
39 |
|
|
|
40 |
$this->resource = $resource; |
|
|
41 |
$this->context = null === $context ? new RequestContext() : $context; |
|
|
42 |
$this->defaults = $defaults; |
|
|
43 |
$this->setOptions($options); |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
/** |
|
|
47 |
* @{inheritdoc} |
|
|
48 |
*/ |
|
|
49 |
public function getRouteCollection() |
|
|
50 |
{ |
|
|
51 |
if (null === $this->collection) { |
|
|
52 |
$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']); |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
return $this->collection; |
|
|
56 |
} |
|
|
57 |
} |