Skip to content

Commit 26d3e5e

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) - [24: Fix loop validation input context is mutable](zendframework#24) - [25: Fix missing optional fields should not be validated](zendframework#25) - [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework#26) - [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework#31) - [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) - [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 26d3e5e

32 files changed

+2647
-2707
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

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/test export-ignore
22
/vendor export-ignore
3+
.coveralls.yml export-ignore
34
.gitattributes export-ignore
45
.gitignore export-ignore
56
.travis.yml export-ignore
67
.php_cs export-ignore
8+
phpunit.xml.dist export-ignore

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nbproject
99
tmp/
1010

1111
clover.xml
12+
composer.lock
1213
coveralls-upload.json
1314
phpunit.xml
1415
vendor

.php_cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
$finder = Symfony\CS\Finder\DefaultFinder::create()
3+
->in('src')
4+
->in('test')
35
->notPath('TestAsset')
46
->notPath('_files')
57
->filter(function (SplFileInfo $file) {
@@ -28,9 +30,10 @@ $config->fixers(
2830
'multiple_use',
2931
'method_argument_space',
3032
'object_operator',
33+
'ordered_use',
3134
'php_closing_tag',
32-
'psr0',
3335
'remove_lines_between_uses',
36+
'long_array_syntax',
3437
'short_tag',
3538
'standardize_not_equal',
3639
'trailing_spaces',

.travis.yml

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@ sudo: false
22

33
language: php
44

5+
branches:
6+
except:
7+
- /^release-.*$/
8+
- /^ghgfk-.*$/
9+
10+
cache:
11+
directories:
12+
- $HOME/.composer/cache
13+
514
matrix:
615
fast_finish: true
716
include:
17+
- php: 5.3
18+
- php: 5.4
819
- php: 5.5
20+
env:
21+
- EXECUTE_CS_CHECK=true
922
- php: 5.6
1023
env:
1124
- EXECUTE_TEST_COVERALLS=true
12-
- EXECUTE_CS_CHECK=true
1325
- php: 7
14-
- php: hhvm
26+
- php: hhvm
1527
allow_failures:
1628
- php: 7
1729
- php: hhvm
@@ -22,14 +34,16 @@ notifications:
2234

2335
before_install:
2436
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
37+
- composer self-update
38+
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
2539

2640
install:
27-
- composer install --no-interaction --prefer-source
41+
- travis_retry composer install --no-interaction --ignore-platform-reqs
2842

2943
script:
30-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis --coverage-clover clover.xml ; fi
31-
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis ; fi
32-
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run --config-file=.php_cs ; fi
44+
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
45+
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
46+
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
3347

3448
after_script:
3549
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi

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

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# zend-inputfilter
22

3+
[![Build Status](https://secure.travis-ci.org/zendframework/zend-inputfilter.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-inputfilter)
4+
[![Coverage Status](https://coveralls.io/repos/zendframework/zend-inputfilter/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-inputfilter?branch=master)
5+
36
The `Zend\InputFilter` component can be used to filter and validate generic sets
47
of input data. For instance, you could use it to filter `$_GET` or `$_POST`
58
values, CLI arguments, etc.

composer.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
"zf2",
77
"inputfilter"
88
],
9-
"homepage": "https://github.com/zendframework/zend-input-filter",
9+
"homepage": "https://github.com/zendframework/zend-inputfilter",
1010
"autoload": {
1111
"psr-4": {
1212
"Zend\\InputFilter\\": "src/"
1313
}
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.*",
24-
"satooshi/php-coveralls": "dev-master",
25-
"phpunit/PHPUnit": "~4.0"
24+
"phpunit/PHPUnit": "^4.5"
2625
},
2726
"suggest": {
2827
"zendframework/zend-servicemanager": "To support plugin manager support"
2928
},
29+
"minimum-stability": "dev",
30+
"prefer-stable": true,
3031
"extra": {
3132
"branch-alias": {
3233
"dev-master": "2.4-dev",
@@ -38,4 +39,4 @@
3839
"ZendTest\\InputFilter\\": "test/"
3940
}
4041
}
41-
}
42+
}

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
functionality works as expected. Such tests include those for
2929
Zend\Soap and Zend\Session, which require that headers not be sent
3030
in order to work. -->
31-
<const name="TESTS_ZEND_OB_ENABLED" value="false" />
31+
<env name="TESTS_ZEND_OB_ENABLED" value="false" />
3232

3333
</php>
3434
</phpunit>

phpunit.xml.travis

-34
This file was deleted.

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)