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.

65 lines
1.2 KiB
PHP

<?php
namespace Artmark\Forms\Attributes;
/**
* Description of RequiredAttribute
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
trait RequiredAttribute
{
/**
*
* @var boolean
*/
private $required = false;
/**
* Is the field required
* @return boolean
*/
public function isRequired()
{
return $this->required;
}
/**
* Is the field required
* @return boolean
*/
public function isOptional()
{
return !$this->required;
}
/**
* Помечает поле обязательным для заполнения
* @return $this
*/
public function setRequired()
{
$this->required = true;
return $this;
}
/**
* Помечает поле необязательным для заполнения
* @return $this
*/
public function setOptional()
{
$this->required = false;
return $this;
}
protected function appendRequiredAttribute(array & $attributes)
{
if ($this->required) {
$attributes['required'] = null;
}
}
}