forked from symfony-cmf/Routing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderBasedGenerator.php
More file actions
60 lines (50 loc) · 1.78 KB
/
ProviderBasedGenerator.php
File metadata and controls
60 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Symfony\Cmf\Component\Routing;
use Symfony\Component\Routing\Route as SymfonyRoute;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Cmf\Component\Routing\RouteProviderInterface;
/**
* A Generator that uses a RouteProvider rather than a RouteCollection
*
* @author Larry Garfield
*/
class ProviderBasedGenerator extends UrlGenerator
{
/**
* The route provider for this generator.
*
* @var RouteProviderInterface
*/
protected $provider;
public function __construct(RouteProviderInterface $provider, LoggerInterface $logger = null)
{
$this->provider = $provider;
$this->logger = $logger;
}
/**
* {@inheritDoc}
*/
public function generate($name, $parameters = array(), $absolute = false)
{
if ($name instanceof SymfonyRoute) {
$route = $name;
} elseif (null === $route = $this->provider->getRouteByName($name, $parameters)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
// the Route has a cache of its own and is not recompiled as long as it does not get modified
$compiledRoute = $route->compile();
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $absolute, $compiledRoute->getHostnameTokens());
}
/**
* Support a route object and any string as route name
*
* {@inheritDoc}
*/
public function supports($name)
{
return is_string($name) || $name instanceof SymfonyRoute;
}
}