-
Notifications
You must be signed in to change notification settings - Fork 0
/
InMemoryProvider.php
95 lines (76 loc) · 2.34 KB
/
InMemoryProvider.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Sky\Bundle\SeoBundle;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
class InMemoryProvider
{
protected $defaults;
protected $routes;
protected $routeCollection;
function __construct ($defaults, $routes)
{
$this->defaults = $defaults;
$this->routes = $routes;
$this->routeCollection = null;
}
public function getTitle ($routeName)
{
if (isset($this->routes[$routeName]['title'])) {
$title = $this->routes[$routeName]['title'];
} else {
$title = $this->defaults['title'];
}
return $title;
}
public function getMetaContent($routeName, $attributeName, $attributeValue)
{
if (isset($this->routes[$routeName]['metas'][$attributeName][$attributeValue]))
{
$content = $this->routes[$routeName]['metas'][$attributeName][$attributeValue];
}
elseif (isset($this->defaults['metas'][$attributeName][$attributeValue]))
{
$content = $this->defaults['metas'][$attributeName][$attributeValue];
}
else
{
$content = null;
}
return $content;
}
public function getMetas ($routeName)
{
$metas = $this->defaults['metas'];
$overwriteMetas = array();
if (isset($this->routes[$routeName]['metas']))
{
$overwriteMetas = $this->routes[$routeName]['metas'];
}
foreach($overwriteMetas as $metasKey => $metasValues)
{
foreach ($metasValues as $metaKey => $metaValue)
{
$metas[$metasKey][$metaKey] = $metaValue;
}
}
return $metas;
}
/**
*
* @return the $routeCollection
*/
public function getRouteCollection ()
{
if ($this->routeCollection === null)
{
$routes = $this->routes;
$routeCollection = new RouteCollection();
foreach ($routes as $name => $value) {
$routeCollection->add($name, new Route($value['pattern']));
unset($this->routes[$name]['pattern']);
}
$this->routeCollection = $routeCollection;
}
return $this->routeCollection;
}
}