[BUGFIX] Deactivate EscapeInterceptor for certain ViewHelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / CountViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * This ViewHelper counts elements of the specified array or countable object.
25 *
26 * = Examples =
27 *
28 * <code title="Count array elements">
29 * <f:count subject="{0:1, 1:2, 2:3, 3:4}" />
30 * </code>
31 * <output>
32 * 4
33 * </output>
34 *
35 * <code title="inline notation">
36 * {objects -> f:count()}
37 * </code>
38 * <output>
39 * 10 (depending on the number of items in {objects})
40 * </output>
41 *
42 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
43 * @api
44 */
45 class Tx_Fluid_ViewHelpers_CountViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
46
47 /**
48 * @var boolean
49 */
50 protected $escapingInterceptorEnabled = FALSE;
51
52 /**
53 * Counts the items of a given property.
54 *
55 * @param array $subject The array or ObjectStorage to iterated over
56 * @return integer The number of elements
57 * @author Jochen Rau <jochen.rau@typoplanet.de>
58 * @author Bastian Waidelich <bastian@typo3.org>
59 * @api
60 */
61 public function render($subject = NULL) {
62 if ($subject === NULL) {
63 $subject = $this->renderChildren();
64 }
65 if (is_object($subject) && !$subject instanceof Countable) {
66 throw new Tx_Fluid_Core_ViewHelper_Exception('CountViewHelper only supports arrays and objects implementing Countable interface. Given: "' . get_class($subject) . '"', 1279808078);
67 }
68 return count($subject);
69 }
70 }
71
72 ?>