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

Already on GitHub? Sign in to your account

Validate empty with context #4165

Merged
merged 8 commits into from Apr 12, 2013

Conversation

Projects
None yet
4 participants
Contributor

zburnham commented Apr 2, 2013

Trying this again, I messed up a rebase.

Currently there is no way for Zend\InputFilter to determine the validity of an empty field based on context; for example, an empty field might be valid if another field is 'Y', but not valid if that other field is 'N'. This adds a continueIfEmpty flag to the Input definition, via a separate interface.

zburnham added some commits Mar 15, 2013

@zburnham zburnham Adding code to allow for input validation to continue if value is emp…
…ty instead of just being marked as valid if empty. Required to test for validity of an empty value based on context.
92531c9
@zburnham zburnham Tests for added Continue If empty functionality. 616dfb6
@zburnham zburnham Adding code to allow for input validation to continue if value is emp…
…ty instead of just being marked as valid if empty. Required to test for validity of an empty value based on context.
ffd1c93
@zburnham zburnham Tests for added Continue If empty functionality. 288dc75
@zburnham zburnham Splitting 'continue if empty' functionality into its own interface. F…
…ixing a failing unit test; test was not providing data for a required input.
272eecf
@zburnham zburnham Catching up with remote differences. 3f9aaca

Should not you add 'zomg' in the array ?

You're quite correct, good catch.

@ghost ghost assigned weierophinney Apr 12, 2013

@weierophinney weierophinney added a commit that referenced this pull request Apr 12, 2013

@weierophinney weierophinney Merge pull request #4165 from zburnham/validate_empty_with_context
Validate empty with context

Conflicts:
	library/Zend/InputFilter/Factory.php
570c07b

@weierophinney weierophinney added a commit that referenced this pull request Apr 12, 2013

@weierophinney weierophinney [#4165] CS fixes
- per php-cs-fixer
a415f67

@weierophinney weierophinney merged commit 1ba74d2 into zendframework:develop Apr 12, 2013

Owner

weierophinney commented Apr 12, 2013

Merged, and will release with 2.2.0. Thanks, Zach!

Contributor

zburnham commented Apr 12, 2013

Excellent. I promise that I'll update the documentation, really I will.

@weierophinney weierophinney added a commit that referenced this pull request Apr 12, 2013

@weierophinney weierophinney [#4165] Remove duplicate methods from InputInterface
- `InputInterface` had a BC break, as it added `setContinueIfEmpty()` and
  `continueIfEmpty()` -- which were technically already defined in
  `EmptyContextInterface`, which `Input` had been modified to implement.
  Removing the methods from `InputInterface` removes the BC break, and fixes an
  issue that appears in 5.3.3 with one class implementing two interfaces that
  define compatible methods.
3247de8

@danizord danizord commented on the diff May 4, 2013

library/Zend/InputFilter/BaseInputFilter.php
@@ -187,8 +187,10 @@ protected function validateInputs(array $inputs)
&& $input->isRequired()
&& $input->allowEmpty()
) {
- $this->validInputs[$name] = $input;
- continue;
+ if (!$input->allowEmpty()) {
@danizord

danizord May 4, 2013

Contributor

@zburnham Should this be if (!$input->continueIfEmpty()) {?

@zburnham

zburnham May 4, 2013

Contributor

Well, MWOP seemed to think it was ok, but I'll definitely take a look, more
eyes on the code and all that.

Z

On May 4, 2013, at 6:24 PM, Daniel Gimenes notifications@github.com wrote:

In library/Zend/InputFilter/BaseInputFilter.php:

@@ -187,8 +187,10 @@ protected function validateInputs(array $inputs)
&& $input->isRequired()
&& $input->allowEmpty()
) {

  •            $this->validInputs[$name] = $input;
    
  •            continue;
    
  •            if (!$input->allowEmpty()) {
    

@zburnham https://github.com/zburnham Should this be if
(!$input->continueIfEmpty()) {?


Reply to this email directly or view it on
GitHubhttps://github.com/zendframework/zf2/pull/4165/files#r4085890
.

@danizord

danizord May 4, 2013

Contributor

See line 188.

Contributor

danizord commented May 4, 2013

@zburnham You have not fulfilled your promise yet. 😄

Contributor

zburnham commented May 4, 2013

I know :/ I'm going to be looking at it tonight anyway.

On May 4, 2013, at 6:41 PM, Daniel Gimenes notifications@github.com wrote:

@zburnham https://github.com/zburnham You have not fulfilled your promise
yet. [image: 😄]


Reply to this email directly or view it on
GitHubhttps://github.com/zendframework/zf2/pull/4165#issuecomment-17442654
.

Contributor

danizord commented May 6, 2013

@zburnham Sorry if I'm wrong, but on second thought, this is useless since you can simply setAllowEmpty(false) and get the same result.

Contributor

zburnham commented May 6, 2013

It stood a little tweaking, anyway.

On Mon, May 6, 2013 at 8:40 AM, Daniel Gimenes notifications@github.comwrote:

@zburnham https://github.com/zburnham Sorry if I'm wrong, but on second
thought, this is useless since you can simply setAllowEmpty(false) and get
the same result.


Reply to this email directly or view it on GitHubhttps://github.com/zendframework/zf2/pull/4165#issuecomment-17479371
.

Contributor

danizord commented May 6, 2013

@weierophinney Can you please review this before release RC2?

Owner

weierophinney commented May 6, 2013

@danizord Already did. :)

Contributor

danizord commented May 6, 2013

@weierophinney It seems reasonable? As said setAllowEmpty(false) does the same thing.

Owner

weierophinney commented May 6, 2013

@danizord they're in different contexts. allowEmpty() works for individual input objects, but the EmptyContextInterface allows looking at empty in relation to the context of the input (i.e., the other inputs), as well as input filters.

So, it does seem reasonable to me; it provides more validation options, basically.

Contributor

danizord commented May 6, 2013

@weierophinney

allows looking at empty in relation to the context of the input (i.e., the other inputs), as well as input filters.

setAllowEmpty(false) also.

I don't want to be against you, but this is going to be complicated. Now we have:

  • setRequired()
  • setAllowEmpty()
  • setContinueIfEmpty()

It is impossible to understand without looking at the code of the component. Since the documentation does not cover it all.

Contributor

zburnham commented May 6, 2013

The documentation is something I'm going to try to fix over the next few
days. The docs for InputFilter are pretty cursory.

On Mon, May 6, 2013 at 1:02 PM, Daniel Gimenes notifications@github.comwrote:

@weierophinney https://github.com/weierophinney

allows looking at empty in relation to the context of the input (i.e., the
other inputs), as well as input filters.

setAllowEmpty(false) also.

I don't want to be against you, but this is going to be complicated. Now
we have:

  • setRequired()
  • setAllowEmpty()
  • setContinueIfEmpty()

It is impossible to understand without looking at the code of the
component. Since the documentation does not cover it all.


Reply to this email directly or view it on GitHubhttps://github.com/zendframework/zf2/pull/4165#issuecomment-17493928
.

@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge pull request zendframework/zendframework#4165 from zburnham/val…
…idate_empty_with_context

Validate empty with context

Conflicts:
	library/Zend/InputFilter/Factory.php
d3644c9

@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015

@weierophinney weierophinney [zendframework/zendframework#4165] CS fixes
- per php-cs-fixer
7f3bb0e

@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge branch 'feature/4165' into develop 4cc8b20

@weierophinney weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015

@weierophinney weierophinney [zendframework/zendframework#4165] Remove duplicate methods from Inpu…
…tInterface

- `InputInterface` had a BC break, as it added `setContinueIfEmpty()` and
  `continueIfEmpty()` -- which were technically already defined in
  `EmptyContextInterface`, which `Input` had been modified to implement.
  Removing the methods from `InputInterface` removes the BC break, and fixes an
  issue that appears in 5.3.3 with one class implementing two interfaces that
  define compatible methods.
bc17b68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment