|
@ -11,8 +11,14 @@ |
|
|
|
|
|
|
|
|
class FormField |
|
|
class FormField |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var iValidator[] |
|
|
|
|
|
*/ |
|
|
protected $validators = array(); |
|
|
protected $validators = array(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var iFilter[] |
|
|
|
|
|
*/ |
|
|
protected $filters = array(); |
|
|
protected $filters = array(); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -21,41 +27,77 @@ class FormField |
|
|
* @var string |
|
|
* @var string |
|
|
*/ |
|
|
*/ |
|
|
protected $default_message = false; |
|
|
protected $default_message = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
protected $message = false; |
|
|
protected $message = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var mixed |
|
|
|
|
|
*/ |
|
|
protected $value; |
|
|
protected $value; |
|
|
|
|
|
|
|
|
/* Flags */ |
|
|
/* Flags */ |
|
|
|
|
|
/** |
|
|
|
|
|
* @var bool |
|
|
|
|
|
*/ |
|
|
protected $required = true; |
|
|
protected $required = true; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var bool |
|
|
|
|
|
*/ |
|
|
protected $ignored = false; |
|
|
protected $ignored = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param bool|string $default_message |
|
|
|
|
|
*/ |
|
|
public function __construct($default_message = false) |
|
|
public function __construct($default_message = false) |
|
|
{ |
|
|
{ |
|
|
$this->default_message = $default_message; |
|
|
$this->default_message = $default_message; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param bool $flag |
|
|
|
|
|
* @return FormField |
|
|
|
|
|
*/ |
|
|
public function setRequired($flag) |
|
|
public function setRequired($flag) |
|
|
{ |
|
|
{ |
|
|
$this->required = (bool) $flag; |
|
|
$this->required = (bool) $flag; |
|
|
return $this; |
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @return bool |
|
|
|
|
|
*/ |
|
|
public function isRequired() |
|
|
public function isRequired() |
|
|
{ |
|
|
{ |
|
|
return $this->required; |
|
|
return $this->required; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param bool $flag |
|
|
|
|
|
* @return FormField |
|
|
|
|
|
*/ |
|
|
public function setIgnored($flag) |
|
|
public function setIgnored($flag) |
|
|
{ |
|
|
{ |
|
|
$this->ignored = (bool) $flag; |
|
|
$this->ignored = (bool) $flag; |
|
|
return $this; |
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @return bool |
|
|
|
|
|
*/ |
|
|
public function isIgnored() |
|
|
public function isIgnored() |
|
|
{ |
|
|
{ |
|
|
return $this->ignored; |
|
|
return $this->ignored; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param string[]|iValidator[] $validators |
|
|
|
|
|
* @return FormField |
|
|
|
|
|
*/ |
|
|
public function addValidators($validators) |
|
|
public function addValidators($validators) |
|
|
{ |
|
|
{ |
|
|
foreach ($validators as $validator) { |
|
|
foreach ($validators as $validator) { |
|
@ -64,6 +106,11 @@ class FormField |
|
|
return $this; |
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param string|iValidator $validator |
|
|
|
|
|
* @return FormField |
|
|
|
|
|
* @throws InitializationException |
|
|
|
|
|
*/ |
|
|
public function addValidator($validator) |
|
|
public function addValidator($validator) |
|
|
{ |
|
|
{ |
|
|
if ($validator instanceof iValidator) { |
|
|
if ($validator instanceof iValidator) { |
|
@ -88,7 +135,7 @@ class FormField |
|
|
|
|
|
|
|
|
public function addFilter($filter) |
|
|
public function addFilter($filter) |
|
|
{ |
|
|
{ |
|
|
if ($filter instanceof iFilter) { |
|
|
|
|
|
|
|
|
if ($filter instanceof iFilter) { |
|
|
$name = get_class($filter); |
|
|
$name = get_class($filter); |
|
|
} elseif (is_string($filter)) { |
|
|
} elseif (is_string($filter)) { |
|
|
$name = $filter . 'Filter'; |
|
|
$name = $filter . 'Filter'; |
|
|