*/ 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; } } }