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

Commit

Permalink
Merging develop to master in preparation for 2.8.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 4, 2017
2 parents 178d21a + c0708e0 commit 0099987
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 60 deletions.
51 changes: 11 additions & 40 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,14 @@ sudo: false

language: php

branches:
except:
- /^release-\d+\.\d+\.\d+.*$/
- /^ghgfk-.*$/

cache:
directories:
- $HOME/.composer/cache
- vendor
- $HOME/.local
- zf-mkdoc-theme

env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="satooshi/php-coveralls"
- LEGACY_DEPS="phpunit/phpunit"
- SITE_URL: https://zendframework.github.io/zend-inputfilter
- GH_USER_NAME: "Matthew Weier O'Phinney"
- GH_USER_EMAIL: [email protected]
- GH_REF: github.com/zendframework/zend-inputfilter.git
- secure: "BZ5FxRDnh7Q4KSjnZXBn+vrY0RjZVHUfOcOIVTLR5hIlBRFBz436GbbyyIGAO+YQ8MGPj8Ek+fm/zuDP9gTafG3fNen4dLJOR4dOYmHUNZRgXdLeCpor6W1kaXOQInEs2mpjnsIlSM5s7/IP3QCkaZcj6GBiYuYLXGrH1PJxhE047B8StV3PWpcHi3idRqsdz26oUTH0szD70QNlk0dHqtbzjr9uSk1pRrz8LZW6WuW8yFEq3X1zDEA/XICTXPBk+CEi68wnX8RhXiTvtDpYUnPF3ZkCy6m94PROmBs0UwTPr9MCQShAVSJ0OikFkvEKJgkHNaKce+FqGK5sGcR1asunx87iMsScNKmM/0FrQOqa1pNsv6/jl+n05FZRKbfoK68bnb4YZmOnNAqPiSrF/8oiBfe2tvZVtFmAIkI6uaGD7jP07ljA9JAqtOuTt4u4DX9J2dNYoNF7+F+jtI8/+Ec1wBFvsI/DF02Mw4KYfFfdz5a5+Xzc84MkaFb+hTmAlP8BPh/7RRciL86rCELvQ2zyfwDYk5q4uLJgwg5VjpS/4B2lsjqomXC3iTYUbmdF1Y9ZFE+tyEi/XlyrQOEHisdgrfIf8Itown3S+2vJh15851UtOWs2FQWtAOM/fv4ovLyZwf6adJ0tEUtHsgr+C8NLjSfeY1i6E5QuoOhG9OA="

matrix:
include:
Expand All @@ -33,10 +19,7 @@ matrix:
- php: 5.6
env:
- DEPS=locked
- CS_CHECK=true
- TEST_COVERAGE=true
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- LEGACY_DEPS="phpunit/phpunit"
- php: 5.6
env:
- DEPS=latest
Expand All @@ -46,60 +29,48 @@ matrix:
- php: 7
env:
- DEPS=locked
- LEGACY_DEPS="phpunit/phpunit"
- php: 7
env:
- DEPS=latest
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=locked
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPS=latest
- php: hhvm
- php: 7.2
env:
- DEPS=lowest
- php: hhvm
- php: 7.2
env:
- DEPS=locked
- php: hhvm
- php: 7.2
env:
- DEPS=latest
allow_failures:
- php: hhvm

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- travis_retry composer self-update

install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
- if [[ $TRAVIS_PHP_VERSION =~ ^5.6 ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi
- if [[ $LEGACY_DEPS != '' ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update $COMPOSER_ARGS --prefer-lowest --prefer-stable ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120
- COLUMNS=120 composer show
- stty cols 120 && composer show

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; fi
- if [[ $TEST_COVERAGE != 'true' ]]; then composer test ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi

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

notifications:
email: false
slack:
rooms:
- secure: "Jlr0RxX9sUVOWeo8BK75JlKYnf0Pj/ZD1p3+keEvAO71iB4zVK1OKlUjdARYx8bgEX8aKSun3v6aImu8NwuCrshl3bkXBtADEiQ7ibghi+apHU3A/HGYtiUfwRMmR4+SNXB5qe7RMA5FbKu5j28acea5N4urJqJIDAgQvlZVJrUCsJDpOpwkJ0BlV/UUA7sUvHTs/N3jsUhL+YZdNjirpcrj1LVdwWBs62h25lJ8BvYkGzg4WckP808dSokbfEtAisg/TyxoBFA+GQESvmch0tvQeZBmdrgBJ/t/MRZy8L+u80oXIs26uTnuIxKWtp8p80WPiGdMsJTxyPr1JpIJXVTGYoAzhjGG8ukXXkKxpc4bbhvEm5aPLh0l1RVzzTbp+RaPSaBBqIpEBpAWzzrJMS7owaPMkZzfv/VjUPxawDK7ZIk1Q+VFdeoWdgiKnmr78VtQ8YWeiwKE2FK6JL+UmKMXNSKKJ3Fz4vnlig0tJ+UrqL3LtKLJmqn7+K8rTntPrCIoxKElruazGuKtyUFR/13l6y10mmwtdj14YmENG1OjWDuG+hzrzs0+MwthqSqIADwduyjxu2XE0AbNjCaXqjpwO72zZgfFYtJppaWAS4VF+XpLDy+Ig11RKJccX1bPbMA06Bl32pJieNCFBua2RWnFTK20NMDf/Bht66nFubs="
on_success: change
on_failure: always
30 changes: 28 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

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

## 2.7.6 - 2017-12-04
## 2.8.0 - TBD

### Added

- Nothing.
- [#135](https://github.com/zendframework/zend-inputfilter/pull/135) adds
`Zend\InputFilter\OptionalInputFilter`, which allows defining optional sets of
data. This acts like a standard input filter, but is considered valid if no
data, `null` data, or empty data sets are provided to it; if a non-empty data
set is provided, it will run normal validations.

- [#142](https://github.com/zendframework/zend-inputfilter/pull/142) adds
support for PHP 7.2.

### Changed

Expand All @@ -18,6 +25,25 @@ All notable changes to this project will be documented in this file, in reverse

### Removed

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

### Fixed

- Nothing.

## 2.7.6 - 2017-12-04

### Added

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"php": "^5.6 || ^7.0",
"zendframework/zend-filter": "^2.6",
"zendframework/zend-stdlib": "^2.7 || ^3.0",
"zendframework/zend-validator": "^2.6"
"zendframework/zend-validator": "^2.10.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

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

98 changes: 98 additions & 0 deletions docs/book/optional-input-filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Optional Input Filters

- Since 2.8.0

Normally, input filters are _required_, which means that if you compose them as
a subset of another input filter (e.g., to validate a subset of a larger set of
data), and no data is provided for that item, or an empty set of data is
provided, then the input filter will consider the data invalid.

If you want to allow a set of data to be empty, you can use
`Zend\InputFilter\OptionalInputFilter`.

To illustrate this, let's consider a form where a user provides profile
information. The user can provide an optional "title" and a required "email",
and _optionally_ details about a project they lead, which will include the
project title and a URL, both of which are required if present.

First, let's create an `OptionalInputFilter` instance for the project data:

```php
$projectFilter = new OptionalInputFilter();
$projectFilter->add([
'name' => 'project_name',
'required' => true,
]);
$projectFilter->add([
'name' => 'url',
'required' => true,
'validators' => [
['type' => 'uri'],
],
]);
```

Now, we'll create our primary input filter:

```php
$profileFilter = new InputFilter();
$profileFilter->add([
'name' => 'title',
'required' => false,
]);
$profileFilter->add([
'name' => 'email',
'required' => true,
'validators' => [
['type' => 'EmailAddress'],
],
]);

// And, finally, compose our project sub-filter:
$profileFilter->add($projectFilter, 'project');
```

With this defined, we can now validate the following sets of data, presented in
JSON for readability:

- Just profile information:

```json
{
"email": "[email protected]",
"title": "Software Developer"
}
```

- `null` project provided:

```json
{
"email": "[email protected]",
"title": "Software Developer",
"project": null
}
```

- Empty project provided:

```json
{
"email": "[email protected]",
"title": "Software Developer",
"project": {}
}
```

- Valid project provided:

```json
{
"email": "[email protected]",
"title": "Software Developer",
"project": {
"project_name": "zend-inputfilter",
"url": "https://github.com/zend-inputfilter",
}
}
```
6 changes: 4 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ site_dir: docs/html
pages:
- index.md
- Intro: intro.md
- Specifications: specs.md
- Files: file-input.md
- Reference:
- Specifications: specs.md
- Files: file-input.md
- "Optional Input Filters": optional-input-filters.md
site_name: zend-inputfilter
site_description: zend-inputfilter
repo_url: 'https://github.com/zendframework/zend-inputfilter'
Expand Down
15 changes: 10 additions & 5 deletions src/InputFilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class InputFilterPluginManager extends AbstractPluginManager
* @var string[]
*/
protected $aliases = [
'inputfilter' => InputFilter::class,
'inputFilter' => InputFilter::class,
'InputFilter' => InputFilter::class,
'collection' => CollectionInputFilter::class,
'Collection' => CollectionInputFilter::class,
'inputfilter' => InputFilter::class,
'inputFilter' => InputFilter::class,
'InputFilter' => InputFilter::class,
'collection' => CollectionInputFilter::class,
'Collection' => CollectionInputFilter::class,
'optionalinputfilter' => OptionalInputFilter::class,
'optionalInputFilter' => OptionalInputFilter::class,
'OptionalInputFilter' => OptionalInputFilter::class,
];

/**
Expand All @@ -43,9 +46,11 @@ class InputFilterPluginManager extends AbstractPluginManager
protected $factories = [
InputFilter::class => InvokableFactory::class,
CollectionInputFilter::class => InvokableFactory::class,
OptionalInputFilter::class => InvokableFactory::class,
// v2 canonical FQCN
'zendinputfilterinputfilter' => InvokableFactory::class,
'zendinputfiltercollectioninputfilter' => InvokableFactory::class,
'zendinputfilteroptionalinputfilter' => InvokableFactory::class,
];

/**
Expand Down
Loading

0 comments on commit 0099987

Please sign in to comment.