Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / CountViewHelper.php
1 <?php
2
3 /* *
4 * This script is backported from the FLOW3 package "TYPO3.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, either version 3 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * The TYPO3 project - inspiring people to share! *
11 * */
12
13
14 /**
15 * This ViewHelper counts elements of the specified array or countable object.
16 *
17 * = Examples =
18 *
19 * <code title="Count array elements">
20 * <f:count subject="{0:1, 1:2, 2:3, 3:4}" />
21 * </code>
22 * <output>
23 * 4
24 * </output>
25 *
26 * <code title="inline notation">
27 * {objects -> f:count()}
28 * </code>
29 * <output>
30 * 10 (depending on the number of items in {objects})
31 * </output>
32 *
33 * @api
34 */
35 class Tx_Fluid_ViewHelpers_CountViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
36
37 /**
38 * @var boolean
39 */
40 protected $escapingInterceptorEnabled = FALSE;
41
42 /**
43 * Counts the items of a given property.
44 *
45 * @param array $subject The array or ObjectStorage to iterated over
46 * @return integer The number of elements
47 * @api
48 */
49 public function render($subject = NULL) {
50 if ($subject === NULL) {
51 $subject = $this->renderChildren();
52 }
53 if (is_object($subject) && !$subject instanceof Countable) {
54 throw new Tx_Fluid_Core_ViewHelper_Exception('CountViewHelper only supports arrays and objects implementing Countable interface. Given: "' . get_class($subject) . '"', 1279808078);
55 }
56 return count($subject);
57 }
58 }
59
60 ?>