mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 00:24:40 +00:00
MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes. part duex
Although our previous strategy should work according to how bind() and validation() are being implemented (https://github.com/phalcon/cphalcon/blob/4.2.x/phalcon/Validation.zep), in reality it seems they aren't the same. Our previous attempt failed some validations (such as booleans) for no valid reasons. Long term we should remove the phalcon dependency as these effects are highly unpredictable.
This commit is contained in:
parent
e23de4c457
commit
c67ca3fd87
@ -36,6 +36,7 @@ class Validation
|
||||
public function __construct($validators = [])
|
||||
{
|
||||
$this->validators = $validators;
|
||||
$this->phalcon_validation = new \Phalcon\Validation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,10 +59,14 @@ class Validation
|
||||
*/
|
||||
public function add($key, $validator)
|
||||
{
|
||||
if (empty($this->validators[$key])){
|
||||
$this->validators[$key] = [];
|
||||
if (is_a($validator, "OPNsense\Base\BaseValidator")) {
|
||||
if (empty($this->validators[$key])){
|
||||
$this->validators[$key] = [];
|
||||
}
|
||||
$this->validators[$key][] = $validator;
|
||||
} else {
|
||||
$this->phalcon_validation->add($key, $validator);
|
||||
}
|
||||
$this->validators[$key][] = $validator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -73,22 +78,15 @@ class Validation
|
||||
public function validate($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
// XXX: version check
|
||||
$validation = new \Phalcon\Validation();
|
||||
$validation->bind($this, $data);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (!empty($this->validators[$key])) {
|
||||
foreach ($this->validators[$key] as $validator) {
|
||||
if (is_a($validator, "OPNsense\Base\BaseValidator")) {
|
||||
$validator->validate($this, $key);
|
||||
} else {
|
||||
$validator->validate($validation, $key);
|
||||
}
|
||||
$validator->validate($this, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
$phalconMsgs = $validation->getMessages();
|
||||
// XXX: temporary dual validation
|
||||
$phalconMsgs = $this->phalcon_validation->validate($data);
|
||||
if (!empty($phalconMsgs)) {
|
||||
foreach ($phalconMsgs as $phalconMsg) {
|
||||
$this->messages[] = $phalconMsg;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user