1

I am using Zend Standard Validation Classes (http://framework.zend.com/manual/1.12/en/zend.validate.set.html) to validate requests to an api.

You basically specify each request parameter and a set of rules for validating each parameter.

Is it possible to specify that there can be 2 (or more) options when validating a given request, depending on what parameters are in the request?

Like for example if you post:

{
    "a": "someVal", 
    "b": "someVal",
    "c": "someVal",
    "d": "someVal"
}

then a, b, c, and d are required fields, but if you post like this:

{
    "a": "someVal", 
    "e": "someVal",
    "f": "someVal",
    "g": "someVal"
}

then a, e, f and g are required fields?

If you examine the data above you will notice that field "b" is a required field in one POST, but it is an optional field in the other POST.

QUESTION:

How do you specify that a request may be validated in 1 of 2 (or more) ways? How do you specify that a request should be validated based on what parameters are in the request? Is this possible, and how?

Have been stuck on this one for a while so any assistance would be great..

Zend Framework 2.2

4

1 回答 1

1

您可以创建一个策略类,该类可以根据发布的参数选择适合当前请求的输入过滤器。

换句话说,您的请求流程应该是这样的:

Request -> Route -> Controller -> Input Filter Strategy -> InputFilter -> Other Stuff
于 2013-07-08T15:39:38.897 回答