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.
71 lines
1.2 KiB
PHP
71 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Artmark\Forms\Attributes;
|
|
|
|
/**
|
|
* Description of MaxLengthAttribute
|
|
*
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
*/
|
|
trait MaxLengthAttribute
|
|
{
|
|
/**
|
|
*
|
|
* @var int
|
|
*/
|
|
private $maxlength = 0;
|
|
|
|
/**
|
|
* HTML site attribute of the input tag
|
|
* @return int
|
|
*/
|
|
public function maxLength()
|
|
{
|
|
return $this->maxlength;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function hasMaxLength()
|
|
{
|
|
return $this->maxlength > 0;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param int $newMaxLength
|
|
* @return $this
|
|
*/
|
|
public function setMaxLength($newMaxLength)
|
|
{
|
|
$this->maxlength = intval($newMaxLength);
|
|
|
|
if ($this->maxlength < 0) {
|
|
$this->maxlength = 0;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function removeMaxLength()
|
|
{
|
|
$this->maxlength = 0;
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function appendMaxLengthAttribute(array & $attributes)
|
|
{
|
|
if ($this->hasMaxLength())
|
|
{
|
|
$attributes['maxlength'] = $this->maxlength;
|
|
}
|
|
}
|
|
}
|