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.
81 lines
1.4 KiB
PHP
81 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Artmark\Forms\Attributes;
|
|
|
|
/**
|
|
* Description of TargetAttribute
|
|
*
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
*/
|
|
trait TargetAttribute
|
|
{
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
private $target = '';
|
|
|
|
/**
|
|
* HTML target attribute of the tag
|
|
* @return string
|
|
*/
|
|
public function target()
|
|
{
|
|
return $this->target;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function hasTarget()
|
|
{
|
|
return $this->target !== '';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $newTarget
|
|
* @return $this
|
|
*/
|
|
public function setTarget($newTarget)
|
|
{
|
|
self::checkTarget($newTarget);
|
|
|
|
$this->target = trim($newTarget);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function removeTarget()
|
|
{
|
|
$this->target = '';
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function appendTargetAttribute(array & $attributes)
|
|
{
|
|
if ($this->hasTarget())
|
|
{
|
|
$attributes['target'] = $this->target;
|
|
}
|
|
}
|
|
|
|
public static function checkTarget($target)
|
|
{
|
|
if (!self::isCorrectTarget($target)) {
|
|
throw new AttributeException('Incorrect target value: `' . strval($target) . '`');
|
|
}
|
|
}
|
|
|
|
public static function isCorrectTarget($target)
|
|
{
|
|
return is_string($target);
|
|
}
|
|
}
|