1 | <?php |
||
26 | class UtilityTwigExtension extends AbstractTwigExtension { |
||
27 | |||
28 | /** |
||
29 | * Service name. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const SERVICE_NAME = "webeweb.core.twig.extension.utility"; |
||
34 | |||
35 | /** |
||
36 | * Calculates an age. |
||
37 | * |
||
38 | * @param DateTime $birthDate The birth date. |
||
39 | * @param DateTime|null $refDate The reference date. |
||
40 | * @return int Returns teh age. |
||
41 | * @throws Exception Throws an exception if an error occurs. |
||
42 | */ |
||
43 | public function calcAge(DateTime $birthDate, DateTime $refDate = null) { |
||
46 | |||
47 | /** |
||
48 | * Format a date/time. |
||
49 | * |
||
50 | * @param DateTime|null $dateTime The date/time. |
||
51 | * @param string $format The format. |
||
52 | * @return string Returns the formatted date/time. |
||
53 | */ |
||
54 | public function formatDate(DateTime $dateTime = null, $format = DateTimeRenderer::DATETIME_FORMAT) { |
||
57 | |||
58 | /** |
||
59 | * Format a string. |
||
60 | * |
||
61 | * @param string $string The string. |
||
62 | * @param string $format The format. |
||
63 | * @return string Returns the formatted string. |
||
64 | */ |
||
65 | public function formatString($string, $format) { |
||
72 | |||
73 | /** |
||
74 | * Get the Twig filters. |
||
75 | * |
||
76 | * @return TwigFilter[] Returns the Twig filters. |
||
77 | */ |
||
78 | public function getFilters() { |
||
95 | |||
96 | /** |
||
97 | * Get the Twig functions. |
||
98 | * |
||
99 | * @return TwigFunction[] Returns the Twig functions. |
||
100 | */ |
||
101 | public function getFunctions() { |
||
118 | |||
119 | /** |
||
120 | * Decodes HTML entities. |
||
121 | * |
||
122 | * @param string $string The string. |
||
123 | * @return string Returns the decoded HTML entities. |
||
124 | */ |
||
125 | public function htmlEntityDecode($string) { |
||
131 | |||
132 | /** |
||
133 | * Encodes HTML entities. |
||
134 | * |
||
135 | * @param string $string The string. |
||
136 | * @return string Returns the encoded HTML entities. |
||
137 | */ |
||
138 | public function htmlEntityEncode($string) { |
||
144 | |||
145 | /** |
||
146 | * MD5. |
||
147 | * |
||
148 | * @param string $string The string. |
||
149 | * @return string Returns the MD5. |
||
150 | */ |
||
151 | public function md5($string) { |
||
157 | } |
||
158 |