classList = $classList; return $this; } /** * Get class list * * @return array */ public function getClassList() { return $this->classList; } /** * Set the font size unit * * Possible values are: em, ex, px, in, cm, mm, pt, pc and % * * @param string $fontSizeUnit * @throws InvalidArgumentException When an invalid fontsize unit is specified * @return HTMLTag */ public function setFontSizeUnit($fontSizeUnit) { if (!in_array($fontSizeUnit, $this->allowedFontSizeUnits)) { throw new InvalidArgumentException('Invalid fontsize unit specified'); } $this->fontSizeUnit = (string) $fontSizeUnit; $this->setClassList(null); return $this; } /** * Retrieve font size unit * * @return string */ public function getFontSizeUnit() { return $this->fontSizeUnit; } /** * Set the HTML tags surrounding the element * * @param array $htmlTags * @return HTMLTag */ public function setHTMLTags(array $htmlTags) { $this->htmlTags = $htmlTags; return $this; } /** * Get HTML tags map * * @return array */ public function getHTMLTags() { return $this->htmlTags; } /** * Set maximum font size * * @param int $maxFontSize * @throws InvalidArgumentException When fontsize is not numeric * @return HTMLTag */ public function setMaxFontSize($maxFontSize) { if (!is_numeric($maxFontSize)) { throw new InvalidArgumentException('Fontsize must be numeric'); } $this->maxFontSize = (int) $maxFontSize; $this->setClassList(null); return $this; } /** * Retrieve maximum font size * * @return int */ public function getMaxFontSize() { return $this->maxFontSize; } /** * Set minimum font size * * @param int $minFontSize * @throws InvalidArgumentException When fontsize is not numeric * @return HTMLTag */ public function setMinFontSize($minFontSize) { if (!is_numeric($minFontSize)) { throw new InvalidArgumentException('Fontsize must be numeric'); } $this->minFontSize = (int) $minFontSize; $this->setClassList(null); return $this; } /** * Retrieve minimum font size * * @return int */ public function getMinFontSize() { return $this->minFontSize; } /** * Defined by Tag * * @param ItemList $tags * @throws InvalidArgumentException * @return array */ public function render($tags) { if (!$tags instanceof ItemList) { throw new InvalidArgumentException(sprintf( 'HtmlTag::render() expects a Zend\Tag\ItemList argument; received "%s"', (is_object($tags) ? get_class($tags) : gettype($tags)) )); } if (null === ($weightValues = $this->getClassList())) { $weightValues = range($this->getMinFontSize(), $this->getMaxFontSize()); } $tags->spreadWeightValues($weightValues); $result = array(); $escaper = $this->getEscaper(); foreach ($tags as $tag) { if (null === ($classList = $this->getClassList())) { $attribute = sprintf('style="font-size: %d%s;"', $tag->getParam('weightValue'), $this->getFontSizeUnit()); } else { $attribute = sprintf('class="%s"', $escaper->escapeHtmlAttr($tag->getParam('weightValue'))); } $tagHTML = sprintf('%s', $escaper->escapeHtml($tag->getParam('url')), $attribute, $escaper->escapeHtml($tag->getTitle())); $tagHTML = $this->wrapTag($tagHTML); $result[] = $tagHTML; } return $result; } }