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

Add a collection rule to validate collection data #28

Closed
elie29 opened this issue Dec 5, 2019 · 0 comments
Closed

Add a collection rule to validate collection data #28

elie29 opened this issue Dec 5, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@elie29
Copy link
Owner

elie29 commented Dec 5, 2019

In order to validate a collection of data, it would be helpful to have a CollectionRule that accepts a list of rules as follow:

       $rules = [
            ['email', EmailRule::class, EmailRule::REQUIRED => true],
            ['tags', CollectionRule::class, CollectionRule::RULES => [
                ['code', NumericRule::class, NumericRule::MAX => 80],
                ['slug', MatchRule::class, MatchRule::PATTERN => '/^[a-z]{1,5}$/i'],
            ]],
        ];

        $data = [
            'email' => 'elie29@gmail.com',
            'tags' => [
                ['code' => 12, 'slug' => 'one'],
                ['code' => 13, 'slug' => 'two'],
                ['code' => 15, 'slug' => 'three'],
            ],
        ];

        $validator = new Validator($data, $rules);

        assertThat($validator->validate(), is(true));

        $tags = $validator->getValidatedContext()['tags'];

        assertThat($tags, arrayWithSize(3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant