3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\View\Helper
;
13 * Helper for ordered and unordered lists
15 class HtmlList
extends AbstractHtmlElement
18 * Generates a 'List' element.
20 * @param array $items Array with the elements of the list
21 * @param bool $ordered Specifies ordered/unordered list; default unordered
22 * @param array $attribs Attributes for the ol/ul tag.
23 * @param bool $escape Escape the items.
24 * @return string The list XHTML.
26 public function __invoke(array $items, $ordered = false, $attribs = false, $escape = true)
30 foreach ($items as $item) {
31 if (!is_array($item)) {
33 $escaper = $this->getView()->plugin('escapeHtml');
34 $item = $escaper($item);
36 $list .= '<li>' . $item . '</li>' . self
::EOL
;
38 $itemLength = 5 +
strlen(self
::EOL
);
39 if ($itemLength < strlen($list)) {
40 $list = substr($list, 0, strlen($list) - $itemLength)
41 . $this($item, $ordered, $attribs, $escape) . '</li>' . self
::EOL
;
43 $list .= '<li>' . $this($item, $ordered, $attribs, $escape) . '</li>' . self
::EOL
;
49 $attribs = $this->htmlAttribs($attribs);
54 $tag = ($ordered) ?
'ol' : 'ul';
56 return '<' . $tag . $attribs . '>' . self
::EOL
. $list . '</' . $tag . '>' . self
::EOL
;