forked from bankiru/seo-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestinationMatcher.php
39 lines (33 loc) · 1.11 KB
/
DestinationMatcher.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
<?php
namespace Bankiru\Seo;
use Bankiru\Seo\Exception\MatchingException;
use Bankiru\Seo\Exception\PageException;
use Bankiru\Seo\Target\TargetSorter;
final class DestinationMatcher implements DestinationMatcherInterface
{
/** @var PageRepositoryInterface */
private $pageRepository;
/** @var TargetSorter */
private $sorter;
/**
* DestinationMatcher constructor.
*
* @param TargetSorter $sorter
* @param PageRepositoryInterface $pageRepository
*/
public function __construct(TargetSorter $sorter, PageRepositoryInterface $pageRepository)
{
$this->pageRepository = $pageRepository;
$this->sorter = $sorter;
}
/** {@inheritdoc} */
public function match(DestinationInterface $destination)
{
$target = $this->sorter->getMatchingTarget($destination);
try {
return $this->pageRepository->getByTargetDestination($target, $destination);
} catch (PageException $exception) {
throw new MatchingException($exception->getMessage(), $exception->getCode(), $exception);
}
}
}