You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.4 KiB
PHP

<?php
namespace Artmark\Forms\Attributes;
use Artmark\Forms\Utils;
/**
* Description of StyleAttribute
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
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);
}
}