Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending base validation fails. #17631

Open
dereuromark opened this issue Mar 14, 2024 · 2 comments
Open

Extending base validation fails. #17631

dereuromark opened this issue Mar 14, 2024 · 2 comments
Labels
Milestone

Comments

@dereuromark
Copy link
Member

dereuromark commented Mar 14, 2024

Description

It should be possible to use a different (extended) Validation class for all validators
https://book.cakephp.org/5/en/core-libraries/validation.html#adding-validation-providers

As per book in bootstrap:

// replacing core one with app
\Cake\Validation\Validator::addDefaultProvider('default', \App\Validation\Validation::class);

leads to

[TypeError] Cake\Validation\Validation::decimal(): Argument # 3 ($regex) must be of type ?string, array given

But it is just

namespace App\Validation;

use Cake\Validation\Validation as CakeValidation;

class Validation extends CakeValidation {}

CakePHP Version

5.0

PHP Version

8.2

@dereuromark dereuromark added this to the 5.0.7 milestone Mar 14, 2024
@dereuromark
Copy link
Member Author

dereuromark commented Mar 15, 2024

The whole validation thing in Cake is quite buggy, as pointed out earlier ( #12697 ).
It doesn't help that the argument count can vary, and context can be at any position of validation rules, depending on what other arguments are available.

As soon as the validation provider is configured in any way, even core rules fail with the above.

The main reason seems to be that in this case, the 3rd arg is set with this array instead as $context instead of the expected $regex:

[
'newRecord' => false,
'data' => [
    ...
],
'field' => 'weight',
'providers' => [ ],
]

@dereuromark
Copy link
Member Author

My guess would be that because ?string $regexp = null is an optional value, and possibly null here
that it messes up the count when passing them in

if ($this->_pass) {
            $args = array_values(array_merge([$value], $this->_pass, [$context]));
            $result = $callable(...$args);
        } else {
            $result = $callable($value, $context);
        }
if ($this->_pass) {
            $args = array_values(array_merge([$value], $this->_pass, [$context]));
            $result = $callable(...$args);
        } else {
            $result = $callable($value, $context);
        }

@markstory markstory modified the milestones: 5.0.7, 5.0.8 Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants