-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractSitemapProvider.php
58 lines (48 loc) · 1.3 KB
/
AbstractSitemapProvider.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
<?php
declare(strict_types=1);
/*
* Studio 107 (c) 2017 Maxim Falaleev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mindy\Sitemap;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Class AbstractSitemapProvider.
*/
abstract class AbstractSitemapProvider implements SitemapProviderInterface
{
/**
* @var UrlGeneratorInterface
*/
protected $router;
/**
* PageProvider constructor.
*
* @param UrlGeneratorInterface $router
*/
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* @param string $hostWithScheme
* @param $route
* @param array $parameters
*
* @return string
*/
protected function generateLoc($hostWithScheme, $route, $parameters = [])
{
if (null === $this->router) {
throw new \RuntimeException('UrlGenerator interface is missing');
}
list($scheme, $host) = explode('://', $hostWithScheme);
$this->router
->getContext()
->setHost($host)
->setScheme($scheme);
return $this->router->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
}
}