|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bankiru\Seo\Listener; |
| 4 | + |
| 5 | +use Bankiru\Seo\DestinationInterface; |
| 6 | +use Bankiru\Seo\DestinationMatcherInterface; |
| 7 | +use Bankiru\Seo\Exception\MatchingException; |
| 8 | +use Bankiru\Seo\Page\SeoPageInterface; |
| 9 | + |
| 10 | +final class MasterSeoRequest |
| 11 | +{ |
| 12 | + /** @var DestinationInterface */ |
| 13 | + private $destination; |
| 14 | + /** @var SeoPageInterface */ |
| 15 | + private $page; |
| 16 | + /** @var DestinationMatcherInterface */ |
| 17 | + private $matcher; |
| 18 | + |
| 19 | + /** |
| 20 | + * MasterSeoRequest constructor. |
| 21 | + * |
| 22 | + * @param DestinationMatcherInterface $matcher |
| 23 | + */ |
| 24 | + public function __construct(DestinationMatcherInterface $matcher) |
| 25 | + { |
| 26 | + $this->matcher = $matcher; |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + /** |
| 31 | + * @return DestinationInterface|null |
| 32 | + * @throws \LogicException |
| 33 | + */ |
| 34 | + public function getDestination() |
| 35 | + { |
| 36 | + if (null === $this->destination) { |
| 37 | + throw new \LogicException('Destination is not set'); |
| 38 | + } |
| 39 | + |
| 40 | + return $this->destination; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @param DestinationInterface $destination |
| 45 | + */ |
| 46 | + public function setDestination(DestinationInterface $destination) |
| 47 | + { |
| 48 | + $this->destination = $destination; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return SeoPageInterface |
| 53 | + * @throws \LogicException |
| 54 | + * @throws MatchingException |
| 55 | + */ |
| 56 | + public function getPage() |
| 57 | + { |
| 58 | + if (null === $this->page) { |
| 59 | + $this->page = $this->matcher->match($this->getDestination()); |
| 60 | + } |
| 61 | + |
| 62 | + return $this->page; |
| 63 | + } |
| 64 | +} |
0 commit comments