1 | <?php |
||
23 | class ArticleResolver implements ArticleResolverInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var UrlMatcherInterface |
||
27 | */ |
||
28 | private $matcher; |
||
29 | |||
30 | /** |
||
31 | * @var CacheProvider |
||
32 | */ |
||
33 | private $cacheProvider; |
||
34 | |||
35 | public function __construct(UrlMatcherInterface $matcher, CacheProvider $cacheProvider) |
||
40 | |||
41 | public function resolve(string $url): ?ArticleInterface |
||
42 | { |
||
43 | $collectionRouteCacheKey = md5('route_'.$url); |
||
44 | |||
45 | $result = null; |
||
46 | |||
47 | if ($this->cacheProvider->contains($collectionRouteCacheKey)) { |
||
48 | return $result; |
||
49 | } |
||
50 | |||
51 | try { |
||
52 | $route = $this->matcher->match($this->getFragmentFromUrl($url, 'path')); |
||
53 | |||
54 | if (isset($route['_article_meta']) && $route['_article_meta'] instanceof Meta && $route['_article_meta']->getValues() instanceof ArticleInterface) { |
||
55 | return $route['_article_meta']->getValues(); |
||
56 | } |
||
57 | } catch (ResourceNotFoundException $e) { |
||
|
|||
58 | } |
||
59 | |||
60 | $this->cacheProvider->save($collectionRouteCacheKey, $result); |
||
61 | |||
62 | return $result; |
||
63 | } |
||
64 | |||
65 | private function getFragmentFromUrl(string $url, string $fragment): ?string |
||
74 | } |
||
75 |