This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging develop to master in preparation for 2.8.0 release.
- Loading branch information
Showing
9 changed files
with
361 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.