Skip to content

Commit a9daa50

Browse files
committed
Backported 2.5.5 fixes to 2.4 series
Includes these changes: - [14: NotEmpty validator doesn't override the required attribute](zendframework#14) - [16: BC in validators context value](zendframework#16) - [22: Missing required field with fallback does not return input in getValidInput](zendframework#22) - [24: Fix loop validation input context is mutable](zendframework#24) - [25: Fix missing optional fields should not be validated](zendframework#25) - [32: Promote HHVM](zendframework#32) - [36: Fix docblocks declared as regular comment block](zendframework#36) - [40: Remove test about Input setters permutation](zendframework#40) - [41: Refactor tests for group 7448 as a data set matrix](zendframework#41) - [42: Consolidate InputFilterPluginManager tests](zendframework#42) - [43: Consolidate Factory tests + Fixes](zendframework#43) - [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44) - [45: When merge Inputs don't merge values if source does not have one.](zendframework#45) - [46: Expand test matrix with nonempty value scenarios](zendframework#46) - [47: Feature/minor test improvements](zendframework#47) - [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48) - [49: Add tests for exceptions and improve some messages](zendframework#49) - [50: Optional fields without value should be valid ](zendframework#50) - [51: Optional input without value are valid](zendframework#51) - [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52) - [53: Tune NonEmpty options for detect the expected empty values](zendframework#53) - [55: Make symmetric the scenarios when required is true/false](zendframework#55) - [56: Hotfix/minor changes](zendframework#56) - [57: Consolidate tests for InputFilterInterface](zendframework#57) - [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61) - [63: Ensure custom error messages are used for required missing inputs](zendframework#63) - [64: Feature/test cleanup](zendframework#64)
1 parent 3a37474 commit a9daa50

27 files changed

+2587
-2664
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
9+
[**.php]
10+
indent_size = 4
11+
continuation_indent_size = 4
12+
insert_final_newline = true
13+
14+
[**.xml]
15+
indent_size = 4
16+
17+
[**.yml]
18+
indent_size = 2
19+
20+
[composer.json]
21+
indent_size = 4
22+
23+
[package.json]
24+
indent_size = 2

.php_cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $config->fixers(
2828
'multiple_use',
2929
'method_argument_space',
3030
'object_operator',
31+
'ordered_use',
3132
'php_closing_tag',
3233
'psr0',
3334
'remove_lines_between_uses',

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ matrix:
1414
- php: hhvm
1515
allow_failures:
1616
- php: 7
17-
- php: hhvm
1817

1918
notifications:
2019
irc: "irc.freenode.org#zftalk.dev"

CHANGELOG.md

+61
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,67 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.4.8 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Deprecated
12+
13+
- [#26](https://github.com/zendframework/zend-inputfilter/pull/26) Deprecate magic logic for auto attach a NonEmpty
14+
validator with breakChainOnFailure = true. Instead append NonEmpty validator when desired.
15+
16+
```php
17+
$input = new Zend\InputFilter\Input();
18+
$input->setContinueIfEmpty(true);
19+
$input->setAllowEmpty(true);
20+
$input->getValidatorChain()->attach(new Zend\Validator\NotEmpty(), /* break chain on failure */ true);
21+
```
22+
### Removed
23+
24+
- Nothing.
25+
26+
### Fixed
27+
28+
- [#22](https://github.com/zendframework/zend-inputfilter/pull/22) adds tests to
29+
verify two conditions around inputs with fallback values:
30+
- If the input was not in the data set, it should not be represented in either
31+
the list of valid *or* invalid inputs.
32+
- If the input *was* in the data set, but empty, it should be represented in
33+
the list of valid inputs.
34+
- [#31](https://github.com/zendframework/zend-inputfilter/pull/31) updates the
35+
`InputFilterInterface::add()` docblock to match existing, shipped implementations.
36+
- [#25](https://github.com/zendframework/zend-inputfilter/pull/25) Fix missing optional fields to be required.
37+
BC Break since 2.3.9.
38+
For completely fix this you need to setup your inputs as follow.
39+
40+
```php
41+
$input = new Input();
42+
$input->setAllowEmpty(true); // Disable BC Break logic related to treat `null` values as valid empty value instead *not set*.
43+
$input->setContinueIfEmpty(true); // Disable BC Break logic related to treat `null` values as valid empty value instead *not set*.
44+
$input->getValidatorChain()->attach(
45+
new Zend\Validator\NotEmpty(),
46+
true // break chain on failure
47+
);
48+
```
49+
50+
```php
51+
$inputSpecification = array(
52+
'allow_empty' => true,
53+
'continue_if_empty' => true,
54+
'validators' => array(
55+
array(
56+
'break_chain_on_failure' => true,
57+
'name' => 'Zend\\Validator\\NotEmpty',
58+
),
59+
),
60+
);
61+
```
62+
- [Numerous fixes](https://github.com/zendframework/zend-inputfilter/milestones/2.4.8)
63+
aimed at bringing the functionality back to the pre-2.4 code, and improving
64+
quality overall of the component via increased testing and test coverage.
65+
566
## 2.4.7 - 2015-08-11
667

768
### Added

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
},
1515
"require": {
1616
"php": ">=5.3.23",
17-
"zendframework/zend-filter": "self.version",
18-
"zendframework/zend-validator": "self.version",
19-
"zendframework/zend-stdlib": "self.version"
17+
"zendframework/zend-filter": "~2.4.0",
18+
"zendframework/zend-validator": "~2.4.8",
19+
"zendframework/zend-stdlib": "~2.4.0"
2020
},
2121
"require-dev": {
22-
"zendframework/zend-servicemanager": "self.version",
22+
"zendframework/zend-servicemanager": "~2.4.0",
2323
"fabpot/php-cs-fixer": "1.7.*",
2424
"satooshi/php-coveralls": "dev-master",
25-
"phpunit/PHPUnit": "~4.0"
25+
"phpunit/PHPUnit": "^4.5"
2626
},
2727
"suggest": {
2828
"zendframework/zend-servicemanager": "To support plugin manager support"
@@ -38,4 +38,4 @@
3838
"ZendTest\\InputFilter\\": "test/"
3939
}
4040
}
41-
}
41+
}

src/ArrayInput.php

+32-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public function setValue($value)
3131
return parent::setValue($value);
3232
}
3333

34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function resetValue()
38+
{
39+
$this->value = array();
40+
$this->hasValue = false;
41+
return $this;
42+
}
43+
3444
/**
3545
* @return array
3646
*/
@@ -50,6 +60,22 @@ public function getValue()
5060
*/
5161
public function isValid($context = null)
5262
{
63+
$hasValue = $this->hasValue();
64+
$required = $this->isRequired();
65+
$hasFallback = $this->hasFallback();
66+
67+
if (! $hasValue && $hasFallback) {
68+
$this->setValue($this->getFallbackValue());
69+
return true;
70+
}
71+
72+
if (! $hasValue && $required) {
73+
if ($this->errorMessage === null) {
74+
$this->errorMessage = $this->prepareRequiredValidationFailureMessage();
75+
}
76+
return false;
77+
}
78+
5379
if (!$this->continueIfEmpty() && !$this->allowEmpty()) {
5480
$this->injectNotEmptyValidator();
5581
}
@@ -58,15 +84,19 @@ public function isValid($context = null)
5884
$result = true;
5985
foreach ($values as $value) {
6086
$empty = ($value === null || $value === '' || $value === array());
87+
if ($empty && !$this->isRequired() && !$this->continueIfEmpty()) {
88+
$result = true;
89+
continue;
90+
}
6191
if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) {
6292
$result = true;
6393
continue;
6494
}
6595
$result = $validator->isValid($value, $context);
6696
if (!$result) {
67-
if ($this->hasFallback()) {
97+
if ($hasFallback) {
6898
$this->setValue($this->getFallbackValue());
69-
$result = true;
99+
return true;
70100
}
71101
break;
72102
}

0 commit comments

Comments
 (0)