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

Commit

Permalink
Merging develop to master for 2.10.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 14, 2017
2 parents b44d4de + 6ed3cbd commit b65b9a1
Show file tree
Hide file tree
Showing 29 changed files with 640 additions and 89 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ branches:

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/

env:
global:
Expand Down Expand Up @@ -50,17 +50,17 @@ matrix:
- php: 7.1
env:
- DEPS=latest
- php: hhvm
- php: nightly
env:
- DEPS=lowest
- php: hhvm
- php: nightly
env:
- DEPS=locked
- php: hhvm
- php: nightly
env:
- DEPS=latest
allow_failures:
- php: hhvm
- php: nightly

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

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

notifications:
email: false
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@

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

## 2.10.0 - TBD

### Added

- [#175](https://github.com/zendframework/zend-validator/pull/175) adds support
for PHP 7.2 (conditionally, as PHP 7.2 is currently in beta1).

- [#157](https://github.com/zendframework/zend-validator/pull/157) adds a new
validator, `IsCountable`, which allows validating:
- if a value is countable
- if a countable value exactly matches a configured count
- if a countable value is greater than a configured minimum count
- if a countable value is less than a configured maximum count
- if a countable value is between configured minimum and maximum counts

### Changed

- [#169](https://github.com/zendframework/zend-validator/pull/169) modifies how
the various `File` validators check for readable files. Previously, they used
`stream_resolve_include_path`, which led to false negative checks when the
files did not exist within an `include_path` (which is often the case within a
web application). These now use `is_readable()` instead.

- [#185](https://github.com/zendframework/zend-validator/pull/185) updates the
zend-session requirement (during development, and in the suggestions) to 2.8+,
to ensure compatibility with the upcoming PHP 7.2 release.

- [#187](https://github.com/zendframework/zend-validator/pull/187) updates the
`Between` validator to **require** that both a `min` and a `max` value are
provided to the constructor, and that both are of the same type (both
integer/float values and/or both string values). This fixes issues that could
previously occur when one or the other was not set, but means an exception
will now be raised during instantiation (versus runtime during `isValid()`).

- [#188](https://github.com/zendframework/zend-validator/pull/188) updates the
`ConfigProvider` to alias the service name `ValidatorManager` to the class
`Zend\Validator\ValidatorPluginManager`, and now maps the the latter class to
the `ValidatorPluginManagerFactory`. Previously, we mapped the service name
directly to the factory. Usage should not change for anybody at this point.

### Deprecated

- Nothing.

### Removed

- [#175](https://github.com/zendframework/zend-validator/pull/175) removes
support for HHVM.

### Fixed

- [#160](https://github.com/zendframework/zend-validator/pull/160) fixes how the
`EmailAddress` validator handles the local part of an address, allowing it to
support unicode.

## 2.9.2 - 2017-07-20

### Added
Expand Down
4 changes: 3 additions & 1 deletion bin/update_hostname_validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ function getNewValidTlds($string)
function getPunycodeDecoder()
{
if (function_exists('idn_to_utf8')) {
return 'idn_to_utf8';
return function ($domain) {
return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
};
}

$hostnameValidator = new Hostname();
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"zendframework/zend-i18n": "^2.6",
"zendframework/zend-math": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-session": "^2.6.2",
"zendframework/zend-session": "^2.8",
"zendframework/zend-uri": "^2.5",
"phpunit/PHPUnit": "^6.0.8 || ^5.7.15",
"zendframework/zend-coding-standard": "~1.0.0"
Expand All @@ -38,7 +38,7 @@
"zendframework/zend-math": "Zend\\Math component, required by the Csrf validator",
"zendframework/zend-i18n-resources": "Translations of validator messages",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains",
"zendframework/zend-session": "Zend\\Session component, required by the Csrf validator",
"zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator",
"zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators"
},
"minimum-stability": "dev",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions doc/book/validators/is-countable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# IsCountable Validator

- **Since 2.10.0**

`Zend\Validator\IsCountable` allows you to validate that a value can be counted
(i.e., it's an array or implements `Countable`), and, optionally:

- the exact count of the value
- the minimum count of the value
- the maximum count of the value

Specifying either of the latter two is inconsistent with the first, and, as
such, the validator does not allow setting both a count and a minimum or maximum
value. You may, however specify both minimum and maximum values, in which case
the validator operates similar to the [Between validator](between.md).

## Supported options

The following options are supported for `Zend\Validator\IsCountable`:

- `count`: Defines if the validation should look for a specific, exact count for
the value provided.
- `max`: Sets the maximum value for the validation; if the count of the value is
greater than the maximum, validation fails..
- `min`: Sets the minimum value for the validation; if the count of the value is
lower than the minimum, validation fails.

## Default behaviour

Given no options, the validator simply tests to see that the value may be
counted (i.e., it's an array or `Countable` instance):

```php
$validator = new Zend\Validator\IsCountable();

$validator->isValid(10); // false; not an array or Countable
$validator->isValid([10]); // true; value is an array
$validator->isValid(new ArrayObject([10])); // true; value is Countable
$validator->isValid(new stdClass); // false; value is not Countable
```

## Specifying an exact count

You can also specify an exact count; if the value is countable, and its count
matches, the the value is valid.

```php
$validator = new Zend\Validator\IsCountable(['count' => 3]);

$validator->isValid([1, 2, 3]); // true; countable, and count is 3
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
$validator->isValid([1]); // false; countable, but count is 1
$validator->isValid(new ArrayObject([1])); // false; countable, but count is 1
```

## Specifying a minimum count

You may specify a minimum count. When you do, the value must be countable, and
greater than or equal to the minimum count you specify in order to be valid.

```php
$validator = new Zend\Validator\IsCountable(['min' => 2]);

$validator->isValid([1, 2, 3]); // true; countable, and count is 3
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
$validator->isValid([1, 2]); // true; countable, and count is 2
$validator->isValid(new ArrayObject([1, 2])); // true; countable, and count is 2
$validator->isValid([1]); // false; countable, but count is 1
$validator->isValid(new ArrayObject([1])); // false; countable, but count is 1
```

## Specifying a maximum count

You may specify a maximum count. When you do, the value must be countable, and
less than or equal to the maximum count you specify in order to be valid.

```php
$validator = new Zend\Validator\IsCountable(['max' => 2]);

$validator->isValid([1, 2, 3]); // false; countable, but count is 3
$validator->isValid(new ArrayObject([1, 2, 3])); // false; countable, but count is 3
$validator->isValid([1, 2]); // true; countable, and count is 2
$validator->isValid(new ArrayObject([1, 2])); // true; countable, and count is 2
$validator->isValid([1]); // true; countable, and count is 1
$validator->isValid(new ArrayObject([1])); // true; countable, and count is 1
```

## Specifying both minimum and maximum

If you specify both a minimum and maximum, the count must be _between_ the two,
inclusively (i.e., it may be the minimum or maximum, and any value between).

```php
$validator = new Zend\Validator\IsCountable([
'min' => 3,
'max' => 5,
]);

$validator->isValid([1, 2, 3]); // true; countable, and count is 3
$validator->isValid(new ArrayObject([1, 2, 3])); // true; countable, and count is 3
$validator->isValid(range(1, 5)); // true; countable, and count is 5
$validator->isValid(new ArrayObject(range(1, 5))); // true; countable, and count is 5
$validator->isValid([1, 2]); // false; countable, and count is 2
$validator->isValid(new ArrayObject([1, 2])); // false; countable, and count is 2
$validator->isValid(range(1, 6)); // false; countable, and count is 6
$validator->isValid(new ArrayObject(range(1, 6))); // false; countable, and count is 6
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pages:
- InArray: validators/in-array.md
- Ip: validators/ip.md
- Isbn: validators/isbn.md
- IsCountable: validators/is-countable.md
- IsInstanceOf: validators/isinstanceof.md
- LessThan: validators/less-than.md
- NotEmpty: validators/not-empty.md
Expand Down
12 changes: 7 additions & 5 deletions src/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ public function __construct($options = null)
$options = $temp;
}

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

if (is_numeric($options['min']) && is_numeric($options['max'])) {
if ((isset($options['min']) && is_numeric($options['min']))
&& (isset($options['max']) && is_numeric($options['max']))
) {
$this->numeric = true;
} elseif (is_string($options['min']) && is_string($options['max'])) {
} elseif ((isset($options['min']) && is_string($options['min']))
&& (isset($options['max']) && is_string($options['max']))
) {
$this->numeric = false;
} else {
throw new Exception\InvalidArgumentException(
Expand Down
5 changes: 4 additions & 1 deletion src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public function __invoke()
public function getDependencyConfig()
{
return [
'aliases' => [
'ValidatorManager' => ValidatorPluginManager::class,
],
'factories' => [
'ValidatorManager' => ValidatorPluginManagerFactory::class,
ValidatorPluginManager::class => ValidatorPluginManagerFactory::class,
],
];
}
Expand Down
Loading

0 comments on commit b65b9a1

Please sign in to comment.