1 | <?php |
||
9 | trait THelpers |
||
10 | { |
||
11 | /** |
||
12 | * Render a view with an optional data set of variables. |
||
13 | * |
||
14 | * @param string $template the template file, or array |
||
15 | * @param array $data variables to make available to the |
||
16 | * view, default is empty |
||
17 | * |
||
18 | * @return void |
||
19 | */ |
||
20 | public function renderView($template, $data = []) |
||
28 | |||
29 | |||
30 | |||
31 | /** |
||
32 | * Create a class attribute from a string or array. |
||
33 | * |
||
34 | * @param string|array $args variable amount of classlists. |
||
35 | * |
||
36 | * @return string as complete class attribute |
||
37 | */ |
||
38 | 5 | public function classList(...$args) |
|
53 | |||
54 | |||
55 | |||
56 | /** |
||
57 | * Create an url for a static asset. |
||
58 | * |
||
59 | * @param string $uri part of uri to use when creating an url. |
||
60 | * |
||
61 | * @return string as resulting url. |
||
62 | */ |
||
63 | public function asset($uri = null) |
||
67 | |||
68 | |||
69 | |||
70 | /** |
||
71 | * Create an url and prepending the baseUrl. |
||
72 | * |
||
73 | * @param string $uri part of uri to use when creating an url. "" or null |
||
74 | * means baseurl to current frontcontroller. |
||
75 | * |
||
76 | * @return string as resulting url. |
||
77 | */ |
||
78 | public function url($uri = null) |
||
82 | |||
83 | |||
84 | |||
85 | /** |
||
86 | * Get current url, without querystring. |
||
87 | * |
||
88 | * @return string as resulting url. |
||
89 | */ |
||
90 | public function currentUrl() |
||
94 | |||
95 | |||
96 | |||
97 | /** |
||
98 | * Check if the region in the view container has views to render. |
||
99 | * |
||
100 | * @param string $region to check |
||
101 | * |
||
102 | * @return boolean true or false |
||
103 | */ |
||
104 | public function regionHasContent($region) |
||
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * Render views, from the view container, in the region. |
||
113 | * |
||
114 | * @param string $region to render in |
||
115 | * |
||
116 | * @return boolean true or false |
||
117 | */ |
||
118 | public function renderRegion($region) |
||
122 | |||
123 | |||
124 | |||
125 | /** |
||
126 | * Load content from a route and return details to view. |
||
127 | * |
||
128 | * @param string $route to load content from. |
||
129 | * |
||
130 | * @return array with values to extract in view. |
||
131 | */ |
||
132 | public function getContentForRoute($route) |
||
137 | |||
138 | |||
139 | |||
140 | /** |
||
141 | * Wrap a HTML element with start and end. |
||
142 | * |
||
143 | * @param string $text with content |
||
144 | * @param string $tag HTML tag to search for |
||
145 | * @param string $start wrap start part |
||
146 | * @param string $end wrap end part |
||
147 | * @param number $count hits to search for |
||
148 | * |
||
149 | * @return array with values to extract in view. |
||
150 | */ |
||
151 | public function wrapElementWithStartEnd($text, $tag, $start, $end, $count) |
||
155 | |||
156 | |||
157 | |||
158 | /** |
||
159 | * Wrap content of a HTML element with start and end. |
||
160 | * |
||
161 | * @param string $text with content |
||
162 | * @param string $tag HTML tag to search for |
||
163 | * @param string $start wrap start part |
||
164 | * @param string $end wrap end part |
||
165 | * @param number $count hits to search for |
||
166 | * |
||
167 | * @return array with values to extract in view. |
||
168 | */ |
||
169 | public function wrapElementContentWithStartEnd($text, $tag, $start, $end, $count) |
||
173 | |||
174 | |||
175 | |||
176 | /** |
||
177 | * Extrat the publish or update date for the article. |
||
178 | * |
||
179 | * @param array $dates a collection of possible date values. |
||
180 | * |
||
181 | * @return array with values for showing the date. |
||
182 | */ |
||
183 | public function getPublishedDate($dates) |
||
205 | } |
||
206 |
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: