DavidePastore / Slim-Validation

A validation library for the Slim Framework. It internally uses Respect/Validation.
170 stars 30 forks source link

Use Key with Route Params #46

Open miquellaboria opened 5 years ago

miquellaboria commented 5 years ago

How can I use Key with Route Params:

$app->delete('/group/{groupId}/access/{userId}', '\App\Controller\Group:removeUser') ->add(new \App\Lib\Validation(array( v::oneOf( v::key('groupId',v::IsPublicationOwner($container)), v::key('userId', v::ItsMe($container)) ) )));

Returns:

At least one of these rules must pass for null Key groupId must be present Key userId must be present

DavidePastore commented 5 years ago

Hi @miquellaboria . What are you trying to do here? Do you want validation for both or only one of them?

miquellaboria commented 5 years ago

Hi @DavidePastore I want to validate at least one of them.

Thanks!

DavidePastore commented 5 years ago

@miquellaboria This is a nice use case. Can you please check if #40 fixes it and make it works as expected?

miquellaboria commented 5 years ago

@DavidePastore I have the same validation error: At least one of these rules must pass for null\nKey groupId must be present\nKey userId must be present

Key are not found :(

alissonbezerra commented 5 years ago

Hi, this #40 worked here. Here's my code:

$app->get('/cliente', ClienteController::class . ':listarClientes')->add(new \DavidePastore\Slim\Validation\Validation( v::oneOf( v::key('test', v::notBlank()), v::key('test2', v::notBlank()) ) ));

DavidePastore commented 5 years ago

@miquellaboria I expected that it worked as @alissonbezerra said. Let's investigate it. What is the definition of \App\Lib\Validation?