Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit b65b9a1

Browse files
committed
Merging develop to master for 2.10.0 release
2 parents b44d4de + 6ed3cbd commit b65b9a1

29 files changed

+640
-89
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ branches:
99

1010
cache:
1111
directories:
12-
- $HOME/.composer/cache
12+
- $HOME/.composer/
1313

1414
env:
1515
global:
@@ -50,17 +50,17 @@ matrix:
5050
- php: 7.1
5151
env:
5252
- DEPS=latest
53-
- php: hhvm
53+
- php: nightly
5454
env:
5555
- DEPS=lowest
56-
- php: hhvm
56+
- php: nightly
5757
env:
5858
- DEPS=locked
59-
- php: hhvm
59+
- php: nightly
6060
env:
6161
- DEPS=latest
6262
allow_failures:
63-
- php: hhvm
63+
- php: nightly
6464

6565
before_install:
6666
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
@@ -81,7 +81,7 @@ script:
8181
- if [[ $EXECUTE_HOSTNAME_CHECK == "true" && $TRAVIS_PULL_REQUEST == "false" ]]; then php bin/update_hostname_validator.php --check-only; fi
8282

8383
after_script:
84-
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
84+
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer upload-coverage ; fi
8585

8686
notifications:
8787
email: false

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,61 @@
22

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

5+
## 2.10.0 - TBD
6+
7+
### Added
8+
9+
- [#175](https://github.com/zendframework/zend-validator/pull/175) adds support
10+
for PHP 7.2 (conditionally, as PHP 7.2 is currently in beta1).
11+
12+
- [#157](https://github.com/zendframework/zend-validator/pull/157) adds a new
13+
validator, `IsCountable`, which allows validating:
14+
- if a value is countable
15+
- if a countable value exactly matches a configured count
16+
- if a countable value is greater than a configured minimum count
17+
- if a countable value is less than a configured maximum count
18+
- if a countable value is between configured minimum and maximum counts
19+
20+
### Changed
21+
22+
- [#169](https://github.com/zendframework/zend-validator/pull/169) modifies how
23+
the various `File` validators check for readable files. Previously, they used
24+
`stream_resolve_include_path`, which led to false negative checks when the
25+
files did not exist within an `include_path` (which is often the case within a
26+
web application). These now use `is_readable()` instead.
27+
28+
- [#185](https://github.com/zendframework/zend-validator/pull/185) updates the
29+
zend-session requirement (during development, and in the suggestions) to 2.8+,
30+
to ensure compatibility with the upcoming PHP 7.2 release.
31+
32+
- [#187](https://github.com/zendframework/zend-validator/pull/187) updates the
33+
`Between` validator to **require** that both a `min` and a `max` value are
34+
provided to the constructor, and that both are of the same type (both
35+
integer/float values and/or both string values). This fixes issues that could
36+
previously occur when one or the other was not set, but means an exception
37+
will now be raised during instantiation (versus runtime during `isValid()`).
38+
39+
- [#188](https://github.com/zendframework/zend-validator/pull/188) updates the
40+
`ConfigProvider` to alias the service name `ValidatorManager` to the class
41+
`Zend\Validator\ValidatorPluginManager`, and now maps the the latter class to
42+
the `ValidatorPluginManagerFactory`. Previously, we mapped the service name
43+
directly to the factory. Usage should not change for anybody at this point.
44+
45+
### Deprecated
46+
47+
- Nothing.
48+
49+
### Removed
50+
51+
- [#175](https://github.com/zendframework/zend-validator/pull/175) removes
52+
support for HHVM.
53+
54+
### Fixed
55+
56+
- [#160](https://github.com/zendframework/zend-validator/pull/160) fixes how the
57+
`EmailAddress` validator handles the local part of an address, allowing it to
58+
support unicode.
59+
560
## 2.9.2 - 2017-07-20
661

762
### Added

bin/update_hostname_validator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ function getNewValidTlds($string)
177177
function getPunycodeDecoder()
178178
{
179179
if (function_exists('idn_to_utf8')) {
180-
return 'idn_to_utf8';
180+
return function ($domain) {
181+
return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
182+
};
181183
}
182184

183185
$hostnameValidator = new Hostname();

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"zendframework/zend-i18n": "^2.6",
2727
"zendframework/zend-math": "^2.6",
2828
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
29-
"zendframework/zend-session": "^2.6.2",
29+
"zendframework/zend-session": "^2.8",
3030
"zendframework/zend-uri": "^2.5",
3131
"phpunit/PHPUnit": "^6.0.8 || ^5.7.15",
3232
"zendframework/zend-coding-standard": "~1.0.0"
@@ -38,7 +38,7 @@
3838
"zendframework/zend-math": "Zend\\Math component, required by the Csrf validator",
3939
"zendframework/zend-i18n-resources": "Translations of validator messages",
4040
"zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains",
41-
"zendframework/zend-session": "Zend\\Session component, required by the Csrf validator",
41+
"zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator",
4242
"zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators"
4343
},
4444
"minimum-stability": "dev",

composer.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/book/validators/is-countable.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# IsCountable Validator
2+
3+
- **Since 2.10.0**
4+
5+
`Zend\Validator\IsCountable` allows you to validate that a value can be counted
6+
(i.e., it's an array or implements `Countable`), and, optionally:
7+
8+
- the exact count of the value
9+
- the minimum count of the value
10+
- the maximum count of the value
11+
12+
Specifying either of the latter two is inconsistent with the first, and, as
13+
such, the validator does not allow setting both a count and a minimum or maximum
14+
value. You may, however specify both minimum and maximum values, in which case
15+
the validator operates similar to the [Between validator](between.md).
16+
17+
## Supported options
18+
19+
The following options are supported for `Zend\Validator\IsCountable`:
20+
21+
- `count`: Defines if the validation should look for a specific, exact count for
22+
the value provided.
23+
- `max`: Sets the maximum value for the validation; if the count of the value is
24+
greater than the maximum, validation fails..
25+
- `min`: Sets the minimum value for the validation; if the count of the value is
26+
lower than the minimum, validation fails.
27+
28+
## Default behaviour
29+
30+
Given no options, the validator simply tests to see that the value may be
31+
counted (i.e., it's an array or `Countable` instance):
32+
33+
```php
34+
$validator = new Zend\Validator\IsCountable();
35+
36+
$validator->isValid(10); // false; not an array or Countable
37+
$validator->isValid([10]); // true; value is an array
38+
$validator->isValid(new ArrayObject([10])); // true; value is Countable
39+
$validator->isValid(new stdClass); // false; value is not Countable
40+
```
41+
42+
## Specifying an exact count
43+
44+
You can also specify an exact count; if the value is countable, and its count
45+
matches, the the value is valid.
46+
47+
```php
48+
$validator = new Zend\Validator\IsCountable(['count' => 3]);
49+
50+
$validator->isValid([1, 2, 3]); // true; countable, and count is 3
51+
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
52+
$validator->isValid([1]); // false; countable, but count is 1
53+
$validator->isValid(new ArrayObject([1])); // false; countable, but count is 1
54+
```
55+
56+
## Specifying a minimum count
57+
58+
You may specify a minimum count. When you do, the value must be countable, and
59+
greater than or equal to the minimum count you specify in order to be valid.
60+
61+
```php
62+
$validator = new Zend\Validator\IsCountable(['min' => 2]);
63+
64+
$validator->isValid([1, 2, 3]); // true; countable, and count is 3
65+
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
66+
$validator->isValid([1, 2]); // true; countable, and count is 2
67+
$validator->isValid(new ArrayObject([1, 2])); // true; countable, and count is 2
68+
$validator->isValid([1]); // false; countable, but count is 1
69+
$validator->isValid(new ArrayObject([1])); // false; countable, but count is 1
70+
```
71+
72+
## Specifying a maximum count
73+
74+
You may specify a maximum count. When you do, the value must be countable, and
75+
less than or equal to the maximum count you specify in order to be valid.
76+
77+
```php
78+
$validator = new Zend\Validator\IsCountable(['max' => 2]);
79+
80+
$validator->isValid([1, 2, 3]); // false; countable, but count is 3
81+
$validator->isValid(new ArrayObject([1, 2, 3])); // false; countable, but count is 3
82+
$validator->isValid([1, 2]); // true; countable, and count is 2
83+
$validator->isValid(new ArrayObject([1, 2])); // true; countable, and count is 2
84+
$validator->isValid([1]); // true; countable, and count is 1
85+
$validator->isValid(new ArrayObject([1])); // true; countable, and count is 1
86+
```
87+
88+
## Specifying both minimum and maximum
89+
90+
If you specify both a minimum and maximum, the count must be _between_ the two,
91+
inclusively (i.e., it may be the minimum or maximum, and any value between).
92+
93+
```php
94+
$validator = new Zend\Validator\IsCountable([
95+
'min' => 3,
96+
'max' => 5,
97+
]);
98+
99+
$validator->isValid([1, 2, 3]); // true; countable, and count is 3
100+
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
101+
$validator->isValid(range(1, 5)); // true; countable, and count is 5
102+
$validator->isValid(new ArrayObject(range(1, 5))); // true; countable, and count is 5
103+
$validator->isValid([1, 2]); // false; countable, and count is 2
104+
$validator->isValid(new ArrayObject([1, 2])); // false; countable, and count is 2
105+
$validator->isValid(range(1, 6)); // false; countable, and count is 6
106+
$validator->isValid(new ArrayObject(range(1, 6))); // false; countable, and count is 6
107+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pages:
2525
- InArray: validators/in-array.md
2626
- Ip: validators/ip.md
2727
- Isbn: validators/isbn.md
28+
- IsCountable: validators/is-countable.md
2829
- IsInstanceOf: validators/isinstanceof.md
2930
- LessThan: validators/less-than.md
3031
- NotEmpty: validators/not-empty.md

src/Between.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ public function __construct($options = null)
9090
$options = $temp;
9191
}
9292

93-
if (count($options) !== 2
94-
&& (! array_key_exists('min', $options) || ! array_key_exists('max', $options))
95-
) {
93+
if (! array_key_exists('min', $options) || ! array_key_exists('max', $options)) {
9694
throw new Exception\InvalidArgumentException("Missing option: 'min' and 'max' have to be given");
9795
}
9896

99-
if (is_numeric($options['min']) && is_numeric($options['max'])) {
97+
if ((isset($options['min']) && is_numeric($options['min']))
98+
&& (isset($options['max']) && is_numeric($options['max']))
99+
) {
100100
$this->numeric = true;
101-
} elseif (is_string($options['min']) && is_string($options['max'])) {
101+
} elseif ((isset($options['min']) && is_string($options['min']))
102+
&& (isset($options['max']) && is_string($options['max']))
103+
) {
102104
$this->numeric = false;
103105
} else {
104106
throw new Exception\InvalidArgumentException(

src/ConfigProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ public function __invoke()
2929
public function getDependencyConfig()
3030
{
3131
return [
32+
'aliases' => [
33+
'ValidatorManager' => ValidatorPluginManager::class,
34+
],
3235
'factories' => [
33-
'ValidatorManager' => ValidatorPluginManagerFactory::class,
36+
ValidatorPluginManager::class => ValidatorPluginManagerFactory::class,
3437
],
3538
];
3639
}

0 commit comments

Comments
 (0)