1 | <?php |
||
27 | class UtilityTwigExtension extends AbstractTwigExtension { |
||
28 | |||
29 | /** |
||
30 | * Service name. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | const SERVICE_NAME = "webeweb.core.twig.extension.utility"; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | * |
||
39 | * @param Twig_Environment $twigEnvironment The wig environment. |
||
40 | */ |
||
41 | public function __construct(Twig_Environment $twigEnvironment) { |
||
44 | |||
45 | /** |
||
46 | * Calculates an age. |
||
47 | * |
||
48 | * @param DateTime $birthDate The birth date. |
||
49 | * @param DateTime|null $refDate The reference date. |
||
50 | * @return int Returns teh age. |
||
51 | * @throws Exception Throws an exception if an error occurs. |
||
52 | */ |
||
53 | public function calcAge(DateTime $birthDate, DateTime $refDate = null) { |
||
56 | |||
57 | /** |
||
58 | * Format a date/time. |
||
59 | * |
||
60 | * @param DateTime|null $dateTime The date/time. |
||
61 | * @param string $format The format. |
||
62 | * @return string Returns the formatted date/time. |
||
63 | */ |
||
64 | public function formatDate(DateTime $dateTime = null, $format = DateTimeRenderer::DATETIME_FORMAT) { |
||
67 | |||
68 | /** |
||
69 | * Get the Twig filters. |
||
70 | * |
||
71 | * @return Twig_SimpleFilter[] Returns the Twig filters. |
||
72 | */ |
||
73 | public function getFilters() { |
||
82 | |||
83 | /** |
||
84 | * Get the Twig functions. |
||
85 | * |
||
86 | * @return array Returns the Twig functions. |
||
87 | */ |
||
88 | public function getFunctions() { |
||
97 | |||
98 | /** |
||
99 | * Decodes HTML entities. |
||
100 | * |
||
101 | * @param string $string The string. |
||
102 | * @return string Returns the decoded HTML entities. |
||
103 | */ |
||
104 | public function htmlEntityDecode($string) { |
||
110 | |||
111 | /** |
||
112 | * Encodes HTML entities. |
||
113 | * |
||
114 | * @param string $string The string. |
||
115 | * @return string Returns the encoded HTML entities. |
||
116 | */ |
||
117 | public function htmlEntityEncode($string) { |
||
123 | |||
124 | /** |
||
125 | * MD5. |
||
126 | * |
||
127 | * @param string $string The string. |
||
128 | * @return string Returns the MD5. |
||
129 | */ |
||
130 | public function md5($string) { |
||
136 | } |
||
137 |