-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seo.php
100 lines (80 loc) · 2.47 KB
/
Seo.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
96
97
98
99
100
<?php
namespace Sky\Bundle\SeoBundle;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\DependencyInjection\ContainerAware;
class Seo extends ContainerAware
{
protected $match = null;
/**
* Returns meta content.
*
* @param $attributeName string
* @param $attributeValue string
* @return string meta content
*/
public function getMetaContent ($attributeName, $attributeValue)
{
$routeName = $this->getRouteName();
$metaContent = $this->getProvider()->getMetaContent($routeName,
$attributeName, $attributeValue);
return $metaContent;
}
public function getMetas ()
{
$routeName = $this->getRouteName();
$metas = $this->getProvider()->getMetas($routeName);
return $metas;
}
private function getRouteName ()
{
$match = $this->getMatch();
if (isset($match['_route'])) {
$routeName = $match['_route'];
} else {
$routeName = '';
}
return $routeName;
}
public function getTitle ()
{
$routeName = $this->getRouteName();
$title = $this->getProvider()->getTitle($routeName);
return $title;
}
protected function getMatch ()
{
if ($this->match == null) {
$matcher = $this->getMatcher();
$path = $req = $this->container->get('request')->getPathInfo();
if (($path) != '/')
{
$path =rtrim($path, "/");
}
try {
$match = $matcher->match($path);
}
catch(ResourceNotFoundException $e)
{
$match = array();
}
$this->match = $match;
} else {
$match = $this->match;
}
return $match;
}
protected function getMatcher ()
{
$context = $this->container->get('router')->getContext();
$provider = $this->getProvider();
$routeCollection = $provider->getRouteCollection();
$matcher = new UrlMatcher($routeCollection, $context);
return $matcher;
}
protected function getProvider ()
{
$inMemoryProvider = $this->container->get('sky_seo.providers.in_memory');
return $inMemoryProvider;
}
}