*/ trait StyleAttribute { /** * * @var string */ private $style = ''; /** * HTML style attribute of the tag * @return string */ public function style() { return $this->style; } /** * * @return boolean */ public function hasStyle() { return $this->style !== ''; } /** * * @param string $newStyle * @return $this */ public function setStyle($newStyle) { self::checkStyle($newStyle); $this->style = Utils::cleanString($newStyle); return $this; } /** * * @return $this */ public function removeStyle() { $this->style = ''; return $this; } protected function appendStyleAttribute(array & $attributes) { if ($this->hasStyle()) { $attributes['style'] = $this->style; } } public static function checkStyle($style) { if (!self::isCorrectStyle($style)) { throw new AttributeException('Incorrect style value: `' . strval($style) . '`'); } } public static function isCorrectStyle($style) { return is_string($style); } }