1 | <?php |
||
28 | class SeoUrlMatcher extends RedirectableUrlMatcher |
||
29 | { |
||
30 | const SCHEME_HTTP = 'http'; |
||
31 | |||
32 | /** |
||
33 | * @var RedirectableUrlMatcher |
||
34 | */ |
||
35 | protected $cachedMatcher = null; |
||
36 | |||
37 | /** |
||
38 | * @var Manager |
||
39 | */ |
||
40 | protected $esManager = null; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $typeMap = null; |
||
46 | |||
47 | /** |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $allowHttps = false; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $urlKey = null; |
||
56 | |||
57 | /** |
||
58 | * @var SeoUrlMapper |
||
59 | */ |
||
60 | protected $seoUrlMapper; |
||
61 | |||
62 | /** |
||
63 | * @param RedirectableUrlMatcher $parentMatcher Parent matcher that is called when this matcher fails. |
||
64 | * @param Manager $esManager ES manager. |
||
65 | * @param array $typeMap Type map. |
||
66 | * @param bool $allowHttps Is https allowed. |
||
67 | * @param string $urlKey Url key to search routes with. |
||
68 | */ |
||
69 | public function __construct($parentMatcher, $esManager, $typeMap, $allowHttps = false, $urlKey = null) |
||
77 | |||
78 | /** |
||
79 | * Sets SEO URL mapper. |
||
80 | * |
||
81 | * @param SeoUrlMapper $seoUrlMapper SEO URL mapper. |
||
82 | */ |
||
83 | public function setSeoUrlMapper($seoUrlMapper) |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function match($pathinfo) |
||
144 | |||
145 | /** |
||
146 | * Cached matcher redirect. |
||
147 | * |
||
148 | * @param string $link URL. |
||
149 | * @param string $route Route name. |
||
150 | * @param string $scheme Scheme to use. E.g. 'http' or 'https'. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function doRedirect($link, $route, $scheme = self::SCHEME_HTTP) |
||
158 | |||
159 | /** |
||
160 | * Hacky solution to get seo key and url. |
||
161 | * |
||
162 | * @param SeoAwareTrait $document Document. |
||
163 | * @param string $url Url. |
||
164 | * |
||
165 | * @return array |
||
166 | * @throws \LogicException |
||
167 | */ |
||
168 | protected function getLink($document, $url) |
||
179 | |||
180 | /** |
||
181 | * Generates hash for given url. |
||
182 | * |
||
183 | * @param string $url URL string. |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | protected function getUrlHash($url) |
||
191 | |||
192 | /** |
||
193 | * Returns search instance that is used to search for documents in Elasticsearch. |
||
194 | * |
||
195 | * @param string $url URL. |
||
196 | * |
||
197 | * @return Search |
||
198 | */ |
||
199 | protected function getSearch($url) |
||
219 | |||
220 | /** |
||
221 | * Returns document by URL. |
||
222 | * |
||
223 | * @param string $url URL. |
||
224 | * |
||
225 | * @return array|null |
||
226 | * @throws \Exception Search type not found. |
||
227 | */ |
||
228 | private function getDocumentByUrl($url) |
||
241 | |||
242 | /** |
||
243 | * Helper method to ensure that link has slash prefix. |
||
244 | * |
||
245 | * @param string $link Link. |
||
246 | * |
||
247 | * @return string Link with slash prefix. |
||
248 | */ |
||
249 | private function ensurePrefixSlash($link) |
||
257 | |||
258 | /** |
||
259 | * @return SeoUrlMapper |
||
260 | */ |
||
261 | public function getSeoUrlMapper() |
||
265 | |||
266 | /** |
||
267 | * @return array |
||
268 | */ |
||
269 | public function getTypeMap() |
||
273 | |||
274 | /** |
||
275 | * @return Manager |
||
276 | */ |
||
277 | public function getEsManager() |
||
281 | |||
282 | /** |
||
283 | * @return RedirectableUrlMatcher |
||
284 | */ |
||
285 | public function getCachedMatcher() |
||
289 | } |
||
290 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.