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.
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Artmark\Forms;
|
|
|
|
use Artmark\Forms\Attributes\SizeAttribute;
|
|
use Artmark\Forms\Attributes\MaxLengthAttribute;
|
|
|
|
/**
|
|
* Description of AbstractTextField
|
|
*
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
*/
|
|
abstract class AbstractTextField extends AbstractVisibleField
|
|
{
|
|
use SizeAttribute, MaxLengthAttribute;
|
|
|
|
private $value = '';
|
|
|
|
protected function __construct($form, $type, $name, $value = '')
|
|
{
|
|
parent::__construct($form, $type, $name);
|
|
|
|
$this->setValue($value);
|
|
}
|
|
|
|
/**
|
|
* Возвращает значение поля
|
|
* @return string
|
|
*/
|
|
public function value()
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
/**
|
|
* Задаёт новое значение для текстового поля
|
|
* @param string|int|float $newValue
|
|
* @return $this
|
|
*/
|
|
public function setValue($newValue)
|
|
{
|
|
if (is_string($newValue) || is_numeric($newValue)) {
|
|
$this->value = strval($newValue);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Ассоциативный массив аттрибутов текстового поля
|
|
* @return array
|
|
*/
|
|
public function getAssociativeAttributes()
|
|
{
|
|
$attributes = parent::getAssociativeAttributes();
|
|
|
|
$this->appendSizeAttribute($attributes);
|
|
|
|
$this->appendMaxLengthAttribute($attributes);
|
|
|
|
$attributes['value'] = $this->value;
|
|
|
|
return $attributes;
|
|
}
|
|
}
|