1 | <?php |
||
14 | trait UrlParserTrait |
||
15 | { |
||
16 | /** |
||
17 | * Enforces HTTPS-scheme on URL |
||
18 | * |
||
19 | * Applied if: |
||
20 | * - current host runs on HTTPS |
||
21 | * |
||
22 | * @param string $url URL |
||
23 | * @return string |
||
24 | */ |
||
25 | protected function _urlToHttps(string $url): string |
||
33 | |||
34 | /** |
||
35 | * Generate email link |
||
36 | * |
||
37 | * @param string $url address |
||
38 | * @param string $text title |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | protected function _email($url, $text = null) |
||
51 | |||
52 | /** |
||
53 | * Generate URL |
||
54 | * |
||
55 | * @param string $url URL |
||
56 | * @param string $text title |
||
57 | * @param bool $label show label |
||
58 | * @param bool $truncate trunctate |
||
59 | * |
||
60 | * @return string |
||
61 | * @throws \Exception |
||
62 | */ |
||
63 | protected function _url($url, $text, $label = false, $truncate = false) |
||
95 | |||
96 | /** |
||
97 | * Truncates long links |
||
98 | * |
||
99 | * @bogus does this truncate strings or the longest word in the string or |
||
100 | * what? |
||
101 | * @bogus what about [url=][img]...[/img][url]. Is the [img] url truncated |
||
102 | * too? |
||
103 | * |
||
104 | * @param string $string string |
||
105 | * |
||
106 | * @throws \Exception |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function _truncate($string) |
||
129 | |||
130 | /** |
||
131 | * Adds target="_blank" to *all* external links in arbitrary string $string |
||
132 | * |
||
133 | * @param string $string string |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | protected function _decorateTarget($string) |
||
164 | |||
165 | /** |
||
166 | * Creates an URL to an uploaded file based on $id |
||
167 | * |
||
168 | * @param string $id currently name in uploads folder |
||
169 | * @return string URL |
||
170 | */ |
||
171 | protected function _linkToUploadedFile(string $id) : string |
||
178 | } |
||
179 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: