escaper = $escaper ?: new Escaper(); } /** * Generates a 'List' element. * * @param array $items Array with the elements of the list * @param bool $ordered Specifies ordered/unordered list; default unordered * @param AttributeSet|null $attribs Attributes for the ol/ul tag. * @param bool $escape Whether to Escape the items. * @throws Exception\InvalidArgumentException If $items is empty. * @return string The list XHTML. */ public function __invoke(array $items, $ordered = false, $attribs = null, $escape = true) { if (empty($items)) { throw new Exception\InvalidArgumentException(sprintf( '$items array can not be empty in %s', __METHOD__ )); } $list = ''; foreach ($items as $item) { if (! is_array($item)) { $markup = $escape ? $this->escaper->escapeHtml((string) $item) : (string) $item; $list .= '
  • ' . $markup . '
  • ' . PHP_EOL; } else { /** @psalm-var list> $item */ $itemLength = strlen('' . PHP_EOL); if ($itemLength < strlen($list)) { $list = substr($list, 0, strlen($list) - $itemLength) . $this->__invoke($item, $ordered, $attribs, $escape) . '' . PHP_EOL; } else { $list .= '
  • ' . $this->__invoke($item, $ordered, $attribs, $escape) . '
  • ' . PHP_EOL; } } } $attributes = is_array($attribs) ? (string) new HtmlAttributesSet($this->escaper, $attribs) : ''; $tag = $ordered ? 'ol' : 'ul'; return '<' . $tag . $attributes . '>' . PHP_EOL . $list . '' . PHP_EOL; } }