Hoa central
Textarea.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Xyl\Interpreter\Html;
38 
39 use Hoa\Stream;
40 
49 class Textarea extends Generic
50 {
56  protected static $_attributes = [
57  'autocomplete' => parent::ATTRIBUTE_TYPE_NORMAL,
58  'autofocus' => parent::ATTRIBUTE_TYPE_NORMAL,
59  'cols' => parent::ATTRIBUTE_TYPE_NORMAL,
60  'dirname' => parent::ATTRIBUTE_TYPE_NORMAL,
61  'disabled' => parent::ATTRIBUTE_TYPE_NORMAL,
62  'error' => parent::ATTRIBUTE_TYPE_LIST,
63  'form' => parent::ATTRIBUTE_TYPE_NORMAL,
64  'inputmode' => parent::ATTRIBUTE_TYPE_NORMAL,
65  'maxlength' => parent::ATTRIBUTE_TYPE_NORMAL,
66  'name' => parent::ATTRIBUTE_TYPE_NORMAL,
67  'placeholder' => parent::ATTRIBUTE_TYPE_NORMAL,
68  'readonly' => parent::ATTRIBUTE_TYPE_NORMAL,
69  'required' => parent::ATTRIBUTE_TYPE_NORMAL,
70  'rows' => parent::ATTRIBUTE_TYPE_NORMAL,
71  'validate' => parent::ATTRIBUTE_TYPE_CUSTOM,
72  'wrap' => parent::ATTRIBUTE_TYPE_NORMAL
73  ];
74 
80  protected static $_attributesMapping = [
81  'autocomplete',
82  'autofocus',
83  'cols',
84  'dirname',
85  'disabled',
86  'form',
87  'inputmode',
88  'maxlength',
89  'name',
90  'placeholder',
91  'readonly',
92  'required',
93  'rows',
94  'wrap'
95  ];
96 
102  protected $_validity = null;
103 
109  protected $_value = null;
110 
111 
112 
119  protected function paint(Stream\IStream\Out $out)
120  {
121  $name = $this->getName();
122 
123  $out->writeAll('<' . $name . $this->readAttributesAsString() . '>');
124 
125  if (null === $this->_value) {
126  $this->computeValue($out);
127  } else {
128  $out->writeAll($this->_value);
129  }
130 
131  $out->writeAll('</' . $name . '>');
132 
133  return;
134  }
135 
141  public function getForm()
142  {
143  return Form::getMe($this);
144  }
145 
153  public function isValid($revalid = false, $value)
154  {
155  if (false === $revalid && null !== $this->_validity) {
156  return $this->_validity;
157  }
158 
159  $this->_validity = true;
160 
161  if ((null === $value || '' === $value) &&
162  true === $this->attributeExists('required')) {
163  $this->_validity = false;
164 
165  return Form::postValidation($this->_validity, $value, $this);
166  }
167 
168  if (true === $this->attributeExists('maxlength')) {
169  $maxlength = intval($this->readAttribute('maxlength'));
170 
171  if (mb_strlen($value) > $maxlength) {
172  $this->_validity = false;
173 
174  return Form::postValidation($this->_validity, $value, $this);
175  }
176  }
177 
178  if (true === $this->attributeExists('readonly')) {
179  $this->_validity = $value === $this->computeValue();
180 
181  return Form::postValidation($this->_validity, $value, $this);
182  }
183 
184  return Form::postValidation($this->_validity, $value, $this);
185  }
186 
193  public function setValue($value)
194  {
195  $this->_value = $value;
196 
197  return;
198  }
199 }
isValid($revalid=false, $value)
Definition: Textarea.php:153
static getMe(Concrete $element)
Definition: Form.php:592
paint(Stream\IStream\Out $out)
Definition: Textarea.php:119
static postValidation($verdict, &$value, Concrete $element, $postVerification=true)
Definition: Form.php:447