1 | <?php |
||
13 | trait PermalinkDocumentTrait |
||
14 | { |
||
15 | /** @var string */ |
||
16 | protected $permalink = null; |
||
17 | |||
18 | /** @var array */ |
||
19 | protected $redirects = null; |
||
20 | |||
21 | /** Extensions that need to be stripped from permalinks. */ |
||
22 | private static $extensionsToStrip = ['twig']; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | 1 | public function handleSpecialRedirects() |
|
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 6 | final public function getTargetFile() |
|
35 | { |
||
36 | 6 | $permalink = $this->getPermalink(); |
|
37 | 6 | $missingFile = (substr($permalink, -1) == '/'); |
|
38 | 6 | $permalink = str_replace('/', DIRECTORY_SEPARATOR, $permalink); |
|
39 | |||
40 | 6 | if ($missingFile) |
|
41 | { |
||
42 | 2 | $permalink = rtrim($permalink, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'index.html'; |
|
43 | } |
||
44 | |||
45 | 6 | return ltrim($permalink, DIRECTORY_SEPARATOR); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 25 | final public function getPermalink() |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 2 | final public function getRedirects() |
|
76 | |||
77 | /** |
||
78 | * Get the permalink based off the location of where the file is relative to the website. This permalink is to be |
||
79 | * used as a fallback in the case that a permalink is not explicitly specified in the Front Matter. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | 3 | final protected function getPathPermalink() |
|
107 | |||
108 | /** |
||
109 | * Sanitize a permalink to remove unsupported characters or multiple '/' and replace spaces with hyphens. |
||
110 | * |
||
111 | * @param string $permalink A permalink |
||
112 | * |
||
113 | * @return string $permalink The sanitized permalink |
||
114 | */ |
||
115 | 25 | final private function sanitizePermalink($permalink) |
|
142 | } |
||
143 |
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.