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