|
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\Bundle\FrameworkBundle\Controller\ControllerNameParser; |
|
|
15 |
use Symfony\Component\Config\Loader\DelegatingLoader as BaseDelegatingLoader; |
|
|
16 |
use Symfony\Component\Config\Loader\LoaderResolverInterface; |
|
|
17 |
use Symfony\Component\HttpKernel\Log\LoggerInterface; |
|
|
18 |
|
|
|
19 |
/** |
|
|
20 |
* DelegatingLoader delegates route loading to other loaders using a loader resolver. |
|
|
21 |
* |
|
|
22 |
* This implementation resolves the _controller attribute from the short notation |
|
|
23 |
* to the fully-qualified form (from a:b:c to class:method). |
|
|
24 |
* |
|
|
25 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
26 |
*/ |
|
|
27 |
class DelegatingLoader extends BaseDelegatingLoader |
|
|
28 |
{ |
|
|
29 |
protected $parser; |
|
|
30 |
protected $logger; |
|
|
31 |
|
|
|
32 |
/** |
|
|
33 |
* Constructor. |
|
|
34 |
* |
|
|
35 |
* @param ControllerNameParser $parser A ControllerNameParser instance |
|
|
36 |
* @param LoggerInterface $logger A LoggerInterface instance |
|
|
37 |
* @param LoaderResolverInterface $resolver A LoaderResolverInterface instance |
|
|
38 |
*/ |
|
|
39 |
public function __construct(ControllerNameParser $parser, LoggerInterface $logger = null, LoaderResolverInterface $resolver) |
|
|
40 |
{ |
|
|
41 |
$this->parser = $parser; |
|
|
42 |
$this->logger = $logger; |
|
|
43 |
|
|
|
44 |
parent::__construct($resolver); |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
/** |
|
|
48 |
* Loads a resource. |
|
|
49 |
* |
|
|
50 |
* @param mixed $resource A resource |
|
|
51 |
* @param string $type The resource type |
|
|
52 |
* |
|
|
53 |
* @return RouteCollection A RouteCollection instance |
|
|
54 |
*/ |
|
|
55 |
public function load($resource, $type = null) |
|
|
56 |
{ |
|
|
57 |
$collection = parent::load($resource, $type); |
|
|
58 |
|
|
|
59 |
foreach ($collection->all() as $name => $route) { |
|
|
60 |
if ($controller = $route->getDefault('_controller')) { |
|
|
61 |
try { |
|
|
62 |
$controller = $this->parser->parse($controller); |
|
|
63 |
} catch (\Exception $e) { |
|
|
64 |
// unable to optimize unknown notation |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
$route->setDefault('_controller', $controller); |
|
|
68 |
} |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
return $collection; |
|
|
72 |
} |
|
|
73 |
} |