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
83 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Artmark\Forms\Attributes;
|
|
|
|
/**
|
|
* Description of ActionAttribute
|
|
*
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
*/
|
|
trait ActionAttribute
|
|
{
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
private $action = '';
|
|
|
|
/**
|
|
* HTML action attribute of the tag
|
|
* @return string
|
|
*/
|
|
public function action()
|
|
{
|
|
return $this->action;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function hasAction()
|
|
{
|
|
return $this->action !== '';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $newAction
|
|
* @return $this
|
|
*/
|
|
public function setAction($newAction)
|
|
{
|
|
self::checkAction($newAction);
|
|
|
|
$this->action = trim($newAction);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function removeAction()
|
|
{
|
|
$this->action = '';
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function appendActionAttribute(array & $attributes)
|
|
{
|
|
if ($this->hasAction())
|
|
{
|
|
$attributes['action'] = $this->action;
|
|
}
|
|
|
|
return $attributes;
|
|
}
|
|
|
|
public static function checkAction($action)
|
|
{
|
|
if (!self::isCorrectAction($action)) {
|
|
throw new AttributeException('Incorrect action value: `' . strval($action) . '`');
|
|
}
|
|
}
|
|
|
|
public static function isCorrectAction($action)
|
|
{
|
|
return is_string($action);
|
|
}
|
|
}
|