91 $this->checkName(
$name);
97 $parameters = array_change_key_case($parameters);
98 foreach ($this->defaults as $parameter => $default) {
99 $this->$parameter = isset($parameters[strtolower($parameter)]) ? $parameters[strtolower($parameter)] : $default;
114 $this->defaults[
'log'] =
null;
115 $this->defaults[
'class'] =
null;
116 $this->defaults[
'dataAttr'] = [];
117 $this->defaults[
'disabled'] =
false;
132 public function __call($function, $arguments)
134 if (substr($function, 0, 4) ===
'html') {
135 $attribute = str_replace(
'html',
'', $function);
136 $attribute[0] = strtolower($attribute[0]);
138 $escapedAttribute = $attribute .
"Html";
140 if (!empty($this->$escapedAttribute)) {
141 return $this->$escapedAttribute;
146 trigger_error(
"Call to undefined method $function", E_USER_ERROR);
207 if ((isset($parameters)) && (!is_array($parameters))) {
221 private function checkName(
$name)
225 || trim(
$name) ===
''
226 || preg_match(
'/[^a-zA-Z0-9_\-\[\]]/',
$name)
242 protected function log($argument, $type =
null)
244 if (is_callable(array($this->
log,
'log'))) {
245 $this->
log->log($argument, $type);
247 if (gettype($argument) !=
'string') {
250 $message = ob_get_contents();
253 $message = $argument;
269 if (is_string($options)) {
270 $htmlOptions = htmlspecialchars($options, ENT_QUOTES);
271 } elseif (is_array($options)) {
272 $htmlOptions = array();
274 foreach ($options as $index => $option) {
275 if (is_string($index)) $index = htmlspecialchars($index, ENT_QUOTES);
276 if (is_string($option)) $option = htmlspecialchars($option, ENT_QUOTES);
278 $htmlOptions[$index] = $option;
281 $htmlOptions = $options;
293 if (is_array($this->dataAttr)) {
294 foreach ($this->dataAttr as $key => $val) {
296 $attributes .=
" data-$key=\"" . $this->
htmlEscape($val) .
"\"";
$valid
Contains element validation status/result.
setDisabled($disabled=true)
Sets the HTML disabled-attribute of the current input element.
$class
CSS class of the container element.
$defaults
holds default values for element attributes
__construct($name, $parameters, $form)
element class constructor
getName()
Returns the element name.
clearValue()
resets the value to null
htmlDataAttributes()
Returns dataAttr escaped as attribute string.
$disabled
wether a input element will be disabled
__call($function, $arguments)
HTML escaping.
log($argument, $type=null)
error & warning logger
$log
Log object reference.
checkParameters($parameters)
checks element parameters
$validated
True if the element has been validated before.
setDefaults()
Collects initial values across subclasses.
getDisabled()
Gets if input is currently disabled.
$dataAttr
Extra information about the data that is saved inside the element.
htmlEscape($options=array())
Escapes HTML in strings and arrays of strings.
thrown when element parameters aren't of type array on construction
thrown when element name is empty or contains invalid characters
Abstract element classes.