Showing preview only (3,115K chars total). Download the full file or copy to clipboard to get everything.
Repository: zendframework/zend-validator
Branch: master
Commit: 63dd0fe5d89f
Files: 273
Total size: 2.9 MB
Directory structure:
gitextract_70x1ddz0/
├── .coveralls.yml
├── .gitattributes
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── bin/
│ └── update_hostname_validator.php
├── composer.json
├── docs/
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── ISSUE_TEMPLATE.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── SUPPORT.md
│ └── book/
│ ├── index.md
│ ├── intro.md
│ ├── messages.md
│ ├── set.md
│ ├── validator-chains.md
│ ├── validators/
│ │ ├── barcode.md
│ │ ├── between.md
│ │ ├── callback.md
│ │ ├── credit-card.md
│ │ ├── date.md
│ │ ├── db.md
│ │ ├── digits.md
│ │ ├── email-address.md
│ │ ├── explode.md
│ │ ├── file/
│ │ │ ├── count.md
│ │ │ ├── crc32.md
│ │ │ ├── exclude-extension.md
│ │ │ ├── exclude-mime-type.md
│ │ │ ├── exists.md
│ │ │ ├── extension.md
│ │ │ ├── files-size.md
│ │ │ ├── hash.md
│ │ │ ├── image-size.md
│ │ │ ├── intro.md
│ │ │ ├── is-compressed.md
│ │ │ ├── is-image.md
│ │ │ ├── md5.md
│ │ │ ├── mime-type.md
│ │ │ ├── not-exists.md
│ │ │ ├── sha1.md
│ │ │ ├── size.md
│ │ │ ├── upload-file.md
│ │ │ ├── upload.md
│ │ │ └── word-count.md
│ │ ├── greater-than.md
│ │ ├── hex.md
│ │ ├── hostname.md
│ │ ├── iban.md
│ │ ├── identical.md
│ │ ├── in-array.md
│ │ ├── ip.md
│ │ ├── is-countable.md
│ │ ├── isbn.md
│ │ ├── isinstanceof.md
│ │ ├── less-than.md
│ │ ├── not-empty.md
│ │ ├── regex.md
│ │ ├── sitemap.md
│ │ ├── step.md
│ │ ├── string-length.md
│ │ ├── timezone.md
│ │ ├── undisclosed-password.md
│ │ ├── uri.md
│ │ └── uuid.md
│ └── writing-validators.md
├── mkdocs.yml
├── phpcs.xml
├── phpunit.xml.dist
├── src/
│ ├── AbstractValidator.php
│ ├── Barcode/
│ │ ├── AbstractAdapter.php
│ │ ├── AdapterInterface.php
│ │ ├── Codabar.php
│ │ ├── Code128.php
│ │ ├── Code25.php
│ │ ├── Code25interleaved.php
│ │ ├── Code39.php
│ │ ├── Code39ext.php
│ │ ├── Code93.php
│ │ ├── Code93ext.php
│ │ ├── Ean12.php
│ │ ├── Ean13.php
│ │ ├── Ean14.php
│ │ ├── Ean18.php
│ │ ├── Ean2.php
│ │ ├── Ean5.php
│ │ ├── Ean8.php
│ │ ├── Gtin12.php
│ │ ├── Gtin13.php
│ │ ├── Gtin14.php
│ │ ├── Identcode.php
│ │ ├── Intelligentmail.php
│ │ ├── Issn.php
│ │ ├── Itf14.php
│ │ ├── Leitcode.php
│ │ ├── Planet.php
│ │ ├── Postnet.php
│ │ ├── Royalmail.php
│ │ ├── Sscc.php
│ │ ├── Upca.php
│ │ └── Upce.php
│ ├── Barcode.php
│ ├── Between.php
│ ├── Bitwise.php
│ ├── Callback.php
│ ├── ConfigProvider.php
│ ├── CreditCard.php
│ ├── Csrf.php
│ ├── Date.php
│ ├── DateStep.php
│ ├── Db/
│ │ ├── AbstractDb.php
│ │ ├── NoRecordExists.php
│ │ └── RecordExists.php
│ ├── Digits.php
│ ├── EmailAddress.php
│ ├── Exception/
│ │ ├── BadMethodCallException.php
│ │ ├── ExceptionInterface.php
│ │ ├── ExtensionNotLoadedException.php
│ │ ├── InvalidArgumentException.php
│ │ ├── InvalidMagicMimeFileException.php
│ │ └── RuntimeException.php
│ ├── Explode.php
│ ├── File/
│ │ ├── Count.php
│ │ ├── Crc32.php
│ │ ├── ExcludeExtension.php
│ │ ├── ExcludeMimeType.php
│ │ ├── Exists.php
│ │ ├── Extension.php
│ │ ├── FileInformationTrait.php
│ │ ├── FilesSize.php
│ │ ├── Hash.php
│ │ ├── ImageSize.php
│ │ ├── IsCompressed.php
│ │ ├── IsImage.php
│ │ ├── Md5.php
│ │ ├── MimeType.php
│ │ ├── NotExists.php
│ │ ├── Sha1.php
│ │ ├── Size.php
│ │ ├── Upload.php
│ │ ├── UploadFile.php
│ │ └── WordCount.php
│ ├── GpsPoint.php
│ ├── GreaterThan.php
│ ├── Hex.php
│ ├── Hostname/
│ │ ├── Biz.php
│ │ ├── Cn.php
│ │ ├── Com.php
│ │ └── Jp.php
│ ├── Hostname.php
│ ├── Iban.php
│ ├── Identical.php
│ ├── InArray.php
│ ├── Ip.php
│ ├── IsCountable.php
│ ├── IsInstanceOf.php
│ ├── Isbn/
│ │ ├── Isbn10.php
│ │ └── Isbn13.php
│ ├── Isbn.php
│ ├── LessThan.php
│ ├── Module.php
│ ├── NotEmpty.php
│ ├── Regex.php
│ ├── Sitemap/
│ │ ├── Changefreq.php
│ │ ├── Lastmod.php
│ │ ├── Loc.php
│ │ └── Priority.php
│ ├── StaticValidator.php
│ ├── Step.php
│ ├── StringLength.php
│ ├── Timezone.php
│ ├── Translator/
│ │ ├── TranslatorAwareInterface.php
│ │ └── TranslatorInterface.php
│ ├── UndisclosedPassword.php
│ ├── Uri.php
│ ├── Uuid.php
│ ├── ValidatorChain.php
│ ├── ValidatorInterface.php
│ ├── ValidatorPluginManager.php
│ ├── ValidatorPluginManagerAwareInterface.php
│ ├── ValidatorPluginManagerFactory.php
│ └── ValidatorProviderInterface.php
└── test/
├── AbstractTest.php
├── BarcodeTest.php
├── BetweenTest.php
├── BitwiseTest.php
├── CallbackTest.php
├── CreditCardTest.php
├── CsrfTest.php
├── DateStepTest.php
├── DateTest.php
├── Db/
│ ├── AbstractDbTest.php
│ ├── NoRecordExistsTest.php
│ ├── RecordExistsTest.php
│ └── TestAsset/
│ ├── ConcreteDbValidator.php
│ └── TrustingSql92Platform.php
├── DigitsTest.php
├── EmailAddressTest.php
├── ExplodeTest.php
├── File/
│ ├── CountTest.php
│ ├── Crc32Test.php
│ ├── ExcludeExtensionTest.php
│ ├── ExcludeMimeTypeTest.php
│ ├── ExistsTest.php
│ ├── ExtensionTest.php
│ ├── FileInformationTraitTest.php
│ ├── FilesSizeTest.php
│ ├── HashTest.php
│ ├── ImageSizeTest.php
│ ├── IsCompressedTest.php
│ ├── IsImageTest.php
│ ├── Md5Test.php
│ ├── MimeTypeTest.php
│ ├── NotExistsTest.php
│ ├── Sha1Test.php
│ ├── SizeTest.php
│ ├── TestAsset/
│ │ └── FileInformation.php
│ ├── UploadFileTest.php
│ ├── UploadTest.php
│ ├── WordCountTest.php
│ └── _files/
│ ├── magic.7.mime
│ ├── magic.lte.5.3.10.mime
│ ├── magic.mime
│ ├── testsize.mo
│ ├── testsize2.mo
│ ├── testsize3.mo
│ ├── testsize4.mo
│ └── wordcount.txt
├── GPSPointTest.php
├── GreaterThanTest.php
├── HexTest.php
├── HostnameTest.php
├── IbanTest.php
├── IdenticalTest.php
├── InArrayTest.php
├── IpTest.php
├── IsCountableTest.php
├── IsInstanceOfTest.php
├── IsbnTest.php
├── LessThanTest.php
├── MessageTest.php
├── NotEmptyTest.php
├── RegexTest.php
├── Sitemap/
│ ├── ChangefreqTest.php
│ ├── LastmodTest.php
│ ├── LocTest.php
│ └── PriorityTest.php
├── StaticValidatorTest.php
├── StepTest.php
├── StringLengthTest.php
├── TestAsset/
│ ├── ArrayTranslator.php
│ ├── ConcreteValidator.php
│ ├── CreditCardValidatorExtension.php
│ ├── EmailValidatorWithExposedIsReserved.php
│ ├── HttpClientException.php
│ ├── SessionManager.php
│ └── Translator.php
├── TimezoneTest.php
├── UndisclosedPasswordTest.php
├── UriTest.php
├── UuidTest.php
├── ValidatorChainTest.php
├── ValidatorPluginManagerCompatibilityTest.php
├── ValidatorPluginManagerFactoryTest.php
├── ValidatorPluginManagerTest.php
└── _files/
├── MyBarcode1.php
├── MyBarcode2.php
├── MyBarcode3.php
├── MyBarcode4.php
└── MyBarcode5.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .coveralls.yml
================================================
coverage_clover: clover.xml
json_path: coveralls-upload.json
================================================
FILE: .gitattributes
================================================
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/composer.lock export-ignore
/docs/ export-ignore
/mkdocs.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/test/ export-ignore
================================================
FILE: .gitignore
================================================
/clover.xml
/coveralls-upload.json
/docs/html/
/phpunit.xml
/vendor/
/zf-mkdoc-theme.tgz
/zf-mkdoc-theme/
================================================
FILE: .travis.yml
================================================
language: php
branches:
except:
- /^release-.*$/
- /^ghgfk-.*$/
cache:
directories:
- $HOME/.composer/
env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- LEGACY_DEPS="phpunit/phpunit"
- TESTS_ZEND_VALIDATOR_ONLINE_ENABLED=true
matrix:
include:
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=locked
- EXECUTE_HOSTNAME_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPS=latest
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=locked
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=locked
- php: 7.3
env:
- DEPS=latest
- php: 7.4
env:
- DEPS=lowest
- php: 7.4
env:
- DEPS=locked
- php: 7.4
env:
- DEPS=latest
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 [[ $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 [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120
- COLUMNS=120 composer show
script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- 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 travis_retry php vendor/bin/php-coveralls -v ; fi
notifications:
email: false
================================================
FILE: CHANGELOG.md
================================================
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 2.13.0 - 2019-12-27
### Added
- [#275](https://github.com/zendframework/zend-validator/pull/275) adds a new `strict` option to `Zend\Validator\Date`; when `true`, the value being validated must both be a date AND in the same format as provided via the `format` option.
- [#264](https://github.com/zendframework/zend-validator/pull/264) adds `Zend\Validator\UndisclosedPassword`, which can be used to determine if a password has been exposed in a known data breach as reported on the [Have I Been Pwned?](https://www.haveibeenpwned.com) website. [Documentation](https://docs.zendframework.com/zend-validator/validators/undisclosed-password/)
- [#266](https://github.com/zendframework/zend-validator/pull/266) adds a new option to the `File\Extension` and `File\ExcludeExtension` validators, `allowNonExistentFile`. When set to `true`, the validators will continue validating the extension of the filename given even if the file does not exist. The default is `false`, to preserve backwards compatibility with previous versions.
### Changed
- [#264](https://github.com/zendframework/zend-validator/pull/264) bumps the minimum supported PHP version to 7.1.0.
- [#279](https://github.com/zendframework/zend-validator/pull/279) updates the `magic.mime` file used for file validations.
### Deprecated
- Nothing.
### Removed
- [#264](https://github.com/zendframework/zend-validator/pull/264) removes support for PHP versions prior to 7.1.0.
### Fixed
- Nothing.
## 2.12.2 - 2019-10-29
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#277](https://github.com/zendframework/zend-validator/pull/277) fixes `File\Hash` validator in case
when the file hash contains only digits.
- [#277](https://github.com/zendframework/zend-validator/pull/277) fixes `File\Hash` validator to match
hash with the given hashing algorithm.
## 2.12.1 - 2019-10-12
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#272](https://github.com/zendframework/zend-validator/pull/272) changes
curly braces in array and string offset access to square brackets
in order to prevent issues under the upcoming PHP 7.4 release.
- [#231](https://github.com/zendframework/zend-validator/pull/231) fixes validation of input hashes in `Zend\Validator\File\Hash` validator when provided as array.
Only string hashes are allowed. If different type is provided `Zend\Validator\Exception\InvalidArgumentException` is thrown.
## 2.12.0 - 2019-01-30
### Added
- [#250](https://github.com/zendframework/zend-validator/pull/250) adds support for PHP 7.3.
### Changed
- [#251](https://github.com/zendframework/zend-validator/pull/251) updates the logic of each of the various `Zend\Validator\File` validators
to allow validating against PSR-7 `UploadedFileInterface` instances, expanding
the support originally provided in version 2.11.0.
### Deprecated
- Nothing.
### Removed
- [#250](https://github.com/zendframework/zend-validator/pull/250) removes support for zend-stdlib v2 releases.
### Fixed
- Nothing.
## 2.11.1 - 2019-01-29
### Added
- [#249](https://github.com/zendframework/zend-validator/pull/249) adds support in the hostname validator for the `.rs` TLD.
### Changed
- [#253](https://github.com/zendframework/zend-validator/pull/253) updates the list of allowed characters for a `DE` domain name to match those published by IDN.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#256](https://github.com/zendframework/zend-validator/pull/256) fixes hostname validation when omitting the TLD from verification,
ensuring validation of the domain segment considers all URI criteria.
## 2.11.0 - 2018-12-13
### Added
- [#237](https://github.com/zendframework/zend-validator/pull/237) adds support for the [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#uploadedfileinterface)
to each of the `Upload` and `UploadFile` validators.
- [#220](https://github.com/zendframework/zend-validator/pull/220) adds image/webp to the list of known image types for the `IsImage` validator.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.10.3 - 2018-12-13
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#241](https://github.com/zendframework/zend-validator/pull/241) has the `Hostname` validator return an invalid result early when an empty
domain segment is detected.
- [#232](https://github.com/zendframework/zend-validator/pull/232) updates the `Hostname` validator to allow underscores in subdomains.
- [#218](https://github.com/zendframework/zend-validator/pull/218) fixes a precision issue with the `Step` validator.
## 2.10.2 - 2018-02-01
### Added
- [#202](https://github.com/zendframework/zend-validator/pull/202) adds the
ability to use custom constant types in extensions of
`Zend\Validator\CreditCard`, fixing an issue where users were unable to add
new brands as they are created.
- [#203](https://github.com/zendframework/zend-validator/pull/203) adds support
for the new Russian bank card "Mir".
- [#204](https://github.com/zendframework/zend-validator/pull/204) adds support
to the IBAN validator for performing SEPA validation against Croatia and San
Marino.
- [#209](https://github.com/zendframework/zend-validator/pull/209) adds
documentation for the `Explode` validator.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#195](https://github.com/zendframework/zend-validator/pull/195) adds
missing `GpsPoint` validator entries to the `ValidatorPluginManager`, ensuring
they may be retrieved from it correctly.
- [#212](https://github.com/zendframework/zend-validator/pull/212) updates the
`CSRF` validator to automatically mark any non-string values as invalid,
preventing errors such as array to string conversion.
## 2.10.1 - 2017-08-22
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#194](https://github.com/zendframework/zend-validator/pull/194) modifies the
`EmailAddress` validator to omit the `INTL_IDNA_VARIANT_UTS46` flag to
`idn_to_utf8()` if the constant is not defined, fixing an issue on systems
using pre-2012 releases of libicu.
## 2.10.0 - 2017-08-14
### 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
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#180](https://github.com/zendframework/zend-validator/pull/180) fixes how
`Zend\Validator\File\MimeType` "closes" the open FileInfo handle for the file
being validated, using `unset()` instead of `finfo_close()`; this resolves a
segfault that occurs on older PHP versions.
- [#174](https://github.com/zendframework/zend-validator/pull/174) fixes how
`Zend\Validator\Between` handles two situations: (1) when a non-numeric value
is validated against numeric min/max values, and (2) when a numeric value is
validated against non-numeric min/max values. Previously, these incorrectly
validated as true; now they are marked invalid.
## 2.9.1 - 2017-05-17
### Added
- Nothing.
### Changes
- [#154](https://github.com/zendframework/zend-validator/pull/154) updates the
`CreditCard` validator to allow 19 digit Discover card values, and 13 and 19
digit Visa card values, which are now allowed (see
https://en.wikipedia.org/wiki/Payment_card_number).
- [#162](https://github.com/zendframework/zend-validator/pull/162) updates the
`Hostname` validator to support `.hr` (Croatia) IDN domains.
- [#163](https://github.com/zendframework/zend-validator/pull/163) updates the
`Iban` validator to support Belarus.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#168](https://github.com/zendframework/zend-validator/pull/168) fixes how the
`ValidatorPluginManagerFactory` factory initializes the plugin manager instance,
ensuring it is injecting the relevant configuration from the `config` service
and thus seeding it with configured validator services. This means
that the `validators` configuration will now be honored in non-zend-mvc contexts.
## 2.9.0 - 2017-03-17
### Added
- [#78](https://github.com/zendframework/zend-validator/pull/78) added
`%length%` as an optional message variable in StringLength validator
### Deprecated
- Nothing.
### Removed
- [#151](https://github.com/zendframework/zend-validator/pull/151) dropped
php 5.5 support
### Fixed
- [#147](https://github.com/zendframework/zend-validator/issues/147)
[#148](https://github.com/zendframework/zend-validator/pull/148) adds further
`"suggest"` clauses in `composer.json`, since some dependencies are not always
required, and may lead to runtime failures.
- [#66](https://github.com/zendframework/zend-validator/pull/66) fixed
EmailAddress validator applying IDNA conversion to local part
- [#88](https://github.com/zendframework/zend-validator/pull/88) fixed NotEmpty
validator incorrectly applying types bitmaps
- [#150](https://github.com/zendframework/zend-validator/pull/150) fixed Hostname
validator not allowing some characters in .dk IDN
## 2.8.2 - 2017-01-29
### Added
- [#110](https://github.com/zendframework/zend-validator/pull/110) adds new
Mastercard 2-series BINs
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#81](https://github.com/zendframework/zend-validator/pull/81) registers the
Uuid validator into ValidatorPluginManager.
## 2.8.1 - 2016-06-23
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#92](https://github.com/zendframework/zend-validator/pull/92) adds message
templates to the `ExcludeMimeType` validator, to allow differentiating
validation error messages from the `MimeType` validator.
## 2.8.0 - 2016-05-16
### Added
- [#58](https://github.com/zendframework/zend-validator/pull/58) adds a new
`Uuid` validator, capable of validating if Versions 1-5 UUIDs are well-formed.
- [#64](https://github.com/zendframework/zend-validator/pull/64) ports
`Zend\ModuleManager\Feature\ValidatorProviderInterface` to
`Zend\Validator\ValidatorProviderInterface`, and updates the `Module::init()`
to typehint against the new interface instead of the one from
zend-modulemanager. Applications targeting zend-mvc v3 can start updating
their code to implement the new interface, or simply duck-type against it.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.7.3 - 2016-05-16
### Added
- [#67](https://github.com/zendframework/zend-validator/pull/67) adds support
for Punycoded top-level domains in the `Hostname` validator.
- [#79](https://github.com/zendframework/zend-validator/pull/79) adds and
publishes the documentation to https://zendframework.github.io/zend-validator/
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.7.2 - 2016-04-18
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#65](https://github.com/zendframework/zend-validator/pull/65) fixes the
`Module::init()` method to properly receive a `ModuleManager` instance, and
not expect a `ModuleEvent`.
## 2.7.1 - 2016-04-06
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- This release updates the TLD list to the latest version from the IANA.
## 2.7.0 - 2016-04-06
### Added
- [#63](https://github.com/zendframework/zend-validator/pull/63) exposes the
package as a ZF component and/or generic configuration provider, by adding the
following:
- `ValidatorPluginManagerFactory`, which can be consumed by container-interop /
zend-servicemanager to create and return a `ValidatorPluginManager` instance.
- `ConfigProvider`, which maps the service `ValidatorManager` to the above
factory.
- `Module`, which does the same as `ConfigProvider`, but specifically for
zend-mvc applications. It also provices a specification to
`Zend\ModuleManager\Listener\ServiceListener` to allow modules to provide
validator configuration.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.6.0 - 2016-02-17
### Added
- [#18](https://github.com/zendframework/zend-validator/pull/18) adds a `GpsPoint`
validator for validating GPS coordinates.
- [#47](https://github.com/zendframework/zend-validator/pull/47) adds two new
classes, `Zend\Validator\Isbn\Isbn10` and `Isbn13`; these classes are the
result of an extract class refactoring, and contain the logic specific to
calcualting the checksum for each ISBN style. `Zend\Validator\Isbn` now
instantiates the appropriate one and invokes it.
- [#46](https://github.com/zendframework/zend-validator/pull/46) updates
`Zend\Validator\Db\AbstractDb` to implement `Zend\Db\Adapter\AdapterAwareInterface`,
by composing `Zend\Db\Adapter\AdapterAwareTrait`.
### Deprecated
- Nothing.
### Removed
- [#55](https://github.com/zendframework/zend-validator/pull/55) removes some
checks for `safe_mode` within the `MimeType` validator, as `safe_mode` became
obsolete starting with PHP 5.4.
### Fixed
- [#45](https://github.com/zendframework/zend-validator/pull/45) fixes aliases
mapping the deprecated `Float` and `Int` validators to their `Is*` counterparts.
- [#49](https://github.com/zendframework/zend-validator/pull/49)
[#50](https://github.com/zendframework/zend-validator/pull/50), and
[#51](https://github.com/zendframework/zend-validator/pull/51) update the
code to be forwards-compatible with zend-servicemanager and zend-stdlib v3.
- [#56](https://github.com/zendframework/zend-validator/pull/56) fixes the regex
in the `Ip` validator to escape `.` characters used as IP delimiters.
## 2.5.4 - 2016-02-17
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#44](https://github.com/zendframework/zend-validator/pull/44) corrects the
grammar on the `NOT_GREATER_INCLUSIVE` validation error message.
- [#45](https://github.com/zendframework/zend-validator/pull/45) adds normalized
aliases for the i18n isfloat/isint validators.
- Updates the hostname validator regexes per the canonical service on which they
are based.
- [#52](https://github.com/zendframework/zend-validator/pull/52) updates the
`Barcode` validator to cast empty options passed to the constructor to an
empty array, fixing type mismatch errors.
- [#54](https://github.com/zendframework/zend-validator/pull/54) fixes the IP
address detection in the `Hostname` validator to ensure that IPv6 is detected
correctly.
- [#56](https://github.com/zendframework/zend-validator/pull/56) updates the
regexes used by the `IP` validator when comparing ipv4 addresses to ensure a
literal `.` is tested between network segments.
## 2.5.3 - 2015-09-03
### Added
- [#30](https://github.com/zendframework/zend-validator/pull/30) adds tooling to
ensure that the Hostname TLD list stays up-to-date as changes are pushed for
the repository.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#17](https://github.com/zendframework/zend-validator/pull/17) and
[#29](https://github.com/zendframework/zend-validator/pull/29) provide more
test coverage, and fix a number of edge cases, primarily in validator option
verifications.
- [#26](https://github.com/zendframework/zend-validator/pull/26) fixes tests for
`StaticValidator` such that they make correct assertions now. In doing so, we
determined that it was possible to pass an indexed array of options, which
could lead to unexpected results, often leading to false positives when
validating. To correct this situation, `StaticValidator::execute()` now raises
an `InvalidArgumentException` when an indexed array is detected for the
`$options` argument.
- [#35](https://github.com/zendframework/zend-validator/pull/35) modifies the
`NotEmpty` validator to no longer treat the float `0.0` as an empty value for
purposes of validation.
- [#25](https://github.com/zendframework/zend-validator/pull/25) fixes the
`Date` validator to check against `DateTimeImmutable` and not
`DateTimeInterface` (as PHP has restrictions currently on how the latter can
be used).
## 2.5.2 - 2015-07-16
### Added
- [#8](https://github.com/zendframework/zend-validator/pull/8) adds a "strict"
configuration option; when enabled (the default), the length of the address is
checked to ensure it follows the specification.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#8](https://github.com/zendframework/zend-validator/pull/8) fixes bad
behavior on the part of the `idn_to_utf8()` function, returning the original
address in the case that the function fails.
- [#11](https://github.com/zendframework/zend-validator/pull/11) fixes
`ValidatorChain::prependValidator()` so that it works on HHVM.
- [#12](https://github.com/zendframework/zend-validator/pull/12) adds "6772" to
the Maestro range of the `CreditCard` validator.
================================================
FILE: LICENSE.md
================================================
Copyright (c) 2005-2019, Zend Technologies USA, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
- Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: README.md
================================================
# zend-validator
> ## Repository abandoned 2019-12-31
>
> This repository has moved to [laminas/laminas-validator](https://github.com/laminas/laminas-validator).
[](https://secure.travis-ci.org/zendframework/zend-validator)
[](https://coveralls.io/github/zendframework/zend-validator?branch=master)
zend-validator provides a set of commonly needed validators. It also provides a
simple validator chaining mechanism by which multiple validators may be applied
to a single datum in a user-defined order.
## Installation
Run the following to install this library:
```bash
$ composer require zendframework/zend-validator
```
## Documentation
Browse the documentation online at https://docs.zendframework.com/zend-validator/
## Support
* [Issues](https://github.com/zendframework/zend-validator/issues/)
* [Chat](https://zendframework-slack.herokuapp.com/)
* [Forum](https://discourse.zendframework.com/)
================================================
FILE: bin/update_hostname_validator.php
================================================
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
use Zend\Http\Client;
use Zend\Validator\Hostname;
require __DIR__ . '/../vendor/autoload.php';
define('IANA_URL', 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt');
define('ZF2_HOSTNAME_VALIDATOR_FILE', __DIR__.'/../src/Hostname.php');
if (! file_exists(ZF2_HOSTNAME_VALIDATOR_FILE) || ! is_readable(ZF2_HOSTNAME_VALIDATOR_FILE)) {
printf("Error: cannont read file '%s'%s", ZF2_HOSTNAME_VALIDATOR_FILE, PHP_EOL);
exit(1);
}
if (! is_writable(ZF2_HOSTNAME_VALIDATOR_FILE)) {
printf("Error: Cannot update file '%s'%s", ZF2_HOSTNAME_VALIDATOR_FILE, PHP_EOL);
exit(1);
}
$newFileContent = []; // new file content
$insertDone = false; // becomes 'true' when we find start of $validTlds declaration
$insertFinish = false; // becomes 'true' when we find end of $validTlds declaration
$checkOnly = isset($argv[1]) ? $argv[1] === '--check-only' : false;
$response = getOfficialTLDs();
$ianaVersion = getVersionFromString('Version', strtok($response->getBody(), "\n"));
$validatorVersion = getVersionFromString('IanaVersion', file_get_contents(ZF2_HOSTNAME_VALIDATOR_FILE));
if ($checkOnly && $ianaVersion > $validatorVersion) {
printf(
'TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s',
PHP_EOL
);
exit(1);
}
if ($checkOnly) {
printf('TLDs are up-to-date%s', PHP_EOL);
exit(0);
}
foreach (file(ZF2_HOSTNAME_VALIDATOR_FILE) as $line) {
// Replace old version number with new one
if (preg_match('/\*\s+IanaVersion\s+\d+/', $line, $matches)) {
$newFileContent[] = sprintf(" * IanaVersion %s\n", $ianaVersion);
continue;
}
if ($insertDone === $insertFinish) {
// Outside of $validTlds definition; keep line as-is
$newFileContent[] = $line;
}
if ($insertFinish) {
continue;
}
if ($insertDone) {
// Detect where the $validTlds declaration ends
if (preg_match('/^\s+\];\s*$/', $line)) {
$newFileContent[] = $line;
$insertFinish = true;
}
continue;
}
// Detect where the $validTlds declaration begins
if (preg_match('/^\s+protected\s+\$validTlds\s+=\s+\[\s*$/', $line)) {
$newFileContent = array_merge($newFileContent, getNewValidTlds($response->getBody()));
$insertDone = true;
}
}
if (! $insertDone) {
printf('Error: cannot find line with "protected $validTlds"%s', PHP_EOL);
exit(1);
}
if (!$insertFinish) {
printf('Error: cannot find end of $validTlds declaration%s', PHP_EOL);
exit(1);
}
if (false === @file_put_contents(ZF2_HOSTNAME_VALIDATOR_FILE, $newFileContent)) {
printf('Error: cannot write info file "%s"%s', ZF2_HOSTNAME_VALIDATOR_FILE, PHP_EOL);
exit(1);
}
printf('Validator TLD file updated.%s', PHP_EOL);
exit(0);
/**
* Get Official TLDs
*
* @return \Zend\Http\Response
* @throws Exception
*/
function getOfficialTLDs()
{
$client = new Client();
$client->setOptions([
'adapter' => 'Zend\Http\Client\Adapter\Curl',
]);
$client->setUri(IANA_URL);
$client->setMethod('GET');
$response = $client->send();
if (! $response->isSuccess()) {
throw new \Exception(sprintf("Error: cannot get '%s'%s", IANA_URL, PHP_EOL));
}
return $response;
}
/**
* Extract the first match of a string like
* "Version 2015072300" from the given string
*
* @param string $prefix
* @param string $string
* @return string
* @throws Exception
*/
function getVersionFromString($prefix, $string)
{
$matches = [];
if (! preg_match(sprintf('/%s\s+((\d+)?)/', $prefix), $string, $matches)) {
throw new Exception('Error: cannot get last update date');
}
return $matches[1];
}
/**
* Extract new Valid TLDs from a string containing one per line.
*
* @param string $string
* @return array
*/
function getNewValidTlds($string)
{
$decodePunycode = getPunycodeDecoder();
// Get new TLDs from the list previously fetched
$newValidTlds = [];
foreach (preg_grep('/^[^#]/', preg_split("#\r?\n#", $string)) as $line) {
$newValidTlds []= sprintf(
"%s'%s',\n",
str_repeat(' ', 8),
$decodePunycode(strtolower($line))
);
}
return $newValidTlds;
}
/**
* Retrieve and return a punycode decoder.
*
* TLDs are puny encoded.
*
* We need a decodePunycode function to translate TLDs to UTF-8:
*
* - use idn_to_utf8 if available
* - otherwise, use Hostname::decodePunycode()
*
* @return callable
*/
function getPunycodeDecoder()
{
if (function_exists('idn_to_utf8')) {
return function ($domain) {
return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
};
}
$hostnameValidator = new Hostname();
$reflection = new ReflectionClass(get_class($hostnameValidator));
$decodePunyCode = $reflection->getMethod('decodePunycode');
$decodePunyCode->setAccessible(true);
return function ($encode) use ($hostnameValidator, $decodePunyCode) {
if (strpos($encode, 'xn--') === 0) {
return $decodePunyCode->invokeArgs($hostnameValidator, [substr($encode, 4)]);
}
return $encode;
};
}
================================================
FILE: composer.json
================================================
{
"name": "zendframework/zend-validator",
"description": "Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria",
"license": "BSD-3-Clause",
"keywords": [
"zendframework",
"zf",
"validator"
],
"support": {
"docs": "https://docs.zendframework.com/zend-validator/",
"issues": "https://github.com/zendframework/zend-validator/issues",
"source": "https://github.com/zendframework/zend-validator",
"rss": "https://github.com/zendframework/zend-validator/releases.atom",
"chat": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/components"
},
"require": {
"php": "^7.1",
"zendframework/zend-stdlib": "^3.2.1",
"container-interop/container-interop": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0.8 || ^5.7.15",
"psr/http-message": "^1.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"zendframework/zend-cache": "^2.6.1",
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-config": "^2.6",
"zendframework/zend-db": "^2.7",
"zendframework/zend-filter": "^2.6",
"zendframework/zend-http": "^2.5.4",
"zendframework/zend-i18n": "^2.6",
"zendframework/zend-math": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-session": "^2.8",
"zendframework/zend-uri": "^2.5"
},
"suggest": {
"psr/http-message": "psr/http-message, required when validating PSR-7 UploadedFileInterface instances via the Upload and UploadFile validators",
"zendframework/zend-db": "Zend\\Db component, required by the (No)RecordExists validator",
"zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator",
"zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages",
"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, ^2.8; required by the Csrf validator",
"zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators"
},
"autoload": {
"psr-4": {
"Zend\\Validator\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZendTest\\Validator\\": "test/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "2.13.x-dev",
"dev-develop": "2.14.x-dev"
},
"zf": {
"component": "Zend\\Validator",
"config-provider": "Zend\\Validator\\ConfigProvider"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}
================================================
FILE: docs/CODE_OF_CONDUCT.md
================================================
# Contributor Code of Conduct
This project adheres to [The Code Manifesto](http://codemanifesto.com)
as its guidelines for contributor interactions.
## The Code Manifesto
We want to work in an ecosystem that empowers developers to reach their
potential — one that encourages growth and effective collaboration. A space that
is safe for all.
A space such as this benefits everyone that participates in it. It encourages
new developers to enter our field. It is through discussion and collaboration
that we grow, and through growth that we improve.
In the effort to create such a place, we hold to these values:
1. **Discrimination limits us.** This includes discrimination on the basis of
race, gender, sexual orientation, gender identity, age, nationality, technology
and any other arbitrary exclusion of a group of people.
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort
levels. Remember that, and if brought to your attention, heed it.
3. **We are our biggest assets.** None of us were born masters of our trade.
Each of us has been helped along the way. Return that favor, when and where
you can.
4. **We are resources for the future.** As an extension of #3, share what you
know. Make yourself a resource to help those that come after you.
5. **Respect defines us.** Treat others as you wish to be treated. Make your
discussions, criticisms and debates from a position of respectfulness. Ask
yourself, is it true? Is it necessary? Is it constructive? Anything less is
unacceptable.
6. **Reactions require grace.** Angry responses are valid, but abusive language
and vindictive actions are toxic. When something happens that offends you,
handle it assertively, but be respectful. Escalate reasonably, and try to
allow the offender an opportunity to explain themselves, and possibly correct
the issue.
7. **Opinions are just that: opinions.** Each and every one of us, due to our
background and upbringing, have varying opinions. The fact of the matter, is
that is perfectly acceptable. Remember this: if you respect your own
opinions, you should respect the opinions of others.
8. **To err is human.** You might not intend it, but mistakes do happen and
contribute to build experience. Tolerate honest mistakes, and don't hesitate
to apologize if you make one yourself.
================================================
FILE: docs/CONTRIBUTING.md
================================================
# CONTRIBUTING
## RESOURCES
If you wish to contribute to this project, please be sure to
read/subscribe to the following resources:
- [Coding Standards](https://github.com/zendframework/zend-coding-standard)
- [Forums](https://discourse.zendframework.com/c/contributors)
- [Chat](https://zendframework-slack.herokuapp.com)
- [Code of Conduct](CODE_OF_CONDUCT.md)
If you are working on new features or refactoring
[create a proposal](https://github.com/zendframework/zend-validator/issues/new).
## RUNNING TESTS
To run tests:
- Clone the repository:
```console
$ git clone git://github.com/zendframework/zend-validator.git
$ cd zend-validator
```
- Install dependencies via composer:
```console
$ composer install
```
If you don't have `composer` installed, please download it from https://getcomposer.org/download/
- Run the tests using the "test" command shipped in the `composer.json`:
```console
$ composer test
```
You can turn on conditional tests with the `phpunit.xml` file.
To do so:
- Copy `phpunit.xml.dist` file to `phpunit.xml`
- Edit `phpunit.xml` to enable any specific functionality you
want to test, as well as to provide test values to utilize.
## Running Coding Standards Checks
First, ensure you've installed dependencies via composer, per the previous
section on running tests.
To run CS checks only:
```console
$ composer cs-check
```
To attempt to automatically fix common CS issues:
```console
$ composer cs-fix
```
If the above fixes any CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.
## Recommended Workflow for Contributions
Your first step is to establish a public repository from which we can
pull your work into the master repository. We recommend using
[GitHub](https://github.com), as that is where the component is already hosted.
1. Setup a [GitHub account](https://github.com/), if you haven't yet
2. Fork the repository (https://github.com/zendframework/zend-validator)
3. Clone the canonical repository locally and enter it.
```console
$ git clone git://github.com/zendframework/zend-validator.git
$ cd zend-validator
```
4. Add a remote to your fork; substitute your GitHub username in the command
below.
```console
$ git remote add {username} git@github.com:{username}/zend-validator.git
$ git fetch {username}
```
### Keeping Up-to-Date
Periodically, you should update your fork or personal repository to
match the canonical ZF repository. Assuming you have setup your local repository
per the instructions above, you can do the following:
```console
$ git checkout master
$ git fetch origin
$ git rebase origin/master
# OPTIONALLY, to keep your remote up-to-date -
$ git push {username} master:master
```
If you're tracking other branches -- for example, the "develop" branch, where
new feature development occurs -- you'll want to do the same operations for that
branch; simply substitute "develop" for "master".
### Working on a patch
We recommend you do each new feature or bugfix in a new branch. This simplifies
the task of code review as well as the task of merging your changes into the
canonical repository.
A typical workflow will then consist of the following:
1. Create a new local branch based off either your master or develop branch.
2. Switch to your new local branch. (This step can be combined with the
previous step with the use of `git checkout -b`.)
3. Do some work, commit, repeat as necessary.
4. Push the local branch to your remote repository.
5. Send a pull request.
The mechanics of this process are actually quite trivial. Below, we will
create a branch for fixing an issue in the tracker.
```console
$ git checkout -b hotfix/9295
Switched to a new branch 'hotfix/9295'
```
... do some work ...
```console
$ git commit
```
... write your log message ...
```console
$ git push {username} hotfix/9295:hotfix/9295
Counting objects: 38, done.
Delta compression using up to 2 threads.
Compression objects: 100% (18/18), done.
Writing objects: 100% (20/20), 8.19KiB, done.
Total 20 (delta 12), reused 0 (delta 0)
To ssh://git@github.com/{username}/zend-validator.git
b5583aa..4f51698 HEAD -> master
```
To send a pull request, you have two options.
If using GitHub, you can do the pull request from there. Navigate to
your repository, select the branch you just created, and then select the
"Pull Request" button in the upper right. Select the user/organization
"zendframework" (or whatever the upstream organization is) as the recipient.
#### What branch to issue the pull request against?
Which branch should you issue a pull request against?
- For fixes against the stable release, issue the pull request against the
"master" branch.
- For new features, or fixes that introduce new elements to the public API (such
as new public methods or properties), issue the pull request against the
"develop" branch.
### Branch Cleanup
As you might imagine, if you are a frequent contributor, you'll start to
get a ton of branches both locally and on your remote.
Once you know that your changes have been accepted to the master
repository, we suggest doing some cleanup of these branches.
- Local branch cleanup
```console
$ git branch -d <branchname>
```
- Remote branch removal
```console
$ git push {username} :<branchname>
```
================================================
FILE: docs/ISSUE_TEMPLATE.md
================================================
- [ ] I was not able to find an [open](https://github.com/zendframework/zend-validator/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-validator/issues?q=is%3Aclosed) issue matching what I'm seeing.
- [ ] This is not a question. (Questions should be asked on [chat](https://zendframework.slack.com/) ([Signup here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).)
Provide a narrative description of what you are trying to accomplish.
### Code to reproduce the issue
<!-- Please provide the minimum code necessary to recreate the issue -->
```php
```
### Expected results
<!-- What do you think should have happened? -->
### Actual results
<!-- What did you actually observe? -->
================================================
FILE: docs/PULL_REQUEST_TEMPLATE.md
================================================
Provide a narrative description of what you are trying to accomplish:
- [ ] Are you fixing a bug?
- [ ] Detail how the bug is invoked currently.
- [ ] Detail the original, incorrect behavior.
- [ ] Detail the new, expected behavior.
- [ ] Base your feature on the `master` branch, and submit against that branch.
- [ ] Add a regression test that demonstrates the bug, and proves the fix.
- [ ] Add a `CHANGELOG.md` entry for the fix.
- [ ] Are you creating a new feature?
- [ ] Why is the new feature needed? What purpose does it serve?
- [ ] How will users use the new feature?
- [ ] Base your feature on the `develop` branch, and submit against that branch.
- [ ] Add only one feature per pull request; split multiple features over multiple pull requests
- [ ] Add tests for the new feature.
- [ ] Add documentation for the new feature.
- [ ] Add a `CHANGELOG.md` entry for the new feature.
- [ ] Is this related to quality assurance?
<!-- Detail why the changes are necessary -->
- [ ] Is this related to documentation?
<!-- Is it a typographical and/or grammatical fix? -->
<!-- Is it new documentation? -->
================================================
FILE: docs/SUPPORT.md
================================================
# Getting Support
Zend Framework offers three support channels:
- For real-time questions, use our
[chat](https://zendframework-slack.herokuapp.com)
- For detailed questions (e.g., those requiring examples) use our
[forums](https://discourse.zendframework.com/c/questions/components)
- To report issues, use this repository's
[issue tracker](https://github.com/zendframework/zend-validator/issues/new)
**DO NOT** use the issue tracker to ask questions; use chat or the forums for
that. Questions posed to the issue tracker will be closed.
When reporting an issue, please include the following details:
- A narrative description of what you are trying to accomplish.
- The minimum code necessary to reproduce the issue.
- The expected results of exercising that code.
- The actual results received.
We may ask for additional details: what version of the library you are using,
and what PHP version was used to reproduce the issue.
You may also submit a failing test case as a pull request.
================================================
FILE: docs/book/index.md
================================================
../../README.md
================================================
FILE: docs/book/intro.md
================================================
# Introduction
zend-validator provides a set of commonly needed validators. It also provides a
simple validator chaining mechanism by which multiple validators may be applied
to a single datum in a user-defined order.
## What is a validator?
A validator examines its input with respect to some requirements and produces a
boolean result indicating whether the input successfully validates against the
requirements. If the input does not meet the requirements, a validator may
additionally provide information about which requirement(s) the input does not
meet.
For example, a web application might require that a username be between six and
twelve characters in length, and may only contain alphanumeric characters. A
validator can be used for ensuring that a username meets these requirements. If
a chosen username does not meet one or both of the requirements, it would be
useful to know which of the requirements the username fails to meet.
## Basic usage of validators
Having defined validation in this way provides the foundation for
`Zend\Validator\ValidatorInterface`, which defines two methods, `isValid()` and
`getMessages()`. The `isValid()` method performs validation upon the provided
value, returning `true` if and only if the value passes against the validation
criteria.
If `isValid()` returns `false`, the `getMessages()` method will return an array
of messages explaining the reason(s) for validation failure. The array keys are
short strings that identify the reasons for validation failure, and the array
values are the corresponding human-readable string messages. The keys and values
are class-dependent; each validation class defines its own set of validation
failure messages and the unique keys that identify them. Each class also has a
`const` definition that matches each identifier for a validation failure cause.
> ### Stateful validators
>
> The `getMessages()` methods return validation failure information only for the
> most recent `isValid()` call. Each call to `isValid()` clears any messages and
> errors caused by a previous `isValid()` call, because it's likely that each
> call to `isValid()` is made for a different input value.
The following example illustrates validation of an e-mail address:
```php
use Zend\Validator\EmailAddress;
$validator = new EmailAddress();
if ($validator->isValid($email)) {
// email appears to be valid
} else {
// email is invalid; print the reasons
foreach ($validator->getMessages() as $messageId => $message) {
printf("Validation failure '%s': %s\n", $messageId, $message);
}
}
```
## Customizing messages
Validator classes provide a `setMessage()` method with which you can specify the
format of a message returned by `getMessages()` in case of validation failure.
The first argument of this method is a string containing the error message. You
can include tokens in this string which will be substituted with data relevant
to the validator. The token `%value%` is supported by all validators; this is
substituted with the value you passed to `isValid()`. Other tokens may be
supported on a case-by-case basis in each validation class. For example, `%max%`
is a token supported by `Zend\Validator\LessThan`. The `getMessageVariables()`
method returns an array of variable tokens supported by the validator.
The second optional argument is a string that identifies the validation failure
message template to be set, which is useful when a validation class defines more
than one cause for failure. If you omit the second argument, `setMessage()`
assumes the message you specify should be used for the first message template
declared in the validation class. Many validation classes only have one error
message template defined, so there is no need to specify which message template
you are changing.
```php
use Zend\Validator\StringLength;
$validator = new StringLength(8);
$validator->setMessage(
'The string \'%value%\' is too short; it must be at least %min% characters',
StringLength::TOO_SHORT
);
if (! $validator->isValid('word')) {
$messages = $validator->getMessages();
echo current($messages);
// "The string 'word' is too short; it must be at least 8 characters"
}
```
You can set multiple messages using the `setMessages()` method. Its argument is
an array containing key/message pairs.
```php
use Zend\Validator\StringLength;
$validator = new StringLength(['min' => 8, 'max' => 12]);
$validator->setMessages([
StringLength::TOO_SHORT => 'The string \'%value%\' is too short',
StringLength::TOO_LONG => 'The string \'%value%\' is too long',
]);
```
If your application requires even greater flexibility with which it reports
validation failures, you can access properties by the same name as the message
tokens supported by a given validation class. The `value` property is always
available in a validator; it is the value you specified as the argument of
`isValid()`. Other properties may be supported on a case-by-case basis in each
validation class.
```php
use Zend\Validator\StringLength;
$validator = new StringLength(['min' => 8, 'max' => 12]);
if (! $validator->isValid('word')) {
printf(
"Word failed: %s; its length is not between %d and %d\n",
$validator->value,
$validator->min,
$validator->max
);
}
```
## Translating messages
> ### Installation requirements
>
> The translation of validator messages depends on the zend-i18n component, so
> be sure to have it installed before getting started:
>
> ```bash
> $ composer require zendframework/zend-i18n
> ```
Validator classes provide a `setTranslator()` method with which you can specify
an instance of `Zend\Validator\Translator\TranslatorInterface` which will
translate the messages in case of a validation failure. The `getTranslator()`
method returns the translator instance. `Zend\Mvc\I18n\Translator` provides an
implementation compatible with the validator component.
```php
use Zend\Mvc\I18n\Translator;
use Zend\Validator\StringLength;
$validator = new StringLength(['min' => 8, 'max' => 12]);
$translate = new Translator();
// configure the translator...
$validator->setTranslator($translate);
```
With the static `AbstractValidator::setDefaultTranslator()` method you can set a
instance of `Zend\Validator\Translator\TranslatorInterface` which will be used
for all validation classes, and can be retrieved with `getDefaultTranslator()`.
This prevents the need for setting a translator manually with each validator.
```php
use Zend\Mvc\I18n\Translator;
use Zend\Validator\AbstractValidator;
$translate = new Translator();
// configure the translator...
AbstractValidator::setDefaultTranslator($translate);
```
Sometimes it is necessary to disable the translator within a validator. To
achieve this you can use the `setDisableTranslator()` method, which accepts a
boolean parameter, and `isTranslatorDisabled()` to get the set value.
```php
use Zend\Validator\StringLength;
$validator = new StringLength(['min' => 8, 'max' => 12]);
if (! $validator->isTranslatorDisabled()) {
$validator->setDisableTranslator();
}
```
It is also possible to use a translator instead of setting own messages with
`setMessage()`. But doing so, you should keep in mind, that the translator works
also on messages you set your own.
> ### Translation compatibility
>
> In versions 2.0 - 2.1, `Zend\Validator\AbstractValidator` implemented
> `Zend\I18n\Translator\TranslatorAwareInterface` and accepted instances of
> `Zend\I18n\Translator\Translator`. Starting in version 2.2.0, zend-validator
> now defines a translator interface, > `Zend\Validator\Translator\TranslatorInterface`,
> as well as it's own -aware variant, > `Zend\Validator\Translator\TranslatorAwareInterface`.
> This was done to reduce dependencies for the component, and follows the
> principal of Separated Interfaces.
>
> The upshot is that if you are migrating from a pre-2.2 version, and receiving
> errors indicating that the translator provided does not implement
> `Zend\Validator\Translator\TranslatorInterface`, you will need to make a
> change to your code.
>
> An implementation of `Zend\Validator\Translator\TranslatorInterface` is
> provided in `Zend\Mvc\I18n\Translator`, which also extends
> `Zend\I18n\Translator\Translator`. This version can be instantiated and used
> just as the original `Zend\I18n` version.
>
> A new service has also been registered with the MVC, `MvcTranslator`, which
> will return this specialized, bridge instance.
>
> Most users should see no issues, as `Zend\Validator\ValidatorPluginManager`
> has been modified to use the `MvcTranslator` service internally, which is how
> most developers were getting the translator instance into validators in the
> first place. You will only need to change code if you were manually injecting
> the instance previously.
================================================
FILE: docs/book/messages.md
================================================
# Validation Messages
Each validator based on `Zend\Validator\ValidatorInterface` provides one or
multiple messages in the case of a failed validation. You can use this
information to set your own messages, or to translate existing messages which a
validator could return to something different.
Validation messages are defined as constant/template pairs, with the constant
representing a translation key. Such constants are defined per-class. Let's
look into `Zend\Validator\GreaterThan` for a descriptive example:
```php
protected $messageTemplates = [
self::NOT_GREATER => "'%value%' is not greater than '%min%'",
];
```
The constant `self::NOT_GREATER` refers to the failure and is used as the
message key, and the message template itself is used as the value within the
message array.
You can retrieve all message templates from a validator by using the
`getMessageTemplates()` method. It returns the above array containing all
messages a validator could return in the case of a failed validation.
```php
$validator = new Zend\Validator\GreaterThan();
$messages = $validator->getMessageTemplates();
```
Using the `setMessage()` method you can set another message to be returned in
case of the specified failure.
```php
use Zend\Validator\GreaterThan;
$validator = new GreaterThan();
$validator->setMessage('Please enter a lower value', GreaterThan::NOT_GREATER);
```
The second parameter defines the failure which will be overridden. When you omit
this parameter, then the given message will be set for all possible failures of
this validator.
## Using pre-translated validation messages
zend-validator is shipped with more than 45 different validators with more than
200 failure messages. It can be a tedious task to translate all of these
messages. For your convenience, pre-translated messages are provided in the
[zendframework/zend-i18n-resources](https://docs.zendframework.com/zend-i18n-resources/)
package:
```bash
$ composer require zendframework/zend-i18n-resources
```
To translate all validation messages to German for example, attach a translator
to `Zend\Validator\AbstractValidator` using these resource files.
```php
use Zend\I18n\Translator\Resources;
use Zend\Mvc\I18n\Translator;
use Zend\Validator\AbstractValidator;
$translator = new Zend\Mvc\I18n\Translator();
$translator->addTranslationFilePattern(
'phpArray',
Resources::getBasePath(),
Resources::getPatternForValidator()
);
AbstractValidator::setDefaultTranslator($translator);
```
> ### Supported languages
>
> The supported languages may not be complete. New languages will be added with
> each release. Additionally feel free to use the existing resource files to
> make your own translations.
>
> You could also use these resource files to rewrite existing translations. So
> you are not in need to create these files manually yourself.
## Limit the size of a validation message
Sometimes it is necessary to limit the maximum size a validation message can
have; as an example, when your view allows a maximum size of 100 chars to be
rendered on one line. To enable this, `Zend\Validator\AbstractValidator`
is able to automatically limit the maximum returned size of a validation
message.
To get the actual set size use `Zend\Validator\AbstractValidator::getMessageLength()`.
If it is `-1`, then the returned message will not be truncated. This is default
behaviour.
To limit the returned message size, use `Zend\Validator\AbstractValidator::setMessageLength()`.
Set it to any integer size you need. When the returned message exceeds the set
size, then the message will be truncated and the string `**...**` will be added
instead of the rest of the message.
```php
Zend\Validator\AbstractValidator::setMessageLength(100);
```
> ### Where is this parameter used?
>
> The set message length is used for all validators, even for self defined ones,
> as long as they extend `Zend\Validator\AbstractValidator`.
================================================
FILE: docs/book/set.md
================================================
# Standard Validation Classes
The following validators come with the zend-validator distribution.
- [Barcode](validators/barcode.md)
- [Between](validators/between.md)
- [Callback](validators/callback.md)
- [CreditCard](validators/credit-card.md)
- [Date](validators/date.md)
- [RecordExists and NoRecordExists (database)](validators/db.md)
- [Digits](validators/digits.md)
- [EmailAddress](validators/email-address.md)
- [Explode](validators/explode.md)
- [File Validation Classes](validators/file/intro.md)
- [GreaterThan](validators/greater-than.md)
- [Hex](validators/hex.md)
- [Hostname](validators/hostname.md)
- [Iban](validators/iban.md)
- [Identical](validators/identical.md)
- [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)
- [Regex](validators/regex.md)
- [Sitemap](validators/sitemap.md)
- [Step](validators/step.md)
- [StringLength](validators/string-length.md)
- [Timezone](validators/timezone.md)
- [Uri](validators/uri.md)
- [Uuid](validators/uuid.md)
## Additional validators
Several other components offer validators as well:
- [zend-i18n](https://docs.zendframework.com/zend-i18n/validators/)
## Deprecated Validators
### Ccnum
The `Ccnum` validator has been deprecated in favor of the `CreditCard`
validator. For security reasons you should use `CreditCard` instead of `Ccnum`.
================================================
FILE: docs/book/validator-chains.md
================================================
# Validator Chains
## Basic Usage
> ### Installation requirements
>
> The validator chain depends on the zend-servicemanager component, so be sure
> to have it installed before getting started:
>
> ```bash
> $ composer require zendframework/zend-servicemanager
> ```
Often, multiple validations should be applied to some value in a particular
order. The following code demonstrates a way to solve the example from the
[introduction](intro.md), where a username must be between 6 and 12 alphanumeric
characters:
```php
use Zend\I18n\Validator\Alnum;
use Zend\Validator\StringLength;
use Zend\Validator\ValidatorChain;
// Create a validator chain and add validators to it
$validatorChain = new ValidatorChain();
$validatorChain->attach(new StringLength(['min' => 6, 'max' => 12]));
$validatorChain->attach(new Alnum());
// Validate the username
if ($validatorChain->isValid($username)) {
// username passed validation
} else {
// username failed validation; print reasons
foreach ($validatorChain->getMessages() as $message) {
echo "$message\n";
}
}
```
Validators are run in the order they were added to the `ValidatorChain`. In the
above example, the username is first checked to ensure that its length is
between 6 and 12 characters, and then it is checked to ensure that it contains
only alphanumeric characters. The second validation, for alphanumeric
characters, is performed regardless of whether the first validation, for length
between 6 and 12 characters, succeeds. This means that if both validations fail,
`getMessages()` will return failure messages from both validators.
In some cases, it makes sense to have a validator *break the chain* if its
validation process fails. `ValidatorChain` supports such use cases with the
second parameter to the `attach()` method. By setting `$breakChainOnFailure` to
`true`, if the validator fails, it will short-circuit execution of the chain,
preventing subsequent validators from executing. If the above example were
written as follows, then the alphanumeric validation would not occur if the
string length validation fails:
```php
$chain->attach(new StringLength(['min' => 6, 'max' => 12]), true);
$chain->attach(new Alnum());
```
Any object that implements `Zend\Validator\ValidatorInterface` may be used in a
validator chain.
## Setting Validator Chain Order
For each validator added to the `ValidatorChain`, you can set a *priority* to
define the chain order. The default value is `1`. Higher values indicate earlier
execution, while lower values execute later; use negative values to force late
execution.
In the following example, the username is first checked to ensure that its
length is between 7 and 9 characters, and then it is checked to ensure that its
length is between 3 and 5 characters.
```php
use Zend\I18n\Validator\Alnum;
use Zend\Validator\StringLength;
use Zend\Validator\ValidatorChain;
$username = 'ABCDFE';
// Create a validator chain and add validators to it
$validatorChain = new ValidatorChain();
$validatorChain->attach(
new StringLength(['min' => 3, 'max' => 5]),
true, // break chain on failure
1
);
$validatorChain->attach(
new StringLength(['min' => 7, 'max' => 9]),
true, // break chain on failure
2 // higher priority!
);
// Validate the username
if ($validatorChain->isValid($username)) {
// username passed validation
echo "Success";
} else {
// username failed validation; print reasons
foreach ($validatorChain->getMessages() as $message) {
echo "$message\n";
}
}
// This first example will display: The input is less than 7 characters long
```
================================================
FILE: docs/book/validators/barcode.md
================================================
# Barcode Validator
`Zend\Validator\Barcode` allows you to check if a given value can be represented
as a barcode.
## Supported barcodes
`Zend\Validator\Barcode` supports multiple barcode standards and can be extended
with proprietary barcode implementations. The following barcode standards are
supported:
### CODABAR
Also known as Code-a-bar.
This barcode has no length limitation. It supports only digits, and 6 special
chars. Codabar is a self-checking barcode. This standard is very old. Common use
cases are within airbills or photo labs where multi-part forms are used with
dot-matrix printers.
### CODE128
CODE128 is a high density barcode.
This barcode has no length limitation. It supports the first 128 ascii
characters. When used with printing characters it has an checksum which is
calculated modulo 103. This standard is used worldwide as it supports upper and
lowercase characters.
### CODE25
Often called "two of five" or "Code25 Industrial".
This barcode has no length limitation. It supports only digits, and the last
digit can be an optional checksum which is calculated with modulo 10. This
standard is very old and nowadays not often used. Common use cases are within
the industry.
### CODE25INTERLEAVED
Often called "Code 2 of 5 Interleaved".
This standard is a variant of CODE25. It has no length limitation, but it must
contain an even amount of characters. It supports only digits, and the last
digit can be an optional checksum which is calculated with modulo 10. It is used
worldwide and common on the market.
### CODE39
CODE39 is one of the oldest available codes.
This barcode has a variable length. It supports digits, upper cased alphabetical
characters and 7 special characters like whitespace, point and dollar sign. It
can have an optional checksum which is calculated with modulo 43. This standard
is used worldwide and common within the industry.
### CODE39EXT
CODE39EXT is an extension of CODE39.
This barcode has the same properties as CODE39. Additionally it allows the usage
of all 128 ASCII characters. This standard is used worldwide and common within
the industry.
### CODE93
CODE93 is the successor of CODE39.
This barcode has a variable length. It supports digits, alphabetical characters
and 7 special characters. It has an optional checksum which is calculated with
modulo 47 and contains 2 characters. This standard produces a denser code than
CODE39 and is more secure.
### CODE93EXT
CODE93EXT is an extension of CODE93.
This barcode has the same properties as CODE93. Additionally it allows the usage
of all 128 ASCII characters. This standard is used worldwide and common within
the industry.
### EAN2
EAN is the shortcut for "European Article Number".
These barcode must have 2 characters. It supports only digits and does not have
a checksum. This standard is mainly used as addition to EAN13 (ISBN) when
printed on books.
### EAN5
EAN is the shortcut for "European Article Number".
These barcode must have 5 characters. It supports only digits and does not have
a checksum. This standard is mainly used as addition to EAN13 (ISBN) when
printed on books.
### EAN8
EAN is the shortcut for "European Article Number".
These barcode can have 7 or 8 characters. It supports only digits. When it has a
length of 8 characters it includes a checksum. This standard is used worldwide
but has a very limited range. It can be found on small articles where a longer
barcode could not be printed.
### EAN12
EAN is the shortcut for "European Article Number".
This barcode must have a length of 12 characters. It supports only digits, and
the last digit is always a checksum which is calculated with modulo 10. This
standard is used within the USA and common on the market. It has been superseded
by EAN13.
### EAN13
EAN is the shortcut for "European Article Number".
This barcode must have a length of 13 characters. It supports only digits, and
the last digit is always a checksum which is calculated with modulo 10. This
standard is used worldwide and common on the market.
### EAN14
EAN is the shortcut for "European Article Number".
This barcode must have a length of 14 characters. It supports only digits, and
the last digit is always a checksum which is calculated with modulo 10. This
standard is used worldwide and common on the market. It is the successor for
EAN13.
### EAN18
EAN is the shortcut for "European Article Number".
This barcode must have a length of 18 characters. It support only digits. The
last digit is always a checksum digit which is calculated with modulo 10. This
code is often used for the identification of shipping containers.
### GTIN12
GTIN is the shortcut for "Global Trade Item Number".
This barcode uses the same standard as EAN12 and is its successor. It's commonly
used within the USA.
### GTIN13
GTIN is the shortcut for "Global Trade Item Number".
This barcode uses the same standard as EAN13 and is its successor. It is used
worldwide by industry.
### GTIN14
GTIN is the shortcut for "Global Trade Item Number".
This barcode uses the same standard as EAN14 and is its successor. It is used
worldwide and common on the market.
### IDENTCODE
Identcode is used by Deutsche Post and DHL. It's an specialized implementation of Code25.
This barcode must have a length of 12 characters. It supports only digits, and
the last digit is always a checksum which is calculated with modulo 10. This
standard is mainly used by the companies DP and DHL.
### INTELLIGENTMAIL
Intelligent Mail is a postal barcode.
This barcode can have a length of 20, 25, 29 or 31 characters. It supports only
digits, and contains no checksum. This standard is the successor of PLANET and
POSTNET. It is mainly used by the United States Postal Services.
### ISSN
ISSN is the abbreviation for International Standard Serial Number.
This barcode can have a length of 8 or 13 characters. It supports only digits,
and the last digit must be a checksum digit which is calculated with modulo 11.
It is used worldwide for printed publications.
### ITF14
ITF14 is the GS1 implementation of an Interleaved Two of Five bar code.
This barcode is a special variant of Interleaved 2 of 5. It must have a length
of 14 characters and is based on GTIN14. It supports only digits, and the last
digit must be a checksum digit which is calculated with modulo 10. It is used
worldwide and common within the market.
### LEITCODE
Leitcode is used by Deutsche Post and DHL. It's an specialized implementation of Code25.
This barcode must have a length of 14 characters. It supports only digits, and
the last digit is always a checksum which is calculated with modulo 10. This
standard is mainly used by the companies DP and DHL.
### PLANET
Planet is the abbreviation for Postal Alpha Numeric Encoding Technique.
This barcode can have a length of 12 or 14 characters. It supports only digits,
and the last digit is always a checksum. This standard is mainly used by the
United States Postal Services.
### POSTNET
Postnet is used by the US Postal Service.
This barcode can have a length of 6, 7, 10 or 12 characters. It supports only
digits, and the last digit is always a checksum. This standard is mainly used by
the United States Postal Services.
### ROYALMAIL
Royalmail is used by Royal Mail.
This barcode has no defined length. It supports digits, uppercase letters, and
the last digit is always a checksum. This standard is mainly used by Royal Mail
for their Cleanmail Service. It is also called RM4SCC.
### SSCC
SSCC is the shortcut for "Serial Shipping Container Code".
This barcode is a variant of EAN barcode. It must have a length of 18 characters
and supports only digits. The last digit must be a checksum digit which is
calculated with modulo 10. It is commonly used by the transport industry.
### UPCA
UPC is the shortcut for "Universal Product Code".
This barcode preceded EAN13. It must have a length of 12 characters and supports
only digits. The last digit must be a checksum digit which is calculated with
modulo 10. It is commonly used within the USA.
### UPCE
UPCE is the short variant from UPCA.
This barcode is a smaller variant of UPCA. It can have a length of 6, 7 or 8
characters and supports only digits. When the barcode is 8 chars long it
includes a checksum which is calculated with modulo 10. It is commonly used with
small products where a UPCA barcode would not fit.
## Supported options
The following options are supported for `Zend\Validator\Barcode`:
- `adapter`: Sets the barcode adapter which will be used. Supported are all
above noted adapters. When using a self defined adapter, then you have to set
the complete class name.
- `checksum`: `TRUE` when the barcode should contain a checksum. The default
value depends on the used adapter. Note that some adapters don't allow to set
this option.
- `options`: Defines optional options for a self written adapters.
## Basic usage
To validate if a given string is a barcode you must know its type. See the
following example for an EAN13 barcode:
```php
$valid = new Zend\Validator\Barcode('EAN13');
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
## Optional checksum
Some barcodes can be provided with an optional checksum. These barcodes would be
valid even without checksum. Still, when you provide a checksum, then you should
also validate it. By default, these barcode types perform no checksum
validation. By using the `checksum` option you can define if the checksum will
be validated or ignored.
```php
$valid = new Zend\Validator\Barcode([
'adapter' => 'EAN13',
'checksum' => false,
]);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
> ### Reduced security by disabling checksum validation
>
> By switching off checksum validation you will also reduce the security of the
> used barcodes. Additionally you should note that you can also turn off the
> checksum validation for those barcode types which must contain a checksum
> value. Barcodes which would not be valid could then be returned as valid even
> if they are not.
## Writing custom adapters
You may write custom barcode validators for usage with `Zend\Validator\Barcode`;
this is often necessary when dealing with proprietary barcode types. To write
your own barcode validator, you need the following information.
- `Length`: The length your barcode must have. It can have one of the following
values:
- `Integer`: A value greater 0, which means that the barcode must have this
length.
- `-1`: There is no limitation for the length of this barcode.
- `"even"`: The length of this barcode must have a even amount of digits.
- `"odd"`: The length of this barcode must have a odd amount of digits.
- `array`: An array of integer values. The length of this barcode must have
one of the set array values.
- `Characters`: A string which contains all allowed characters for this barcode.
Also the integer value 128 is allowed, which means the first 128 characters of
the ASCII table.
- `Checksum`: A string which will be used as callback for a method which does
the checksum validation.
Your custom barcode validator must extend `Zend\Validator\Barcode\AbstractAdapter`
or implement `Zend\Validator\Barcode\AdapterInterface`.
As an example, let's create a validator that expects an even number of
characters that include all digits and the letters 'ABCDE', and which requires a
checksum.
```php
namespace My\Barcode;
use Zend\Validator\Barcode;
use Zend\Validator\Barcode\AbstractAdapter;
class MyBar extends AbstractAdapter
{
protected $length = 'even';
protected $characters = '0123456789ABCDE';
protected $checksum = 'mod66';
protected function mod66($barcode)
{
// do some validations and return a boolean
}
}
$valid = Barcode(MyBar::class);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
================================================
FILE: docs/book/validators/between.md
================================================
# Between Validator
`Zend\Validator\Between` allows you to validate if a given value is between two
other values.
> ### Only supports number validation
>
> `Zend\Validator\Between` supports only the validation of numbers. Strings or
> dates can not be validated with this validator.
## Supported options
The following options are supported for `Zend\Validator\Between`:
- `inclusive`: Defines if the validation is inclusive of the minimum and maximum
border values, or exclusive. It defaults to `true`.
- `max`: Sets the maximum border for the validation.
- `min`: Sets the minimum border for the validation.
## Default behaviour
Per default, this validator checks if a value is between `min` and `max` where
both border values are allowed as value.
```php
$valid = new Zend\Validator\Between(['min' => 0, 'max' => 10]);
$value = 10;
$result = $valid->isValid($value);
// returns true
```
In the above example, the result is `true` due to the reason that the default
search is inclusive of the border values. This means in our case that any value
from '0' to '10' is allowed; values like '-1' and '11' will return `false`.
## Excluding border values
Sometimes it is useful to validate a value by excluding the border values. See
the following example:
```php
$valid = new Zend\Validator\Between([
'min' => 0,
'max' => 10,
'inclusive' => false,
]);
$value = 10;
$result = $valid->isValid($value);
// returns false
```
The example above is almost identical to our first example, but we now exclue
the border values; as such, the values '0' and '10' are no longer allowed and
will return `false`.
================================================
FILE: docs/book/validators/callback.md
================================================
# Callback Validator
`Zend\Validator\Callback` allows you to provide a callback with which to
validate a given value.
## Supported options
The following options are supported for `Zend\Validator\Callback`:
- `callback`: Sets the callback which will be called for the validation.
- `options`: Sets the additional options which will be given to the validator
and/or callback.
## Basic usage
The simplest use case is to pass a function as a callback. Consider the
following function:
```php
function myMethod($value)
{
// some validation
return true;
}
```
To use it within `Zend\Validator\Callback`, pass it to the constructor
```php
$valid = new Zend\Validator\Callback('myMethod');
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
## Usage with closures
The `Callback` validator supports any PHP callable, including PHP
[closures](http://php.net/functions.anonymous).
```php
$valid = new Zend\Validator\Callback(function($value) {
// some validation
return true;
});
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
## Usage with class-based callbacks
Of course it's also possible to use a class method as callback. Consider the
following class definition:
```php
class MyClass
{
public function myMethod($value)
{
// some validation
return true;
}
}
```
To use it with the `Callback` validator, pass a callable using an instance of
the class:
```php
$valid = new Zend\Validator\Callback([new MyClass, 'myMethod']);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
You may also define a static method as a callback. Consider the following class
definition and validator usage:
```php
class MyClass
{
public static function test($value)
{
// some validation
return true;
}
}
$valid = new Zend\Validator\Callback(MyClass::class, 'test']);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
Finally, you may define the magic method `__invoke()` in your class. If you do
so, you can provide a class instance itself as the callback:
```php
class MyClass
{
public function __invoke($value)
{
// some validation
return true;
}
}
$valid = new Zend\Validator\Callback(new MyClass());
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
## Adding options
`Zend\Validator\Callback` also allows the usage of options which are provided as
additional arguments to the callback.
Consider the following class and method definition:
```php
class MyClass
{
public static function myMethod($value, $option)
{
// some validation
return true;
}
/**
* Or, to use with contextual validation
*/
public static function myMethod($value, $context, $option)
{
// some validation
return true;
}
}
```
There are two ways to inform the validator of additional options: pass them in
the constructor, or pass them to the `setOptions()` method.
To pass them to the constructor, you would need to pass an array containing two
keys, `callback` and `callbackOptions`:
```php
$valid = new Zend\Validator\Callback([
'callback' => [MyClass::class, 'myMethod'],
'callbackOptions' => $options,
]);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
Otherwise, you may pass them to the validator after instantiation:
```php
$valid = new Zend\Validator\Callback([MyClass::class, 'myMethod']);
$valid->setOptions($options);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
When there are additional values given to `isValid()`, then these values will be
passed as an additional argument:
```php
$valid = new Zend\Validator\Callback([MyClass::class, 'myMethod']);
$valid->setOptions($options);
if ($valid->isValid($input, $context)) {
// input appears to be valid
} else {
// input is invalid
}
```
When making the call to the callback, the value to be validated will always be
passed as the first argument to the callback followed by all other values given
to `isValid()`; all other options will follow it. The amount and type of options
which can be used is not limited.
================================================
FILE: docs/book/validators/credit-card.md
================================================
# CreditCard Validator
`Zend\Validator\CreditCard` allows you to validate if a given value could be a
credit card number.
A credit card contains several items of metadata, including a hologram, account
number, logo, expiration date, security code, and the card holder name. The
algorithms for verifying the combination of metadata are only known to the
issuing company, and should be verified with them for purposes of payment.
However, it's often useful to know whether or not a given number actually falls
within the ranges of possible numbers **prior** to performing such verification,
and, as such, `Zend\Validator\CreditCard` verifies that the credit card number
provided is well-formed.
For those cases where you have a service that can perform comprehensive
verification, `Zend\Validator\CreditCard` also provides the ability to attach a
service callback to trigger once the credit card number has been deemed valid;
this callback will then be triggered, and its return value will determine
overall validity.
The following issuing institutes are accepted:
- American Express
- China UnionPay
- Diners Club Card Blanche
- Diners Club International
- Diners Club US and Canada
- Discover Card
- JCB
- Laser
- Maestro
- MasterCard
- Solo
- Visa
- Visa Electron
- Russia Mir
> ### Invalid institutes
>
> The institutes **Bankcard** and **Diners Club enRoute** no longer exist, and
> are treated as invalid.
>
> **Switch** has been rebranded to **Visa** and is therefore also treated as
> invalid.
## Supported options
The following options are supported for `Zend\Validator\CreditCard`:
- `service`: A callback to an online service which will additionally be used for
the validation.
- `type`: The type of credit card which will be validated. See the below list of
institutes for details.
## Basic usage
There are several credit card institutes which can be validated by
`Zend\Validator\CreditCard`. Per default, all known institutes will be accepted.
See the following example:
```php
$valid = new Zend\Validator\CreditCard();
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
The above example would validate against all known credit card institutes.
## Accepting only specific credit cards
Sometimes it is necessary to accept only specific credit card institutes instead
of all; e.g., when you have a webshop which accepts only Visa and American
Express cards. `Zend\Validator\CreditCard` allows you to do exactly this by
limiting it to exactly these institutes.
To use a limitation you can either provide specific institutes at initiation, or
afterwards by using `setType()`. Each can take several arguments.
You can provide a single institute:
```php
use Zend\Validator\CreditCard;
$valid = new CreditCard(CreditCard::AMERICAN_EXPRESS);
```
When you want to allow multiple institutes, then you can provide them as array:
```php
use Zend\Validator\CreditCard;
$valid = new CreditCard([
CreditCard::AMERICAN_EXPRESS,
CreditCard::VISA
]);
```
And, as with all validators, you can also pass an associative array of options
or an instance of `Traversable`. In this case you have to provide the institutes
with the `type` array key as demostrated here:
```php
use Zend\Validator\CreditCard;
$valid = new CreditCard([
'type' => [CreditCard::AMERICAN_EXPRESS]
]);
```
You can also manipulate institutes after instantiation by using the methods
`setType()`, `addType()`, and `getType()`.
```php
use Zend\Validator\CreditCard;
$valid = new CreditCard();
$valid->setType([
CreditCard::AMERICAN_EXPRESS,
CreditCard::VISA
]);
```
> ### Default institute
>
> When no institute is given at initiation then `ALL` will be used, which sets
> all institutes at once.
>
> In this case the usage of `addType()` is useless because all institutes are
> already added.
## Validation using APIs
As said before `Zend\Validator\CreditCard` will only validate the credit card
number. Fortunately, some institutes provide online APIs which can validate a
credit card number by using algorithms which are not available to the public.
Most of these services are paid services. Therefore, this check is deactivated
per default.
When you have access to such an API, then you can use it as an add on for
`Zend\Validator\CreditCard` and increase the security of the validation.
To do so, provide a callback to invoke when generic validation has passed. This
prevents the API from being called for invalid numbers, which increases the
performance of the application.
`setService()` sets a new service, and `getService()` returns the set service.
As a configuration option, you can give the array key `service` at instantiatio.
For details about possible options, read the
[Callback validator documentation](callback.md).
```php
use Zend\Validator\CreditCard;
// Your service class
class CcService
{
public function checkOnline($cardnumber, $types)
{
// some online validation
}
}
// The validation
$service = new CcService();
$valid = new CreditCard(CreditCard::VISA);
$valid->setService([$service, 'checkOnline']);
```
The callback method will be called with the credit card number as the first
parameter, and the accepted types as the second parameter.
================================================
FILE: docs/book/validators/date.md
================================================
# Date Validator
`Zend\Validator\Date` allows you to validate if a given value contains a date.
## Supported options
The following options are supported for `Zend\Validator\Date`:
- `format`: Sets the format which is used to write the date.
- `locale`: Sets the locale which will be used to validate date values.
## Default date validation
The easiest way to validate a date is by using the default date format,
`Y-m-d`.
```php
$validator = new Zend\Validator\Date();
$validator->isValid('2000-10-10'); // returns true
$validator->isValid('10.10.2000'); // returns false
```
## Specifying a date format
`Zend\Validator\Date` also supports custom date formats. When you want to
validate such a date, use the `format` option. This option accepts any format
allowed by the PHP [DateTime::createFromFormat()](http://php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters) method.
```php
$validator = new Zend\Validator\Date(['format' => 'Y']);
$validator->isValid('2010'); // returns true
$validator->isValid('May'); // returns false
```
## Strict mode
- **Since 2.13.0**
By default, `Zend\Validator\Date` only validates that it can convert the
provided value to a valid `DateTime` value.
If you want to require that the date is specified in a specific format, you can
provide both the [date format](#specifying-a-date-format) and the `strict`
options. In such a scenario, the value must both be covertable to a `DateTime`
value **and** be in the same format as provided to the validator. (Generally,
this will mean the value must be a string.)
```php
$validator = new Zend\Validator\Date(['format' => 'Y-m-d', 'strict' => true]);
$validator->isValid('2010-10-10'); // returns true
$validator->isValid(new DateTime('2010-10-10)); // returns false; value is not a string
$validator->isValid('2010.10.10'); // returns false; format differs
```
================================================
FILE: docs/book/validators/db.md
================================================
# Db\\RecordExists and Db\\NoRecordExists Validators
`Zend\Validator\Db\RecordExists` and `Zend\Validator\Db\NoRecordExists` provide
a means to test whether a record exists in a given table of a database, with a
given value.
> ### Installation requirements
>
> `Zend\Validator\Db\NoRecordExists` and `Zend\Validator\Db\RecordExists`
> depends on the zend-db component, so be sure to have it installed before
> getting started:
>
> ```bash
> $ composer require zendframework/zend-db
> ```
## Supported options
The following options are supported for `Zend\Validator\Db\NoRecordExists` and
`Zend\Validator\Db\RecordExists`:
- `adapter`: The database adapter that will be used for the search.
- `exclude`: Sets records that will be excluded from the search.
- `field`: The database field within this table that will be searched for the record.
- `schema`: Sets the schema that will be used for the search.
- `table`: The table that will be searched for the record.
## Basic usage
An example of basic usage of the validators:
```php
// Check that the email address exists in the database
$validator = new Zend\Validator\Db\RecordExists([
'table' => 'users',
'field' => 'emailaddress',
'adapter' => $dbAdapter,
]);
if ($validator->isValid($emailaddress)) {
// email address appears to be valid
} else {
// email address is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
```
The above will test that a given email address is in the database table. If no
record is found containing the value of `$emailaddress` in the specified column,
then an error message is displayed.
```php
// Check that the username is not present in the database
$validator = new Zend\Validator\Db\NoRecordExists([
'table' => 'users',
'field' => 'username',
'adapter' => $dbAdapter,
]);
if ($validator->isValid($username)) {
// username appears to be valid
} else {
// username is invalid; print the reason
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
```
The above will test that a given username is *not* in the database table. If a
record is found containing the value of `$username` in the specified column,
then an error message is displayed.
## Excluding records
`Zend\Validator\Db\RecordExists` and `Zend\Validator\Db\NoRecordExists` also
provide a means to test the database, excluding a part of the table, either by
providing a `WHERE` clause as a string, or an array with the keys `field` and
`value`.
When providing an array for the exclude clause, the `!=` operator is used, so
you can check the rest of a table for a value before altering a record (for
example on a user profile form)
```php
// Check no other users have the username
$user_id = $user->getId();
$validator = new Zend\Validator\Db\NoRecordExists([
'table' => 'users',
'field' => 'username',
'exclude' => [
'field' => 'id',
'value' => $user_id,
],
]);
if ($validator->isValid($username)) {
// username appears to be valid
} else {
// username is invalid; print the reason
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
```
The above example will check the table to ensure no records other than the one
where `id = $user_id` contains the value `$username`.
You can also provide a string to the exclude clause so you can use an operator
other than `!=`. This can be useful for testing against composite keys.
```php
$email = 'user@example.com';
$clause = $dbAdapter->quoteIdentifier('email') . ' = ' . $dbAdapter->quoteValue($email);
$validator = new Zend\Validator\Db\RecordExists([
'table' => 'users',
'field' => 'username',
'adapter' => $dbAdapter,
'exclude' => $clause,
]);
if ($validator->isValid($username)) {
// username appears to be valid
} else {
// username is invalid; print the reason
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
```
The above example will check the `users` table to ensure that only a record with
both the username `$username` and with the email `$email` is valid.
## Database Schemas
You can specify a schema within your database for adapters such as PostgreSQL
and DB/2 by supplying an array with `table` and `schema` keys, as demonstrated
below:
```php
$validator = new Zend\Validator\Db\RecordExists([
'table' => 'users',
'schema' => 'my',
'field' => 'id',
]);
```
## Using a Select object
It is also possible to supply the validators with a `Zend\Db\Sql\Select` object
in place of options. The validator then uses this object instead of building its
own. This allows for greater flexibility with selection of records used for
validation.
```php
use Zend\Db\Sql\Select;
use Zend\Validator\Db\RecordExists;
$select = new Select();
$select
->from('users')
->where->equalTo('id', $user_id)
->where->equalTo('email', $email);
$validator = new RecordExists($select);
// We still need to set our database adapter
$validator->setAdapter($dbAdapter);
// Validation is then performed as usual
if ($validator->isValid($username)) {
// username appears to be valid
} else {
// username is invalid; print the reason
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
```
The above example will check the `users` table to ensure that only a record with
both the username `$username` and with the email `$email` is valid.
================================================
FILE: docs/book/validators/digits.md
================================================
# Digits Validator
`Zend\Validator\Digits` validates if a given value contains only digits.
> ### Installation requirements
>
> `Zend\Validator\Digits` depends on the zend-filter component, so be sure to
> have it installed before getting started:
>
> ```bash
> $ composer require zendframework/zend-filter
> ```
## Supported options
There are no additional options for `Zend\Validator\Digits`:
## Validating digits
To validate if a given value contains only digits and no other characters,
call the validator as shown below:
```php
$validator = new Zend\Validator\Digits();
$validator->isValid("1234567890"); // returns true
$validator->isValid(1234); // returns true
$validator->isValid('1a234'); // returns false
```
> ### Validating numbers
>
> When you want to validate numbers or numeric values, be aware that this
> validator only validates *digits*. This means that any other sign like a
> thousand separator or a comma will not pass this validator. In this case you
> should use `Zend\I18n\Validator\IsInt` or `Zend\I18n\Validator\IsFloat`.
================================================
FILE: docs/book/validators/email-address.md
================================================
# EmailAddress Validator
`Zend\Validator\EmailAddress` allows you to validate an email address. The
validator first splits the email address on `local-part @ hostname` and attempts
to match these against known specifications for email addresses and hostnames.
## Basic usage
A basic example of usage is below:
```php
$validator = new Zend\Validator\EmailAddress();
if ($validator->isValid($email)) {
// email appears to be valid
} else {
// email is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
```
This will match the email address `$email` and on failure populate
`getMessages()` with useful error messages.
## Supported Options
`Zend\Validator\EmailAddress` supports several options which can either be set
at instantiation, by giving an array with the related options, or afterwards, by
using `setOptions()`. The following options are supported:
- `allow`: Defines which type of domain names are accepted. This option is used
in conjunction with the hostnameValidator option to set the hostname validator.
Possible values of this option defined in [Hostname](hostname.md) validator's
`ALLOW_*` constants:
- `ALLOW_DNS` (default) - Allows Internet domain names _(e.g. example.com)_
- `ALLOW_IP` - Allows IP addresses _(e.g. 192.168.0.1)_
- `ALLOW_LOCAL` - Allows local network such as _localhost_ or _www.localdomain_
- `ALLOW_URI` - Allows hostnames in URI generic syntax. See [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt)
- `ALLOW_ALL` - Allows all types of hostnames
- `useDeepMxCheck`: Defines if the servers MX records should be verified by a deep check.
When this option is set to `true` then additionally to MX records also the `A`,
`A6` and `AAAA` records are used to verify if the server accepts emails. This
option defaults to `false`.
- `useDomainCheck`: Defines if the domain part should be checked. When this option is
set to `false`, then only the local part of the email address will be checked.
In this case the hostname validator will not be called. This option defaults
to `true`.
- `hostnameValidator`: Sets the hostname validator object instance with which the
domain part of the email address will be validated.
- `useMxCheck`: Defines if the MX records from the server should be detected. If this
option is defined to `true` then the MX records are used to verify if the
server accepts emails. This option defaults to `false`.
## Complex local parts
`Zend\Validator\EmailAddress` will match any valid email address according to
RFC2822. For example, valid emails include `bob@domain.com`,
`bob+jones@domain.us`, `"bob@jones"@domain.com*` and `"bob jones"@domain.com`
Some obsolete email formats will not currently validate (e.g. carriage returns
or a `\\` character in an email address).
## Validating only the local part
If you need `Zend\Validator\EmailAddress` to check only the local part of an
email address, and want to disable validation of the hostname, you can set the
`domain` option to `false`. This forces `Zend\Validator\EmailAddress` not to
validate the hostname part of the email address.
```php
$validator = new Zend\Validator\EmailAddress();
$validator->setOptions(['domain' => FALSE]);
```
## Validating different types of hostnames
The hostname part of an email address is validated against the [Hostname validator](hostname.md).
By default only DNS hostnames of the form `domain.com` are accepted, though if
you wish you can accept IP addresses and Local hostnames too.
To do this you need to instantiate `Zend\Validator\EmailAddress` passing a
parameter to indicate the type of hostnames you want to accept. More details are
included in `Zend\Validator\Hostname`, though an example of how to accept both
DNS and Local hostnames appears below:
```php
use Zend\Validator\EmailAddress;
use Zend\Validator\Hostname;
$validator = new EmailAddress( Hostname::ALLOW_DNS | Hostname::ALLOW_LOCAL);
if ($validator->isValid($email)) {
// email appears to be valid
} else {
// email is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
```
## Checking if the hostname actually accepts email
Just because an email address is in the correct format, it doesn't necessarily
mean that email address actually exists. To help solve this problem, you can use
MX validation to check whether an MX (email) entry exists in the DNS record for
the email's hostname. This tells you that the hostname accepts email, but
doesn't tell you the exact email address itself is valid.
MX checking is not enabled by default. To enable MX checking you can pass a
second parameter to the `Zend\Validator\EmailAddress` constructor.
```php
$validator = new Zend\Validator\EmailAddress([
'allow' => Zend\Validator\Hostname::ALLOW_DNS,
'useMxCheck' => true,
]);
```
Alternatively you can either pass `true` or `false` to `setValidateMx()` to
enable or disable MX validation.
By enabling this setting, network functions will be used to check for the
presence of an MX record on the hostname of the email address you wish to
validate. Please be aware this will likely slow your script down.
Sometimes validation for MX records returns `false`, even if emails are
accepted. The reason behind this behaviour is, that servers can accept emails
even if they do not provide a MX record. In this case they can provide `A`,
`A6`, or `AAAA` records. To allow `Zend\Validator\EmailAddress` to check also
for these other records, you need to set deep MX validation. This can be done at
initiation by setting the `deep` option or by using `setOptions()`.
```php
$validator = new Zend\Validator\EmailAddress([
'allow' => Zend\Validator\Hostname::ALLOW_DNS,
'useMxCheck' => true,
'useDeepMxCheck' => true,
]);
```
Sometimes it can be useful to get the server's MX information which have been
used to do further processing. Simply use `getMXRecord()` after validation. This
method returns the received MX record including weight and sorted by it.
> ### Performance warning**
>
> You should be aware that enabling MX check will slow down you script because
> of the used network functions. Enabling deep check will slow down your script
> even more as it searches the given server for 3 additional types.
> ### Disallowed IP addresses
>
> You should note that MX validation is only accepted for external servers. When
> deep MX validation is enabled, then local IP addresses like `192.168.*` or
> `169.254.*` are not accepted.
## Validating International Domains Names
`Zend\Validator\EmailAddress` will also match international characters that
exist in some domains. This is known as International Domain Name (IDN) support.
This is enabled by default, though you can disable this by changing the setting
via the internal `Zend\Validator\Hostname` object that exists within
`Zend\Validator\EmailAddress`.
```php
$validator->getHostnameValidator()->setValidateIdn(false);
```
More information on the usage of `setValidateIdn()` appears in the
[Hostname documentation](hostname.md).
Please note IDNs are only validated if you allow DNS hostnames to be validated.
## Validating Top Level Domains
By default a hostname will be checked against a list of known TLDs. This is
enabled by default, though you can disable this by changing the setting via the
internal `Zend\Validator\Hostname` object that exists within
`Zend\Validator\EmailAddress`.
```php
$validator->getHostnameValidator()->setValidateTld(false);
```
More information on the usage of `setValidateTld()` appears in the
[Hostname documentation](hostname.md).
Please note TLDs are only validated if you allow DNS hostnames to be validated.
## Setting messages
`Zend\Validator\EmailAddress` makes also use of `Zend\Validator\Hostname` to
check the hostname part of a given email address. You can specify messages for
`Zend\Validator\Hostname` from within `Zend\Validator\EmailAddress`.
```php
$validator = new Zend\Validator\EmailAddress();
$validator->setMessages([
Zend\Validator\Hostname::UNKNOWN_TLD => 'I don\'t know the TLD you gave'
]);
```
================================================
FILE: docs/book/validators/explode.md
================================================
# Explode Validator
`Zend\Validator\Explode` executes a validator for each item exploded from an
array.
## Supported options
The following options are supported for `Zend\Validator\Explode`:
- `valueDelimiter`: Defines the delimiter used to explode values from an array.
It defaults to `,`. If the given value is an array, this option isn't used.
- `validator`: Sets the validator that will be executed on each exploded item.
This may be a validator instance, or a validator service name.
## Basic usage
To validate if every item in an array is in a specified haystack:
```php
$inArrayValidator = new Zend\Validator\InArray([
'haystack' => [1, 2, 3, 4, 5, 6],
]);
$explodeValidator = new Zend\Validator\Explode([
'validator' => $inArrayValidator
]);
$explodeValidator->isValid([1, 4, 6]); // returns true
$explodeValidator->isValid([1, 4, 6, 8]); // returns false
```
## Exploding strings
To validate if every e-mail in a string is contained in a list of names:
```php
$inEmailListValidator = new Zend\Validator\InArray([
'haystack' => ['joseph@test.com', 'mark@test.com', 'lucia@test.com'],
]);
$explodeValidator = new Zend\Validator\Explode([
'validator' => $inEmailListValidator,
'valueDelimiter' => ','
]);
$explodeValidator->isValid('joseph@test.com,mark@test.com'); // returns true
$explodeValidator->isValid('lucia@test.com,maria@test.com'); // returns false
```
================================================
FILE: docs/book/validators/file/count.md
================================================
# Count
`Zend\Validator\File\Count` allows you to validate that the number of files
uploaded matches criteria, including a minimum number of files and/or a maximum
number of files.
## Supported Options
The following options are supported:
- `min`: The minimum number of uploaded files acceptable; `null` is equivalent
to `0`, indicating no minimum.
- `max`: The maximum number of uploaded files acceptable; `null` is equivalent
to no maximum.
## Basic Usage
```php
$validator = new Zend\Validator\File\Count([
'min' => 1,
'max' => 5,
]);
// Setting to the $_FILES superglobal; could also use the zend-http
// request's `getFiles()` or PSR-7 ServerRequest's `getUploadedFiles()`.
$files = $_FILES;
if ($validator->isValid($files)) {
// Received between 1 and 5 files!
}
```
================================================
FILE: docs/book/validators/file/crc32.md
================================================
# Crc32
`Zend\Validator\File\Crc32` allows you to validate if a given file's hashed
contents matches the supplied crc32 hash(es). It is subclassed from the [Hash
validator](hash.md) to provide a validator that only supports the `crc32`
algorithm.
> ### Requires the hash extension
>
> This validator requires the PHP [Hash extension](http://php.net/hash) with the
> `crc32` algorithm.
## Supported Options
The following options are supported:
- `hash`: Single string hash to test the file against, or array of filename/hash
pairs.
## Usage Examples
```php
// Does file have the given hash?
$validator = new \Zend\Validator\File\Crc32('3b3652f');
// Or, check file against multiple hashes
$validator = new \Zend\Validator\File\Crc32(['3b3652f', 'e612b69']);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
## Public Methods
### getCrc32
```php
getCrc32() : array
```
Returns an array of all currently registered hashes to test against.
### addCrc32
```php
addCrc32(string|array $options) : void
```
Add a single hash to test against, or a set of filename/hash pairs to test
against.
### setCrc32
```php
setCrc32(string|array $options): void
```
Overwrite the current list of registered hashes with the one(s) provided.
================================================
FILE: docs/book/validators/file/exclude-extension.md
================================================
# ExcludeExtension
`Zend\Validator\File\ExcludeExtension` checks the extension of files. It will
assert `false` when a given file matches any of the defined extensions.
This validator is inversely related to the [Extension validator](extension.md);
please refer to that validator for full options and usage examples.
================================================
FILE: docs/book/validators/file/exclude-mime-type.md
================================================
ExcludeMimeType
===============
`Zend\Validator\File\ExcludeMimeType` checks the MIME type of files. It will
assert `false` when a given file matches any of the defined MIME types.
This validator is inversely related to the [MimeType validator](mime-type.md);
please refer to that validator's documentation for full options and usage
examples.
================================================
FILE: docs/book/validators/file/exists.md
================================================
# Exists
`Zend\Validator\File\Exists` checks for the existence of files in specified
directories.
This validator is inversely related to the [NotExists validator](not-exists.md).
## Supported Options
The following set of options are supported:
- `directory`: Array of directories, or comma-delimited string of directories.
## Usage Examples
```php
use Zend\Validator\File\Exists;
// Only allow files that exist in ~both~ directories
$validator = new Exists('/tmp,/var/tmp');
// ...or with array notation
$validator = new Exists(['/tmp', '/var/tmp']);
// Perform validation
if ($validator->isValid('/tmp/myfile.txt')) {
// file is valid
}
```
> ### Checks against all directories
>
> This validator checks whether the specified file exists in **all** of the
> given directories; validation will fail if the file does not exist in one
> or more of them.
================================================
FILE: docs/book/validators/file/extension.md
================================================
# Extension
`Zend\Validator\File\Extension` checks the extension of files. It will assert
`true` when a given file matches any of the defined extensions.
This validator is inversely related to the
[ExcludeExtension validator](exclude-extension.md).
## Supported Options
The following set of options are supported:
- `extension`: Array of extensions, or comma-delimited string of extensions,
against which to test.
- `case`: Boolean indicating whether or not extensions should match case
sensitively; defaults to `false` (case-insensitive).
- `allowNonExistentFile`: (**Since 2.13.0**) Boolean indicating whether or not
to allow validating a filename for a non-existent file. Defaults to `false`
(will not validate non-existent files).
## Usage Examples
```php
use Zend\Validator\File\Extension;
// Allow files with 'php' or 'exe' extensions
$validator = new Extension('php,exe');
// ...or with array notation
$validator = new Extension(['php', 'exe']);
// Test with case-sensitivity on
$validator = new Extension(['php', 'exe'], true);
// Using an options array:
$validator = new Extension([
'extension' => ['php', 'exe'],
'case' => true,
]);
// Perform validation
if ($validator->isValid('./myfile.php')) {
// file is valid
}
```
## Public Methods
### addExtension
```php
addExtension(string|array $options) : void
```
Add one or more extensions as a comma-separated list, or as an array.
================================================
FILE: docs/book/validators/file/files-size.md
================================================
# FilesSize
`Zend\Validator\File\FilesSize` allows validating the total size of all file
uploads in aggregate, allowing specifying a minimum upload size and/or a maximum
upload size.
Only use this validator if you will be expecting multiple file uploads in a
single payload, and want to ensure the aggregate size falls within a specific
range.
## Supported Options
`Zend\Validator\File\FilesSize` supports the following options:
- `min`: The minimum aggregate size of all file uploads. May be specified as an
integer or using SI units. `null` indicates no minimum size is required.
- `max`: The maximum aggregate size of all file uploads. May be specified as an
integer or using SI units. `null` indicates no maximum size is required.
- `useByteString`: A flag indicating whether sizes should be reported as
integers or using SI units when reporting validation errors.
See the [Size validator](size.md#supported-options) for details on supported SI
units.
## Basic Usage
```php
use Zend\Validator\File\FilesSize;
$validator = new FilesSize([
'min' => '1kB`, // minimum of 1kB
'max' => `10MB', // maximum of 10MB
]);
if ($validator->isValid($_FILES)) {
// > 1kB, < 10MB in aggregate
}
```
================================================
FILE: docs/book/validators/file/hash.md
================================================
# Hash
`Zend\Validator\File\Hash` allows you to validate if a given file's hashed
contents matches the supplied hash(es) and algorithm(s).
> ### Requires the hash extension
>
> This validator requires the PHP [Hash extension](http://php.net/hash). A list
> of supported hash algorithms can be found with the
> [hash\_algos() function](http://php.net/hash_algos).
## Supported Options
The following set of options are supported:
- `hash`: String hash or array of hashes against which to test.
- `algorithm`: String hashing algorithm to use; defaults to `crc32`
## Basic Usage
```php
use Zend\Validator\File\Hash;
// Does file have the given hash?
$validator = new Hash('3b3652f', 'crc32');
// Or, check file against multiple hashes
$validator = new Hash(['3b3652f', 'e612b69'], 'crc32');
// Or use options notation:
$validator = new Hash([
'hash' => ['3b3652f', 'e612b69'],
'algorithm' => 'crc32',
]);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
## Public Methods
### getHash
```php
getHash() : array
```
Returns an array containing the set of hashes against which to validate.
### addHash
```php
addHash(string|array $options) : void
```
Add one or more hashes against which to validate.
### setHash
```php
setHash(string|array $options) : void
```
Overwrite the current set of hashes with those provided to the method.
================================================
FILE: docs/book/validators/file/image-size.md
================================================
# ImageSize
`Zend\Validator\File\ImageSize` checks the size of image files. Minimum and/or
maximum dimensions can be set to validate against.
## Supported Options
The following set of options are supported:
- `minWidth`: Set the minimum image width as an integer; `null` (the default)
indicates no minimum.
- `minHeight`: Set the minimum image height as an integer; `null` (the default)
indicates no minimum.
- `maxWidth`: Set the maximum image width as an integer; `null` (the default)
indicates no maximum.
- `maxHeight`: Set the maximum image height as an integer; `null` (the default)
indicates no maximum.
## Basic Usage
```php
use Zend\Validator\File\ImageSize;
// Is image size between 320x200 (min) and 640x480 (max)?
$validator = new ImageSize(320, 200, 640, 480);
// ...or with array notation
$validator = new ImageSize([
'minWidth' => 320,
'minHeight' => 200,
'maxWidth' => 640,
'maxHeight' => 480,
]);
// Is image size equal to or larger than 320x200?
$validator = new ImageSize([
'minWidth' => 320,
'minHeight' => 200,
]);
// Is image size equal to or smaller than 640x480?
$validator = new ImageSize([
'maxWidth' => 640,
'maxHeight' => 480,
]);
// Perform validation with file path
if ($validator->isValid('./myfile.jpg')) {
// file is valid
}
```
## Public Methods
### getImageMin
```php
getImageMin() : array
```
Returns the minimum valid dimensions as an array with the keys `width` and
`height`.
### getImageMax
```php
getImageMax() : array
```
Returns the maximum valid dimensions as an array with the keys `width` and
`height`.
================================================
FILE: docs/book/validators/file/intro.md
================================================
# File Validation Classes
Zend Framework comes with a set of classes for validating both files and
uploaded files, such as file size validation and CRC checking.
- [Count](count.md)
- [crc32](crc32.md)
- [ExcludeExtension](exclude-extension.md)
- [ExcludeMimeType](exclude-mime-type.md)
- [Exists](exists.md)
- [Extension](extension.md)
- [FilesSize](files-size.md)
- [Hash](hash.md)
- [ImageSize](image-size.md)
- [IsCompressed](is-compressed.md)
- [IsImage](is-image.md)
- [Md5](md5.md)
- [MimeType](mime-type.md)
- [NotExists](not-exists.md)
- [Sha1](sha1.md)
- [Size](size.md)
- [Upload](upload.md)
- [UploadFile](upload-file.md)
- [WordCount](word-count.md)
> ### Validation argument
>
> All of the File validators' `isValid()` methods support both a file path
> `string` *or* a `$_FILES` array as the supplied argument. When a `$_FILES`
> array is passed in, the `tmp_name` is used for the file path.
================================================
FILE: docs/book/validators/file/is-compressed.md
================================================
# IsCompressed
`Zend\Validator\File\IsCompressed` checks if a file is a compressed archive,
such as zip or gzip. This validator is based on the
[MimeType validator](mime-type.md), and supports the same methods and options.
The default list of [compressed file MIME types](https://github.com/zendframework/zend-validator/blob/master/src/File/IsCompressed.php#L45)
can be found in the source code.
Please refer to the [MimeType validator](mime-type.md) for options and public
methods.
## Basic Usage
```php
$validator = new \Zend\Validator\File\IsCompressed();
if ($validator->isValid('./myfile.zip')) {
// file is valid
}
```
================================================
FILE: docs/book/validators/file/is-image.md
================================================
# IsImage
`Zend\Validator\File\IsImage` checks if a file is an image, such as jpg or png.
This validator is based on the [MimeType validator](mime-type.md) and supports
the same methods and options.
The default list of [image file MIME types](https://github.com/zendframework/zend-validator/blob/master/src/File/IsImage.php#L44)
can be found in the source code.
Please refer to the [MimeType validator](mime-type.md) for options and public
methods.
## Basic Usage
```php
$validator = new Zend\Validator\File\IsImage();
if ($validator->isValid('./myfile.jpg')) {
// file is valid
}
```
================================================
FILE: docs/book/validators/file/md5.md
================================================
# Md5
`Zend\Validator\File\Md5` allows you to validate if a given file's hashed
contents matches the supplied md5 hash(es). It is subclassed from the
[Hash validator](hash.md) to provide a validator that supports only the MD5
algorithm.
> ### Requires the hash extension
>
> This validator requires the PHP [Hash extension](http://php.net/hash) PHP with
> the `md5` algorithm.
## Supported Options
The following set of options are supported:
- `hash`: String hash or array of hashes against which to validate.
## Basic Usage
```php
use Zend\Validator\File\Md5;
// Does file have the given hash?
$validator = new Md5('3b3652f336522365223');
// Or, check file against multiple hashes
$validator = new Md5([
'3b3652f336522365223', 'eb3365f3365ddc65365'
]);
// Or use options notation:
$validator = new Md5(['hash' => [
'3b3652f336522365223', 'eb3365f3365ddc65365'
]]);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
## Public Methods
### getMd5
```php
getMd5() : array
```
Returns an array of MD5 hashes against which to validate.
### addMd5
```php
addMd5(string|array $options) : void
```
Add one or more hashes to validate against.
### setMd5
```php
setMd5(string|array $options) : void
```
Overwrite any previously set hashes with those specified.
================================================
FILE: docs/book/validators/file/mime-type.md
================================================
# MimeType
`Zend\Validator\File\MimeType` checks the MIME type of files. It will assert
`true` when a given file matches any defined MIME type.
This validator is inversely related to the
[ExcludeMimeType validator](exclude-mime-type.md)
> ### Compatibility
>
> This component will use the `FileInfo` extension if it is available. If it's
> not, it will degrade to the `mime_content_type()` function. And if the
> function call fails, it will use the MIME type which is given by HTTP. You
> should be aware of possible security problems when you do not have `FileInfo`
> or `mime_content_type()` available; the MIME type given by HTTP is not secure
> and can be easily manipulated.
## Supported Options
The following set of options are supported:
- `mimeType`: Comma-delimited string of MIME types, or array of MIME types,
against which to test. Types can be specific (e.g., `image/jpeg`), or refer
only to the group (e.g., `image`).
- `magicFile`: Location of the magicfile to use for MIME type comparisons;
defaults to the value of the `MAGIC` constant.
- `enableHeaderCheck`: Boolean flag indicating whether or not to use HTTP
headers when determining the MIME type if neither the `FileInfo` nor
`mime_magic` extensions are available; defaults to `false`.
## Basic Usage
```php
use Zend\Validator\File\MimeType;
// Only allow 'gif' or 'jpg' files
$validator = new MimeType('image/gif,image/jpeg');
// ... or with array notation:
$validator = new MimeType(['image/gif', 'image/jpeg']);
// ... or restrict to entire group of types:
$validator = new MimeType(['image', 'audio']);
// Specify a different magicFile:
$validator = new MimeType([
'mimeType' => ['image/gif', 'image/jpeg'],
'magicFile' => '/path/to/magicfile.mgx',
]);
// Enable HTTP header scanning (do not do this!):
$validator = new MimeType([
'mimeType' => ['image/gif', 'image/jpeg'],
'enableHeaderCheck' => true,
]);
// Perform validation
if ($validator->isValid('./myfile.jpg')) {
// file is valid
}
```
> ### Validating MIME groups is potentially dangerous
>
> Allowing "groups" of MIME types will accept **all** members of this group, even
> if your application does not support them. For instance, When you allow
> `image` you also allow `image/xpixmap` and `image/vasa`, both of which could
> be problematic.
================================================
FILE: docs/book/validators/file/not-exists.md
================================================
# NotExists
`Zend\Validator\File\NotExists` checks for the existence of files in specified
directories.
This validator is inversely related to the [Exists validator](exists.md).
## Supported Options
The following set of options are supported:
- `directory`: Array of directories or comma-delimited string of directories
against which to validate.
## Basic Usage
```php
use Zend\Validator\File\NotExists;
// Only allow files that do not exist in ~either~ directories
$validator = new NotExists('/tmp,/var/tmp');
// ... or with array notation:
$validator = new NotExists(['/tmp', '/var/tmp']);
// ... or using options notation:
$validator = new NotExists(['directory' => [
'/tmp',
'/var/tmp',
]]);
// Perform validation
if ($validator->isValid('/home/myfile.txt')) {
// file is valid
}
```
> ### Checks against all directories
>
> This validator checks whether the specified file does not exist in **any** of
> the given directories; validation will fail if the file exists in one (or
> more) of the given directories.
================================================
FILE: docs/book/validators/file/sha1.md
================================================
# Sha1
`Zend\Validator\File\Sha1` allows you to validate if a given file's hashed
contents matches the supplied sha1 hash(es). It is subclassed from the
[Hash validator](hash.md) to provide a validator that only supports the `sha1`
algorithm.
> ### Requires the hash extension
>
> This validator requires the PHP [Hash extension](http://php.net/hash) with the
> `sha1` algorithm.
## Supported Options
The following set of options are supported:
- `hash`: String hash or array of hashes against which to validate.
## Basic Usage
```php
use Zend\Validator\File\Sha1;
// Does file have the given hash?
$validator = new Sha1('3b3652f336522365223');
// Or check file against multiple hashes:
$validator = new Sha1([
'3b3652f336522365223',
'eb3365f3365ddc65365',
]);
// Or using options notation:
$validator = new Sha1(['hash' => [
'3b3652f336522365223',
'eb3365f3365ddc65365',
]]);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
## Public Methods
### getSha1
```php
getSha1() : array
```
Returns an array of sha1 hashes against which to validate.
### addSha1
```php
addSha1(string|array $options) : void
```
Add one or more hashes to validate against.
### setSha1
```php
setSha1(string|array $options) : void
```
Overwrite any previously set hashes with those specified.
================================================
FILE: docs/book/validators/file/size.md
================================================
# Size
`Zend\Validator\File\Size` checks for the size of a file.
## Supported Options
The following set of options are supported:
- `min`: Minimum file size in integer bytes, or in string SI notation; `null`
indicates no minimum required.
- `max`: maximum file size in integer bytes, or in string SI notation; `null`
indicates no maximum required.
- `useByteString`: Boolean flag indicating whether to dispaly error messages
using SI notation (default, `true`), or in bytes (`false`).
SI units supported are: kB, MB, GB, TB, PB, and EB. All sizes are converted
using 1024 as the base value (ie. 1kB == 1024 bytes, 1MB == 1024kB).
## Basic Usage
```php
use Zend\Validator\File\Size;
// Limit the file size to 40000 bytes
$validator = new Size(40000);
// Limit the file size to between 10kB and 4MB
$validator = new Size([
'min' => '10kB',
'max' => '4MB',
]);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
================================================
FILE: docs/book/validators/file/upload-file.md
================================================
# UploadFile
`Zend\Validator\File\UploadFile` checks whether a single file has been uploaded
via a form `POST` and will return descriptive messages for any upload errors.
## Basic Usage
```php
use Zend\Http\PhpEnvironment\Request;
use Zend\Validator\File\UploadFile;
$request = new Request();
$files = $request->getFiles();
// i.e. $files['my-upload']['error'] == 0
$validator = new UploadFile();
if ($validator->isValid($files['my-upload'])) {
// file is valid
}
```
## PSR-7 Support
- Since 2.11.0
Starting in 2.11.0, you can also pass [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#uploadedfileinterface)
instances as values to the validator. When valid, `getValue()` will return the
instance validated verbatim:
```php
$validator = new UploadFile();
// @var Psr\Http\Message\UploadedFileInterface $uploadedFile
if ($validator->isValid($uploadedFile)) {
// file is valid
$validInstance = $validator->getValue(); // === $uploadedFile
}
```
## Usage with zend-inputfilter
When using zend-inputfilter's [FileInput](https://docs.zendframework.com/zend-inputfilter/file-input/),
this validator will be automatically prepended to the validator chain.
================================================
FILE: docs/book/validators/file/upload.md
================================================
# Upload
`Zend\Validator\File\Upload` validates that a file upload operation was
successful.
## Supported Options
`Zend\Validator\File\Upload` supports the following options:
- `files`: array of file uploads. This is generally the `$_FILES` array, but
should be normalized per the details in [PSR-7](http://www.php-fig.org/psr/psr-7/#16-uploaded-files)
(which is also how [the zend-http Request](https://docs.zendframework.com/zend-http)
normalizes the array).
## Basic Usage
```php
use Zend\Validator\File\Upload;
// Using zend-http's request:
$validator = new Upload($request->getFiles());
// Or using options notation:
$validator = new Upload(['files' => $request->getFiles()]);
// Validate:
if ($validator->isValid('foo')) {
// "foo" file upload was successful
}
```
## PSR-7 Support
- Since 2.11.0
Starting in 2.11.0, you can also pass an array of [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#uploadedfileinterface)
instances to the constructor, the `setFiles()` method, or the `isValid()`
method (in the latter case, you are validating that _all_ uploaded files were
valid).
```php
use Zend\Validator\File\Upload;
// @var Psr\Http\Message\ServerRequestInterface $request
$validator = new Upload($request->getUploadedFiles());
// Or using options notation:
$validator = new Upload([
'files' => $request->getUploadedFiles(),
]);
// Validate:
if ($validator->isValid('foo')) {
// "foo" file upload was successful
}
```
================================================
FILE: docs/book/validators/file/word-count.md
================================================
# WordCount
`Zend\Validator\File\WordCount` validates that the number of words within a file
match the specified criteria.
## Supported Options
The following set of options are supported:
- `min`: the minimum number of words required; `null` indicates no minimum.
- `max`: the maximum number of words required; `null` indicates no maximum.
## Basic Usage
```php
use Zend\Validator\File\WordCount;
// Limit the amount of words to a maximum of 2000:
$validator = new WordCount(2000);
// Limit the amount of words to between 100 and 5000:
$validator = new WordCount(100, 5000);
// ... or use options notation:
$validator = new WordCount([
'min' => 1000,
'max' => 5000,
]);
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
```
================================================
FILE: docs/book/validators/greater-than.md
================================================
# GreaterThan Validator
`Zend\Validator\GreaterThan` allows you to validate if a given value is greater
than a minimum border value.
> ### Only supports numbers
>
> `Zend\Validator\GreaterThan` supports only the validation of numbers. Strings
> or dates can not be validated with this validator.
## Supported options
The following options are supported for `Zend\Validator\GreaterThan`:
- `inclusive`: Defines if the validation is inclusive of the minimum value,
or exclusive. It defaults to `false`.
- `min`: Sets the minimum allowed value.
## Basic usage
To validate if a given value is greater than a defined minimum:
```php
$valid = new Zend\Validator\GreaterThan(['min' => 10]);
$value = 8;
$return = $valid->isValid($value);
// returns false
```
The above example returns `true` for all values which are greater than 10.
## Inclusive validation
Sometimes it is useful to validate a value by including the minimum value.
```php
$valid = new Zend\Validator\GreaterThan([
'min' => 10,
'inclusive' => true,
]);
$value = 10;
$result = $valid->isValid($value);
// returns true
```
The example is identical to our first example, with the exception that we
included the minimum value. Now the value '10' is allowed and will return
`true`.
================================================
FILE: docs/book/validators/hex.md
================================================
# Hex Validator
`Zend\Validator\Hex` allows you to validate if a given value contains only
hexadecimal characters. These are all characters from **0 to 9** and **A to F**,
case insensitive. There is no length limitation for the input you want to
validate.
```php
$validator = new Zend\Validator\Hex();
if ($validator->isValid('123ABC')) {
// value contains only hex chars
} else {
// false
}
```
> ### Invalid characters
>
> All other characters will return false, including whitespace and decimal
> points. Additionally, unicode zeros and numbers from other scripts than latin
> will not be treated as valid.
## Supported options
There are no additional options for `Zend\Validator\Hex`.
================================================
FILE: docs/book/validators/hostname.md
================================================
# Hostname Validator
`Zend\Validator\Hostname` allows you to validate a hostname against a set of
known specifications. It is possible to check for three different types of
hostnames: a DNS Hostname (i.e. `domain.com`), IP address (i.e. 1.2.3.4), and
Local hostnames (i.e. localhost). By default, only DNS hostnames are matched.
## Supported options
The following options are supported for `Zend\Validator\Hostname`:
- `allow`: Defines the sort of hostname which is allowed to be used.
[See below](#validating-different-types-of-hostnames) for details.
- `idn`: Defines if IDN domains are allowed or not. This option defaults to
`true`.
- `ip`: Allows defining a custom IP validator. This option defaults to a new
instance of `Zend\Validator\Ip`.
- `tld`: Defines if TLDs are validated. This option defaults to `true`.
## Basic usage
```php
$validator = new Zend\Validator\Hostname();
if ($validator->isValid($hostname)) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
```
This will match the hostname `$hostname` and on failure populate `getMessages()`
with useful error messages.
## Validating different types of hostnames
You may find you also want to match IP addresses, Local hostnames, or a
combination of all allowed types. This can be done by passing a parameter to
`Zend\Validator\Hostname` when you instantiate it. The parameter should be an
integer which determines what types of hostnames are allowed. You are encouraged
to use the `Zend\Validator\Hostname` constants to do this.
The `Zend\Validator\Hostname` constants are:
- `ALLOW_DNS`, to allow only DNS hostnames
- `ALLOW_IP` to allow IP addresses
- `ALLOW_LOCAL` to allow local network names
- `ALLOW_URI` to allow [RFC3986](http://tools.ietf.org/html/rfc3986)-compliant addresses
- `ALLOW_ALL` to allow all four above types
> ### Additional Information on `ALLOW_URI`
>
> `ALLOW_URI` allows checking hostnames according to
> [RFC3986](http://tools.ietf.org/html/rfc3986). These are registered names
> which are used by WINS, NetInfo and also local hostnames like those defined
> within your `hosts` file.
To check for IP addresses only, you can use the example below:
```php
use Zend\Validator\Hostname;
$validator = new Hostname(Hostname::ALLOW_IP);
if ($validator->isValid($hostname)) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
```
As well as using `ALLOW_ALL` to accept all common hostnames types, you can
combine these types to allow for combinations. For example, to accept DNS and
Local hostnames:
```php
use Zend\Validator\Hostname;
$validator = new Hostname(Hostname::ALLOW_DNS | Hostname::ALLOW_IP);
```
## Validating International Domains Names
Some Country Code Top Level Domains (ccTLDs), such as 'de' (Germany), support
international characters in domain names. These are known as International
Domain Names (IDN). These domains can be matched by `Zend\Validator\Hostname`
via extended characters that are used in the validation process.
At the time of writing, more than 50 ccTLDs support IDN domains.
The `Hostname` validator matches IDN domains by default. If you wish to disable
IDN validation, either pass a parameter to the `Zend\Validator\Hostname`
constructor or call the `setValidateIdn()` method.
You can disable IDN validation by passing a second parameter to the
`Zend\Validator\Hostname` constructor in the following way.
```php
$validator = new Zend\Validator\Hostname([
'allow' => Zend\Validator\Hostname::ALLOW_DNS,
'useIdnCheck' => false,
]);
```
Alternatively you can either pass `true` or `false` to `setValidateIdn()` to
enable or disable IDN validation. If you are trying to match an IDN hostname
which isn't currently supported, it is likely it will fail validation if it has
any international characters in it. Where a ccTLD file doesn't exist in
`Zend/Validator/Hostname` specifying the additional characters, a normal hostname
validation is performed.
Please note that IDNs are only validated if you allow DNS hostnames to be
validated.
## Validating Top Level Domains
By default, a hostname will be verified against a list of known TLDs. If this
functionality is not required, it can be disabled in much the same way as
disabling IDN support. You can disable TLD validation by passing a third
parameter to the `Zend\Validator\Hostname` constructor. In the example below we
are supporting IDN validation via the second parameter.
```php
use Zend\Validator\Hostname;
$validator = new Hostname([
'allow' => Hostname::ALLOW_DNS,
'useIdnCheck' => true,
'useTldCheck' => false,
]);
```
Alternatively you can either pass `true` or `false` to `setValidateTld()` to
enable or disable TLD validation.
Please note, TLDs are only validated if you allow DNS hostnames to be validated.
================================================
FILE: docs/book/validators/iban.md
================================================
# Iban Validator
`Zend\Validator\Iban` validates if a given value could be a IBAN number. IBAN is
the abbreviation for "International Bank Account Number".
## Supported options
The following options are supported for `Zend\Validator\Iban`:
- `country_code`: Sets the country code which is used to get the IBAN format
for validation.
## IBAN validation
IBAN numbers are always related to a country. This means that different
countries use different formats for their IBAN numbers. This is the reason why
IBAN numbers always need a country code. By knowing this we already know how
to use `Zend\Validator\Iban`.
### Ungreedy IBAN validation
Sometime it is useful just to validate if the given value is a IBAN number or
not. This means that you don't want to validate it against a defined country.
This can be done by using `false` as locale.
```php
$validator = new Zend\Validator\Iban(['country_code' => false]);
// Note: you can also provide FALSE as the sole parameter
if ($validator->isValid('AT611904300234573201')) {
// IBAN appears to be valid
} else {
// IBAN is not valid
}
```
In this situation, any IBAN number from any country will considered valid. Note
that this should not be done when you accept only accounts from a single
country!
### Region aware IBAN validation
To validate against a defined country, you just provide a country code. You can
do this during instaniation via the option `country_code`, or afterwards by
using `setCountryCode()`.
```php
$validator = new Zend\Validator\Iban(['country_code' => 'AT']);
if ($validator->isValid('AT611904300234573201')) {
// IBAN appears to be valid
} else {
// IBAN is not valid
}
```
================================================
FILE: docs/book/validators/identical.md
================================================
# Identical Validator
`Zend\Validator\Identical` allows you to validate if a given value is identical
with a set token.
## Supported options
The following options are supported for `Zend\Validator\Identical`:
- `strict`: Defines if the validation should be strict (i.e., if types should
also be considered). The default value is `true`.
- `token`: Sets the token against which the input will be validated.
- `literal`: If set to `true`, the validation will skip the lookup for elements
in the form context, and validate the token just the way it was provided. The
default value is `false`.
## Basic usage
To validate if two values are identical, you need to set the original value as
the token, as demonstrated in the following example:
token.
```php
$valid = new Zend\Validator\Identical('origin');
if ($valid->isValid($value)) {
return true;
}
```
The validation will only then return `true` when both values are 100% identical.
In our example, when `$value` is `'origin'`.
You can set the token after instantiation by using the method `setToken()`.
## Identical objects
`Zend\Validator\Identical` can validate not only strings, but any other variable
type, such as booleans, integers, floats, arrays, or even objects. As already
noted, the token and value must be identical.
```php
$valid = new Zend\Validator\Identical(123);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
> ### Type comparison
>
> You should be aware of the variable type used for validation. This means that
> the string `'3'` is not identical to integer `3`. When you want non-strict
> validation, you must set the `strict` option to `false`.
## Form elements
`Zend\Validator\Identical` supports the comparison of form elements. This can be
done by using the element's name as the `token`:
```php
$form->add([
'name' => 'elementOne',
'type' => 'Password',
]);
$form->add([
'name' => 'elementTwo',
'type' => 'Password',
'validators' => [
[
'name' => 'Identical',
'options' => [
'token' => 'elementOne',
],
],
],
]);
```
By using the element's name from the first element as the `token` for the second
element, the validator validates if the second element is equal with the first
element. In the case your user does not enter two identical values, you will get
a validation error.
### Validating a Value From a Fieldset
Sometimes you will need to validate an input that lives inside a fieldset, and
this can be accomplished as follows:
```php
use Zend\Form\Element;
use Zend\Form\Fieldset;
use Zend\Form\Form;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
$userFieldset = new Fieldset('user'); // (1)
$userFieldset->add([
'name' => 'email', // (2)
'type' => 'Email',
]);
// Let's add one fieldset inside the 'user' fieldset,
// so we can see how to manage the token in a different deepness
$deeperFieldset = new Fieldset('deeperFieldset'); // (3)
$deeperFieldset->add([
'name' => 'deeperFieldsetInput', // (4)
'type' => 'Text',
'options' => [
'label' => 'What validator are we testing?',
],
]);
$userFieldset->add($deeperFieldset);
$signUpForm = new Form('signUp');
$signUpForm->add($userFieldset);
// Add an input that will validate the 'email' input from 'user' fieldset
$signUpForm->add([
'name' => 'confirmEmail', // (5)
'type' => 'Email',
]);
// Add an input that will validate the 'deeperFieldsetInput' from
// 'deeperFieldset' that lives inside the 'user' fieldset
$signUpForm->add([
'name' => 'confirmTestingValidator', // (6)
'type' => 'Text',
]);
// This will ensure the user enter the same email in 'email' (2) and
// 'confirmEmail' (5)
$inputFilter = new InputFilter();
$inputFilter->add([
'name' => 'confirmEmail', // references (5)
'validators' => [
[
'name' => 'Identical',
'options' => [
// 'user' key references 'user' fieldset (1), and 'email'
// references 'email' element inside 'user' fieldset (2)
'token' => ['user' => 'email'],
],
],
],
]);
// This will ensure the user enter the same string in 'deeperFieldsetInput' (4)
// and 'confirmTestingValidator' (6)
$inputFilter->add([
'name' => 'confirmTestingValidator', // references (6)
'validators' => [
[
'name' => 'Identical',
'options' => [
'token' => [
'user' => [ // references 'user' fieldset (1)
// 'deeperFieldset' key references 'deeperFieldset'
// fieldset (3); 'deeperFieldsetInput' references
// 'deeperFieldsetInput' element (4)
'deeperFieldset' => 'deeperFieldsetInput',
],
],
],
],
],
]);
$signUpForm->setInputFilter($inputFilter);
```
> #### Use one token per leaf
>
> Aways make sure that your token array have just one key per level all the way
> till the leaf, otherwise you can end up with unexpected results.
## Strict validation
As mentioned before, `Zend\Validator\Identical` validates tokens using strict
typing. You can change this behaviour by using the `strict` option. The default
value for this property is `true`.
```php
$valid = new Zend\Validator\Identical(['token' => 123, 'strict' => false]);
$input = '123';
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
The difference to the previous example is that the validation returns in this
case `true`, even if you compare a integer with string value as long as the
content is identical but not the type.
For convenience you can also use `setStrict()` and `getStrict()`.
## Configuration
As all other validators, `Zend\Validator\Identical` also supports the usage of
configuration settings during instantiation. This means that you can configure
this validator with a `Traversable` object.
There is a case which you should be aware of. If you are using an array as
token, and it contains a `token` key, you should wrap it within another
`token` key. See the examples below to understand this situation.
```php
// This will not validate ['token' => 123], it will actually validate the
// integer 123
$valid = new Zend\Validator\Identical(['token' => 123]);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
The reason for this special case is that you can configure the token which has
to be used by giving the `token` key.
So, when you are using an array as the token, and it contains one element with a
`token` key, then you have to wrap it as shown in the example below:
```php
// Unlike the previous example, this will validate ['token' => 123]
$valid = new Zend\Validator\Identical(['token' => ['token' => 123]]);
if ($valid->isValid($input)) {
// input appears to be valid
} else {
// input is invalid
}
```
If the array you are willing to validate does not have a `token` key, you do not
need to wrap it.
================================================
FILE: docs/book/validators/in-array.md
================================================
# InArray Validator
`Zend\Validator\InArray` allows you to validate if a given value is contained
within an array. It is also able to validate multidimensional arrays.
## Supported options
The following options are supported for `Zend\Validator\InArray`:
- `haystack`: Sets the haystack for the validation.
- `recursive`: Defines if the validation should be done recursively. This option
defaults to `false`.
- `strict`: Three modes of comparison are offered owing to an often overlooked,
and potentially dangerous security issue when validating string input from
user input.
- `InArray::COMPARE_STRICT`: This is a normal `in_array()` strict comparison
that checks value and type.
- `InArray::COMPARE_NOT_STRICT`: This is a normal `in_array()` non-strict
comparison that checks value only, but not type.
- `InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILTY`: This
operates in essentially the same way as `InArray::COMPARE_NOT_STRICT`,
but ensures that strings are not cast to integer during comparison,
preventing `0 == 'foo43'` types of false positives.
> ### Use non-strict carefully
>
> Non-strict mode (`InArray::COMPARE_NOT_STRICT`) may give false positives when
> strings are compared against ints or floats owing to `in_array()`'s behaviour
> of converting strings to int in such cases. Therefore, `'foo'` would become
> `0`, `'43foo'` would become `43`, while `foo43'` would also become `0`.
## Array validation
Basic usage is to provide an array during instantiation:
```php
$validator = new Zend\Validator\InArray([
'haystack' => ['value1', 'value2',...'valueN'],
]);
if ($validator->isValid('value')) {
// value found
} else {
// no value found
}
```
This will behave exactly like PHP's `in_array()` method when passed only a
needle and haystack.
> ### Non-strict by default
>
> By default, this validation is not strict, nor can it validate
> multidimensional arrays.
Alternately, you can define the array to validate against after object
construction by using the `setHaystack()` method. `getHaystack()` returns the
actual set haystack array.
```php
$validator = new Zend\Validator\InArray();
$validator->setHaystack(['value1', 'value2',...'valueN']);
if ($validator->isValid('value')) {
// value found
} else {
// no value found
}
```
## Array validation modes
As previously mentioned, there are possible security issues when using the
default non-strict comparison mode, so rather than restricting the developer,
we've chosen to offer both strict and non-strict comparisons, and add a safer
middle-ground.
It's possible to set the strict mode at initialisation and afterwards with the
`setStrict` method. `InArray::COMPARE_STRICT` equates to `true` and
`InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY` equates to
`false`.
```php
// defaults to InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY
$validator = new Zend\Validator\InArray([
'haystack' => ['value1', 'value2', /* ... */ 'valueN'],
]);
// set strict mode
$validator = new Zend\Validator\InArray([
'haystack' => ['value1', 'value2', /* ... */ 'valueN'],
'strict' => InArray::COMPARE_STRICT, // equates to ``true``
]);
// set non-strict mode
$validator = new Zend\Validator\InArray([
'haystack' => ['value1', 'value2', /* ... */ 'valueN'],
'strict' => InArray:COMPARE_NOT_STRICT, // equates to ``false``
]);
// or
$validator->setStrict(InArray::COMPARE_STRICT);
$validator->setStrict(InArray::COMPARE_NOT_STRICT);
$validator->setStrict(InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY);
```
> ### Non-strict safe-mode by default
>
> Note that the `strict` setting is per default `false`.
## Recursive array validation
In addition to PHP's `in_array()` method, this validator can also be used to
validate multidimensional arrays.
To validate multidimensional arrays you have to set the `recursive` option.
```php
$validator = new Zend\Validator\InArray([
'haystack' => [
'firstDimension' => ['value1', 'value2', / ... */ 'valueN'],
'secondDimension' => ['foo1', 'foo2', /* ... */ 'fooN'],
],
'recursive' => true,
]);
if ($validator->isValid('value')) {
// value found
} else {
// no value found
}
```
Your array will then be validated recursively to see if the given value is
contained. Additionally you could use `setRecursive()` to set this option
afterwards and `getRecursive()` to retrieve it.
```php
$validator = new Zend\Validator\InArray([
'firstDimension' => ['value1', 'value2', /* ... */ 'valueN'],
'secondDimension' => ['foo1', 'foo2', /* ... */ 'fooN'],
]);
$validator->setRecursive(true);
if ($validator->isValid('value')) {
// value found
} else {
// no value found
}
```
> ### Default setting for recursion
>
> By default, the recursive validation is turned off.
> ### Option keys within the haystack
>
> When you are using the keys `haystack`, `strict`, or `recursive` within
> your haystack, then you must wrap the `haystack` key.
================================================
FILE: docs/book/validators/ip.md
================================================
# Ip Validator
`Zend\Validator\Ip` allows you to validate if a given value is an IP address. It
supports the IPv4, IPv6, and IPvFuture definitions.
## Supported options
The following options are supported for `Zend\Validator\Ip`:
- `allowipv4`: Defines if the validator allows IPv4 addresses. This option
defaults to `true`.
- `allowipv6`: Defines if the validator allows IPv6 addresses. This option
defaults to `true`.
- `allowipvfuture`: Defines if the validator allows IPvFuture addresses. This
option defaults to `false`.
- `allowliteral`: Defines if the validator allows IPv6 or IPvFuture with URI
literal style (the IP surrounded by brackets). This option defaults to `true`.
## Basic usage
```php
$validator = new Zend\Validator\Ip();
if ($validator->isValid($ip)) {
// ip appears to be valid
} else {
// ip is invalid; print the reasons
}
```
> ### Invalid IP addresses
>
> Keep in mind that `Zend\Validator\Ip` only validates IP addresses. Addresses
> like '`mydomain.com`' or '`192.168.50.1/index.html`' are not valid IP
> addresses. They are either hostnames or valid URLs but not IP addresses.
> ### IPv6/IPvFuture validation
>
> `Zend\Validator\Ip` validates IPv6/IPvFuture addresses using a regex. The
> reason is that the filters and methods from PHP itself don't follow the RFC.
> Many other available classes also don't follow it.
## Validate IPv4 or IPV6 alone
Sometimes it's useful to validate only one of the supported formats; e.g., when
your network only supports IPv4. In this case it would be useless to allow IPv6
within this validator.
To limit `Zend\Validator\Ip` to one protocol, you can set the options `allowipv4`
or `allowipv6` to `false`. You can do this either by giving the option to the
constructor or by using `setOptions()` afterwards.
```php
$validator = new Zend\Validator\Ip(['allowipv6' => false]);
if ($validator->isValid($ip)) {
// ip appears to be valid ipv4 address
} else {
// ip is not an ipv4 address
}
```
> ### Default behaviour
>
> The default behaviour which `Zend\Validator\Ip` follows is to allow both
> standards.
================================================
FILE: docs/book/validators/is-countable.md
================================================
# 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
```
================================================
FILE: docs/book/validators/isbn.md
================================================
# Isbn Validator
`Zend\Validator\Isbn` allows you to validate an ISBN-10 or ISBN-13 value.
## Supported options
The following options are supported for `Zend\Validator\Isbn`:
- `separator`: Defines the allowed separator for the ISBN number. It defaults to
an empty string.
- `type`: Defines the allowed ISBN types. It defaults to
`Zend\Validator\Isbn::AUTO`. For details, take a look at the section on
[explicit types](#setting-an-explicit-isbn-validation-type).
## Basic usage
A basic example of usage is below:
```php
$validator = new Zend\Validator\Isbn();
if ($validator->isValid($isbn)) {
// isbn is valid
} else {
// isbn is not valid
}
```
This will validate any ISBN-10 and ISBN-13 without separator.
## Setting an explicit ISBN validation type
An example of an ISBN type restriction follows:
```php
use Zend\Validator\Isbn;
$validator = new Isbn();
$validator->setType(Isbn::ISBN13);
// OR
$validator = new Isbn([ 'type' => Isbn::ISBN13]);
if ($validator->isValid($isbn)) {
// this is a valid ISBN-13 value
} else {
// this is an invalid ISBN-13 value
}
```
The above will validate only ISBN-13 values.
Valid types include:
- `Zend\Validator\Isbn::AUTO` (default)
- `Zend\Validator\Isbn::ISBN10`
- `Zend\Validator\Isbn::ISBN13`
## Specifying a separator restriction
An example of separator restriction:
```php
$validator = new Zend\Validator\Isbn();
$validator->setSeparator('-');
// OR
$validator = new Zend\Validator\Isbn(['separator' => '-']);
if ($validator->isValid($isbn)) {
// this is a valid ISBN with separator
} else {
// this is an invalid ISBN with separator
}
```
> ### Values without separators
>
> This will return `false` if `$isbn` doesn't contain a separator **or** if it's
> an invalid *ISBN* value.
Valid separators include:
- `` (empty) (default)
- `-` (hyphen)
- ` ` (space)
================================================
FILE: docs/book/validators/isinstanceof.md
================================================
# IsInstanceOf Validator
`Zend\Validator\IsInstanceOf` allows you to validate whether a given object is
an instance of a specific class or interface.
## Supported options
The following options are supported for `Zend\Validator\IsInstanceOf`:
- `className`: Defines the fully-qualified class name which objects must be an
instance of.
## Basic usage
```php
$validator = new Zend\Validator\IsInstanceOf([
'className' => 'Zend\Validator\Digits'
]);
$object = new Zend\Validator\Digits();
if ($validator->isValid($object)) {
// $object is an instance of Zend\Validator\Digits
} else {
// false. You can use $validator->getMessages() to retrieve error messages
}
```
If a string argument is passed to the constructor of
`Zend\Validator\IsInstanceOf`, then that value will be used as the class name:
```php
use Zend\Validator\Digits;
use Zend\Validator\IsInstanceOf;
$validator = new IsInstanceOf(Digits::class);
$object = new Digits();
if ($validator->isValid($object)) {
// $object is an instance of Zend\Validator\Digits
} else {
// false. You can use $validator->getMessages() to retrieve error messages
}
```
================================================
FILE: docs/book/validators/less-than.md
================================================
# LessThan Validator
`Zend\Validator\LessThan` allows you to validate if a given value is less than a
maximum value.
> Supports only number validation
>
> `Zend\Validator\LessThan` supports only the validation of numbers. Strings or
> dates can not be validated with this validator.
## Supported options
The following options are supported for `Zend\Validator\LessThan`:
- `inclusive`: Defines if the validation is inclusive the maximum value or
exclusive. It defaults to `false`.
- `max`: Sets the maximum allowed value.
## Basic usage
To validate if a given value is less than a defined maximum:
```php
$valid = new Zend\Validator\LessThan(['max' => 10]);
$value = 12;
$return = $valid->isValid($value);
// returns false
```
The above example returns `true` for all values lower than 10.
## Inclusive validation
Sometimes it is useful to validate a value by including the maximum value:
```php
$valid = new Zend\Validator\LessThan([
'max' => 10,
'inclusive' => true,
]);
$value = 10;
$result = $valid->isValid($value);
// returns true
```
The example is identical to our first example, with the exception that we've
specified that the maximum is inclusive. Now the value '10' is allowed and will
return `true`.
================================================
FILE: docs/book/validators/not-empty.md
================================================
# NotEmpty Validator
This validator allows you to validate if a given value is not empty. This is
often useful when working with form elements or other user input, where you can
use it to ensure required elements have values associated with them.
## Supported options
The following options are supported for `Zend\Validator\NotEmpty`:
- `type`: Sets the type of validation which will be processed; for details, see
the section on [specifying empty behavior](#specifying-empty-behavior).
## Default behaviour
By default, this validator works differently than you would expect when you've
worked with PHP's `empty()` operator. In particular, this validator will
evaluate both the integer `0` and string `'0'` as empty.
```php
$valid = new Zend\Validator\NotEmpty();
$value = '';
$result = $valid->isValid($value);
// returns false
```
## Specifying empty behavior
Some projects have differing opinions of what is considered an "empty" value: a
string with only whitespace might be considered empty, or `0` may be
considered non-empty (particularly for boolean sequences). To accommodate
differing needs, `Zend\Validator\NotEmpty` allows you to configure which types
should be validated as empty and which not.
The following types can be handled:
- `boolean`: Returns `false` when the boolean value is `false`.
- `integer`: Returns `false` when an integer `0` value is given. By default,
this validation is not activate and returns `true` for any integer values.
- `float`: Returns `false` when a float `0.0` value is given. By default, this
validation is not activate and returns `true` on any float values.
- `string`: Returns `false` when an empty string `''` is given.
- `zero`: Returns `false` when the single character zero (`'0'`) is given.
- `empty_array`: Returns `false` when an empty `array` is given.
- `null`: Returns `false` when a `null` value is given.
- `php`: Returns `false` on wherever PHP's `empty()` would return `true`.
- `space`: Returns `false` when an string is given which contains only
whitespace.
- `object`: Returns `true`. `false` will be returned when `object` is not
allowed but an object is given.
- `object_string`: Returns `false` when an object is given and its
`__toString()` method returns an empty string.
- `object_count`: Returns `false` when an object is given, it implements
`Countable`, and its count is 0.
- `all`: Returns `false` on all above types.
All other given values will return `true` per default.
There are several ways to select which of the above types are validated. You can
give one or multiple types and add them, you can provide an array, you can use
constants, or you can provide a textual string. See the following examples:
```php
use Zend\Validator\NotEmpty;
// Returns false on 0
$validator = new NotEmpty(NotEmpty::INTEGER);
// Returns false on 0 or '0'
$validator = new NotEmpty( NotEmpty::INTEGER | NotEmpty::ZERO);
// Returns false on 0 or '0'
$validator = new NotEmpty([ NotEmpty::INTEGER, NotEmpty::ZERO ]);
// Returns false on 0 or '0'
$validator = new NotEmpty(['integer', 'zero']);
```
You can also provide an instance of `Traversable` to set the desired types. To
set types after instantiation, use the `setType()` method.
================================================
FILE: docs/book/validators/regex.md
================================================
# Regex Validator
This validator allows you to validate if a given string conforms a defined
regular expression.
## Supported options
The following options are supported for `Zend\Validator\Regex`:
- `pattern`: Sets the regular expression pattern for this validator.
## Usage
Validation with regular expressions allows complex validations
without writing a custom validator.
```php
$validator = new Zend\Validator\Regex(['pattern' => '/^Test/']);
$validator->isValid("Test"); // returns true
$validator->isValid("Testing"); // returns true
$validator->isValid("Pest"); // returns false
```
The pattern uses the same syntax as `preg_match()`. For details about regular
expressions take a look into [PHP's manual about PCRE pattern
syntax](http://php.net/reference.pcre.pattern.syntax).
## Pattern handling
It is also possible to set a different pattern afterwards by using
`setPattern()` and to get the actual set pattern with `getPattern()`.
```php
$validator = new Zend\Validator\Regex(['pattern' => '/^Test/']);
$validator->setPattern('ing$/');
$validator->isValid("Test"); // returns false
$validator->isValid("Testing"); // returns true
$validator->isValid("Pest"); // returns false
```
================================================
FILE: docs/book/validators/sitemap.md
================================================
# Sitemap Validators
The following validators conform to the
[Sitemap XML protocol](http://www.sitemaps.org/protocol.php).
## Supported options
There are no additional supported options for any of the `Sitemap` validators.
## Changefreq
`Zend\Validator\Sitemap\Changefreq` validates whether a string is valid for
using as a 'changefreq' element in a Sitemap XML document. Valid values are:
'always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', or 'never'.
Returns `true` if and only if the value is a string and is equal to one of the
frequencies specified above.
## Sitemap\\Lastmod
`Zend\Validator\Sitemap\Lastmod` validates whether a string is valid for using
as a 'lastmod' element in a Sitemap XML document. The lastmod element should
contain a W3C date string, optionally discarding information about time.
Returns `true` if and only if the given value is a string and is valid according
to the protocol.
```php
$validator = new Zend\Validator\Sitemap\Lastmod();
$validator->isValid('1999-11-11T22:23:52-02:00'); // true
$validator->isValid('2008-05-12T00:42:52+02:00'); // true
$validator->isValid('1999-11-11'); // true
$validator->isValid('2008-05-12'); // true
$validator->isValid('1999-11-11t22:23:52-02:00'); // false
$validator->isValid('2008-05-12T00:42:60+02:00'); // false
$validator->isValid('1999-13-11'); // false
$validator->isValid('2008-05-32'); // false
$validator->isValid('yesterday'); // false
```
## Loc
`Zend\Validator\Sitemap\Loc` validates whether a string is valid for using as a
'loc' element in a Sitemap XML document. This uses
[Zend\\Uri\\Uri::isValid()](https://docs.zendframework.com/zend-uri/usage/#validating-the-uri)
internally.
> ### Installation requirements
>
> `Zend\Validator\Sitemap\Loc` depends on the zend-uri component, so be sure to
> have it installed before getting started:
>
> ```bash
> $ composer require zendframework/zend-uri
> ```
## Priority
`Zend\Validator\Sitemap\Priority` validates whether a value is valid for using
as a 'priority' element in a Sitemap XML document. The value should be a decimal
between 0.0 and 1.0. This validator accepts both numeric values and string
values.
```php
$validator = new Zend\Validator\Sitemap\Priority();
$validator->isValid('0.1'); // true
$validator->isValid('0.789'); // true
$validator->isValid(0.8); // true
$validator->isValid(1.0); // true
$validator->isValid('1.1'); // false
$validator->isValid('-0.4'); // false
$validator->isValid(1.00001); // false
$validator->isValid(0xFF); // false
$validator->isValid('foo'); // false
```
================================================
FILE: docs/book/validators/step.md
================================================
# Step Validator
`Zend\Validator\Step` allows you to validate if a given value is a valid step
value. This validator requires the value to be a numeric value (either string,
int or float).
## Supported options
The following options are supported for `Zend\Validator\Step`:
- `baseValue`: This is the base value from which the step should be computed.
This option defaults to `0`
- `step`: This is the step value. This option defaults to `1`
## Basic usage
```php
$validator = new Zend\Validator\Step();
if ($validator->isValid(1)) {
// value is a valid step value
} else {
// false
}
```
## Using floating-point values
The `Step` validator also supports floating-point base and step values:
```php
$validator = new Zend\Validator\Step([
'baseValue' => 1.1,
'step' => 2.2,
]);
echo $validator->isValid(1.1); // prints true
echo $validator->isValid(3.3); // prints true
echo $validator->isValid(3.35); // prints false
echo $validator->isValid(2.2); // prints false
```
================================================
FILE: docs/book/validators/string-length.md
================================================
# StringLength Validator
This validator allows you to validate if a given string is between a defined
length.
> ### Supports only string validation
>
> `Zend\Validator\StringLength` supports only the validation of strings.
> Integers, floats, dates or objects can not be validated with this validator.
## Supported options
The following options are supported for `Zend\Validator\StringLength`:
- `encoding`: Sets the `ICONV` encoding to use with the string.
- `min`: Sets the minimum allowed length for a string.
- `max`: Sets the maximum allowed length for a string.
## Default behaviour
By default, this validator checks if a value is between `min` and `max` using a
default `min` value of `0` and default `max` value of `NULL` (meaning unlimited).
As such, without any options, the validator only checks that the input is a
string.
## Limiting the maximum string length
To limit the maximum allowed length of a string you need to set the `max`
property. It accepts an integer value as input.
```php
$validator = new Zend\Validator\StringLength(['max' => 6]);
$validator->isValid("Test"); // returns true
$validator->isValid("Testing"); // returns false
```
You can set the maximum allowed length after instantiation by using the
`setMax()` method; `getMax()` retrieves the value.
```php
$validator = new Zend\Validator\StringLength();
$validator->setMax(6);
$validator->isValid("Test"); // returns true
$validator->isValid("Testing"); // returns false
```
## Limiting the minimum string length
To limit the minimal required string length, set the `min`
property using an integer value:
```php
$validator = new Zend\Validator\StringLength(['min' => 5]);
$validator->isValid("Test"); // returns false
$validator->isValid("Testing"); // returns true
```
You can set the value after instantiation using the `setMin()`
method; `getMin()` retrieves the value.
```php
$validator = new Zend\Validator\StringLength();
$validator->setMin(5);
$validator->isValid("Test"); // returns false
$validator->isValid("Testing"); // returns true
```
## Limiting both minimum and maximum string length
Sometimes you will need to set both a minimum and a maximum string length;
as an example, in a username input, you may want to limit the name to a maximum
of 30 characters, but require at least three charcters:
```php
$validator = new Zend\Validator\StringLength(['min' => 3, 'max' => 30]);
$validator->isValid("."); // returns false
$validator->isValid("Test"); // returns true
$validator->isValid("Testing"); // returns true
```
## Limiting to a strict length
If you need a strict length, then set the `min` and `max` properties to the same
value:
```php
$validator = new Zend\Validator\StringLength(['min' => 4, 'max' => 4]);
$validator->isValid('Tes'); // returns false
$validator->isValid('Test'); // returns true
$validator->isValid('Testi'); // returns false
```
> ### Setting a maximum lower than the minimum
>
> When you try to set a lower maximum value than the specified minimum value, or
> a higher minimum value as the actual maximum value, the validator will raise
> an exception.
## Encoding of values
Strings are always using a encoding. Even when you don't set the encoding
explicitly, PHP uses one. When your application is using a different encoding
than PHP itself, you should set an encoding manually.
You can set an encoding at instantiation with the `encoding` option, or by using
the `setEncoding()` method. We assume that your installation uses ISO and your
application it set to ISO. In this case you will see the below behaviour.
```php
$validator = new Zend\Validator\StringLength(['min' => 6]);
$validator->isValid("Ärger"); // returns false
$validator->setEncoding("UTF-8");
$validator->isValid("Ärger"); // returns true
$validator2 = new Zend\Validator\StringLength([
'min' => 6,
'encoding' => 'UTF-8',
]);
$validator2->isValid("Ärger"); // returns true
```
When your installation and your application are using different encodings, then
you should always set an encoding manually.
## Validation Messages
Using the setMessage() method you can set another message to be returned in case of the specified failure.
```php
$validator = new Zend\Validator\StringLength(['min' => 3, 'max' => 30]);
$validator->setMessage('Youre string is too long. You typed '%length%' chars.', Zend\Validator\StringLength::TOO_LONG);
```
================================================
FILE: docs/book/validators/timezone.md
================================================
# Timezone Validator
`Zend\Validator\Timezone` allows validating if an input string represents a
timezone.
## Supported validation types
The `Zend\Validator\Timezone` validator is capable of validating the
abbreviation (e.g. `ewt`) as well as the location string (e.g.
`America/Los_Angeles`). These options are stored in the validator as
`LOCATION`, `ABBREVIATION`, and `ALL` class constants.
## Basic Usage
The default validation type will check against abbreviations as well as the
location string.
```php
$validator = new Zend\Validator\Timezone();
$validator->isValid('America/Los_Angeles'); // returns true
$validator->isValid('ewt'); // returns true
$validator->isValid('Foobar'); // returns false
```
To validate against only the location string you can set the type:
```php
use Zend\Validator\Timezone;
$validator = new Timezone();
$validator->setType(Timezone::LOCATION);
$validator->isValid('America/Los_Angeles'); // returns true
$validator->isValid('ewt'); // returns false
$validator->isValid('Foobar'); // returns false
```
================================================
FILE: docs/book/validators/undisclosed-password.md
================================================
# Undisclosed Password Validator
- **Since 2.13.0**
`Zend\Validator\UndisclosedPassword` allows you to validate if a given password was found in data breaches using the service [Have I Been Pwned?](https://www.haveibeenpwned.com), in a secure, anonymous way using [K-Anonymity](https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2) to ensure passwords are not send in full over the wire.
> ### Installation requirements
>
> This validator needs to make a request over HTTP; therefore it requires an HTTP client. The validator provides support only for HTTP clients implementing [PSR-18](https://www.php-fig.org/psr/psr-18/) and [PSR-17](https://www.php-fig.org/psr/psr-17/) request and response factories.
>
> To ensure you have these installed before using this validator, run the following:
>
> ```bash
> $ composer require psr/http-client
> $ composer require psr/http-factory
> ```
## Basic usage
The validator has three required constructor arguments:
- an HTTP Client that implements `Psr\Http\Client\ClientInterface`
- a `Psr\Http\Message\RequestFactoryInterface` instance
- a `Psr\Http\Message\ResponseFactoryInterface` instance
Once you have an instance, you can then pass a password to its `isValid()` method to determine if it has been disclosed in a known data breach.
If the password was found via the service, `isValid()` will return `false`. If the password was not found, `isValid()` will return `true`.
```php
$validator = new Zend\Validator\UndisclosedPassword(
$httpClient, // a PSR-18 HttpClientInterface
$requestFactory, // a PSR-17 RequestFactoryInterface
$responseFactory // a PSR-17 ResponseFactoryInterface
);
$result = $validator->isValid('password');
// $result is FALSE because "password" was found in a data breach
$result = $validator->isValid('8aDk=XiW2E.77tLfuAcB');
// $result is TRUE because "8aDk=XiW2E.77tLfuAcB" was not found in a data breach
```
## A simple command line example
In this example, I'm using `zendframework/zend-diactoros` to provide HTTP messages, and `php-http/curl-client` as the HTTP client. Let's begin with installation of all required packages:
```bash
$ composer require \
php-http/message \
php-http/message-factory \
php-http/discovery \
php-http/curl-client \
zendframework/zend-diactoros \
zendframework/zend-validator
```
Next, I create a file, `undisclosed.php`, where I put my code:
```php
<?php
namespace Undisclosed;
use Http\Client\Curl\Client;
use Zend\Diactoros\RequestFactory;
use Zend\Diactoros\ResponseFactory;
use Zend\Validator\UndisclosedPassword;
require_once __DIR__ . '/vendor/autoload.php';
$requestFactory = new RequestFactory();
$responseFactory = new ResponseFactory();
$client = new Client($responseFactory, null);
$undisclosedPassword = new UndisclosedPassword($client, $requestFactory, $responseFactory);
echo 'Password "password" is ' . ($undisclosedPassword->isValid('password') ? 'not disclosed' : 'disclosed') . PHP_EOL;
echo 'Password "NVt3MpvQ" is ' . ($undisclosedPassword->isValid('NVt3MpvQ') ? 'not disclosed' : 'disclosed') . PHP_EOL;
```
To run it, I use the PHP command line interpreter:
```bash
$ php undisclosed.php
```
And it gives me the following output:
```bash
Password "password" is disclosed
Password "NVt3MpvQ" is not disclosed
```
================================================
FILE: docs/book/validators/uri.md
================================================
# Uri Validator
`Zend\Validator\Uri` allows you to validate a URI using the `Zend\Uri\Uri`
handler to parse the URI. The validator allows for both validation of absolute
and/or relative URIs. There is the possibility to exchange the handler for
another one in case the parsing of the uri should be done differently.
## Supported options
The following options are supported for `Zend\Validator\Uri`:
- `uriHandler`: Defines the handler to be used to parse the uri. This options
defaults to a new instance of `Zend\Uri\Uri`.
- `allowRelative`: Defines if relative paths are allowed. This option defaults
to `true`.
- `allowAbsolute`: Defines if absolute paths are allowed. This option defaults
to `true`.
## Basic usage
```php
$validator = new Zend\Validator\Uri();
$uri = 'http://framework.zend.com/manual';
if ($validator->isValid($uri)) {
// $uri was valid
} else {
// false. You can use $validator->getMessages() to retrieve error messages
}
```
================================================
FILE: docs/book/validators/uuid.md
================================================
# UUID Validator
`Zend\Validator\Uuid` allows validating [Universally Unique IDentifiers](https://en.wikipedia.org/wiki/Universally_unique_identifier)
(UUIDs). UUIDs are 128-bit values that are guaranteed to be "practically unique"
in order to help prevent identifier conflicts. Five separate UUID versions
exist:
- Version 1, which uses a combination of date-time and hardware MAC addresses to
generate the hash.
- Version 2, which uses a combination of date-time and system user/group identifiers.
- Version 3, which uses an MD5sum of a URI or distinguished name to generate the
hash.
- Version 4, which uses a CSPRNG to generate the hash.
- Version 5, which uses the same idea as Version 3, but using SHA-1 for hashing.
The `Uuid` validator is capable of validating whether a string is a valid UUID
of any version. It does not validate that the UUID exists in your system,
however, only that it is well-formed.
> ### Introduced in 2.8.0
>
> `Zend\Validator\Uuid` was introduced with version 2.8.0.
## Supported options
The `Uuid` validator has no additional options.
## Basic usage
```php
$validator = new Zend\Validator\Uuid();
if ($validator->isValid($uuid)) {
// UUID was valid
} else {
// Invalid/mal-formed UUID; use $validator->getMessages() for more detail
}
```
================================================
FILE: docs/book/writing-validators.md
================================================
# Writing Validators
zend-validator supplies a set of commonly needed validators, but many
applications have needs for custom validators. The component allows this via
implementations of `Zend\Validator\ValidatorInterface`.
`Zend\Validator\ValidatorInterface` defines two methods: `isValid()` and
`getMessages()`. An object that implements the interface may be added to a
validator chain using `Zend\Validator\ValidatorChain::addValidator()`. Such
objects may also be used with
[zend-inputfilter](https://docs.zendframework.com/zend-inputfilter).
Validators will return a boolean value from `isValid()`, and report information
regarding **why** a value failed validation via `getMessages()`. The
availability of the reasons for validation failures may be valuable to an
application for various purposes, such as providing statistics for usability
analysis.
Basic validation failure message functionality is implemented in
`Zend\Validator\AbstractValidator`, which you may extend for your custom
validators. Extending class you would implement the `isValid()` method logic
and define the message variables and message templates that correspond to the
types of validation failures that can occur. If a value fails your validation
tests, then `isValid()` should return `false`. If the value passes your
validation tests, then `isValid()` should return `true`.
In general, the `isValid()` method should not throw any exceptions, except where
it is impossible to determine whether or not the input value is valid. A few
examples of reasonable cases for throwing an exception might be if a file cannot
be opened, an LDAP server could not be contacted, or a database connection is
unavailable, where such a thing may be required for validation success or
failure to be determined.
## Creating a Validation Class
The following example demonstrates how a custom validator might be written. In
this case, the validator tests that a value is a floating point value.
```php
namespace MyValid;
use Zend\Validator\AbstractValidator;
class Float extends AbstractValidator
{
const FLOAT = 'float';
protected $messageTemplates = [
self::FLOAT => "'%value%' is not a floating point value",
];
public function isValid($value)
{
$this->setValue($value);
if (! is_float($value)) {
$this->error(self::FLOAT);
return false;
}
return true;
}
}
```
The class defines a template for its single validation failure message, which
includes the built-in magic parameter, `%value%`. The call to `setValue()`
prepares the object to insert the tested value into the failure message
automatically, should the value fail validation. The call to `error()` tracks a
reason for validation failure. Since this class only defines one failure
message, it is not necessary to provide `error()` with the name of the failure
message template.
## Writing a Validation Class having Dependent Conditions
The following example demonstrates a more complex set of validation rules:
- The input must be numeric.
- The input must fall within a range of boundary values.
An input value would fail validation for exactly one of the following reasons:
- The input value is not numeric.
- The input value is less than the minimum allowed value.
- The input value is more than the maximum allowed value.
These validation failure reasons are then translated to definitions in the
class:
```php
namespace MyValid;
use Zend\Validator\AbstractValidator;
class NumericBetween extends AbstractValidator
{
const MSG_NUMERIC = 'msgNumeric';
const MSG_MINIMUM = 'msgMinimum';
const MSG_MAXIMUM = 'msgMaximum';
public $minimum = 0;
public $maximum = 100;
protected $messageVariables = [
'min' => 'minimum',
'max' => 'maximum',
];
protected $messageTemplates = [
self::MSG_NUMERIC => "'%value%' is not numeric",
self::MSG_MINIMUM => "'%value%' must be at least '%min%'",
self::MSG_MAXIMUM => "'%value%' must be no more than '%max%'",
];
public function isValid($value)
{
$this->setValue($value);
if (! is_numeric($value)) {
$this->error(self::MSG_NUMERIC);
return false;
}
if ($value < $this->minimum) {
$this->error(self::MSG_MINIMUM);
return false;
}
if ($value > $this->maximum) {
$this->error(self::MSG_MAXIMUM);
return false;
}
return true;
}
}
```
The public properties `$minimum` and `$maximum` have been established to provide
the minimum and maximum boundaries, respectively, for a value to successfully
validate. The class also defines two message variables that correspond to the
public properties and allow `min` and `max` to be used in message templates as
magic parameters, just as with `value`.
Note that if any one of the validation checks in `isValid()` fails, an
appropriate failure message is prepared, and the method immediately returns
`false`. These validation rules are therefore sequentially dependent; that is,
if one test should fail, there is no need to test any subsequent validation
rules. This need not be the case, however. The following example illustrates how
to write a class having independent validation rules, where the validation
object may return multiple reasons why a particular validation attempt failed.
## Validation with Independent Conditions, Multiple Reasons for Failure
Consider writing a validation class for password strength enforcement - when a
user is required to choose a password that meets certain criteria for helping
secure user accounts. Let us assume that the password security criteria enforce
that the password:
- is at least 8 characters in length,
- contains at least one uppercase letter,
- contains at least one lowercase letter,
- and contains at least one digit character.
The following class implements these validation criteria:
```php
namespace MyValid;
use Zend\Validator\AbstractValidator;
class PasswordStrength extends AbstractValidator
{
const LENGTH = 'length';
const UPPER = 'upper';
const LOWER = 'lower';
const DIGIT = 'digit';
protected $messageTemplates = [
self::LENGTH => "'%value%' must be at least 8 characters in length",
self::UPPER => "'%value%' must contain at least one uppercase letter",
self::LOWER => "'%value%' must contain at least one lowercase letter",
self::DIGIT => "'%value%' must contain at least one digit character",
];
public function isValid($value)
{
$this->setValue($value);
$isValid = true;
if (strlen($value) < 8) {
$this->error(self::LENGTH);
$isValid = false;
}
if (! preg_match('/[A-Z]/', $value)) {
$this->error(self::UPPER);
$isValid = false;
}
if (! preg_match('/[a-z]/', $value)) {
$this->error(self::LOWER);
$isValid = false;
}
if (! preg_match('/\d/', $value)) {
$this->error(self::DIGIT);
$isValid = false;
}
return $isValid;
}
}
```
Note that the four criteria tests in `isValid()` do not immediately return
`false`. This allows the validation class to provide **all** of the reasons that
the input password failed to meet the validation requirements. If, for example,
a user were to input the string `#$%` as a password, `isValid()` would cause
all four validation failure messages to be returned by a subsequent call to
`getMessages()`.
================================================
FILE: mkdocs.yml
================================================
docs_dir: docs/book
site_dir: docs/html
nav:
- Home: index.md
- Introduction: intro.md
- Reference:
- "Validator Chains": validator-chains.md
- "Writing Validators": writing-validators.md
- "Validation Messages": messages.md
- "Standard Validation Classes": set.md
- Validators:
- Barcode: validators/barcode.md
- Between: validators/between.md
- Callback: validators/callback.md
- CreditCard: validators/credit-card.md
- Date: validators/date.md
- "Db\\RecordExists and Db\\NoRecordExists": validators/db.md
- Digits: validators/digits.md
- EmailAddress: validators/email-address.md
- Explode: validators/explode.md
- GreaterThan: validators/greater-than.md
- Hex: validators/hex.md
- Hostname: validators/hostname.md
- Iban: validators/iban.md
- Identical: validators/identical.md
- 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
- Regex: validators/regex.md
- Sitemap: validators/sitemap.md
- Step: validators/step.md
- StringLength: validators/string-length.md
- Timezone: validators/timezone.md
- UndisclosedPassword: validators/undisclosed-password.md
- Uri: validators/uri.md
- Uuid: validators/uuid.md
- "File Validators":
- Introduction: validators/file/intro.md
- Count: validators/file/count.md
- Crc32: validators/file/crc32.md
- ExcludeExtension: validators/file/exclude-extension.md
- ExcludeMimeType: validators/file/exclude-mime-type.md
- Exists: validators/file/exists.md
- Extension: validators/file/extension.md
- FilesSize: validators/file/files-size.md
- Hash: validators/file/hash.md
- ImageSize: validators/file/image-size.md
- IsCompressed: validators/file/is-compressed.md
- IsImage: validators/file/is-image.md
- Md5: validators/file/md5.md
- MimeType: validators/file/mime-type.md
- NotExists: validators/file/not-exists.md
- Sha1: validators/file/sha1.md
- Size: validators/file/size.md
- Upload: validators/file/upload.md
- UploadFile: validators/file/upload-file.md
- WordCount: validators/file/word-count.md
site_name: zend-validator
site_description: "Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria."
repo_url: 'https://github.com/zendframework/zend-validator'
================================================
FILE: phpcs.xml
================================================
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
================================================
FILE: phpunit.xml.dist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
colors="true">
<testsuites>
<testsuite name="zend-validator Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<ini name="date.timezone" value="UTC"/>
<!-- OB_ENABLED should be enabled for some tests to check if all
functionality works as expected. Such tests include those for
Zend\Soap and Zend\Session, which require that headers not be sent
in order to work. -->
<env name="TESTS_ZEND_OB_ENABLED" value="false" />
<env name="TESTS_ZEND_VALIDATOR_ONLINE_ENABLED" value="false" />
</php>
</phpunit>
================================================
FILE: src/AbstractValidator.php
================================================
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Validator;
use Traversable;
use Zend\Stdlib\ArrayUtils;
abstract class AbstractValidator implements
Translator\TranslatorAwareInterface,
ValidatorInterface
{
/**
* The value to be validated
*
* @var mixed
*/
protected $value;
/**
* Default translation object for all validate objects
* @var Translator\TranslatorInterface
*/
protected static $defaultTranslator;
/**
* Default text domain to be used with translator
* @var string
*/
protected static $defaultTranslatorTextDomain = 'default';
/**
* Limits the maximum returned length of an error message
*
* @var int
*/
protected static $messageLength = -1;
protected $abstractOptions = [
'messages' => [], // Array of validation failure messages
'messageTemplates' => [], // Array of validation fail
gitextract_70x1ddz0/
├── .coveralls.yml
├── .gitattributes
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── bin/
│ └── update_hostname_validator.php
├── composer.json
├── docs/
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── ISSUE_TEMPLATE.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── SUPPORT.md
│ └── book/
│ ├── index.md
│ ├── intro.md
│ ├── messages.md
│ ├── set.md
│ ├── validator-chains.md
│ ├── validators/
│ │ ├── barcode.md
│ │ ├── between.md
│ │ ├── callback.md
│ │ ├── credit-card.md
│ │ ├── date.md
│ │ ├── db.md
│ │ ├── digits.md
│ │ ├── email-address.md
│ │ ├── explode.md
│ │ ├── file/
│ │ │ ├── count.md
│ │ │ ├── crc32.md
│ │ │ ├── exclude-extension.md
│ │ │ ├── exclude-mime-type.md
│ │ │ ├── exists.md
│ │ │ ├── extension.md
│ │ │ ├── files-size.md
│ │ │ ├── hash.md
│ │ │ ├── image-size.md
│ │ │ ├── intro.md
│ │ │ ├── is-compressed.md
│ │ │ ├── is-image.md
│ │ │ ├── md5.md
│ │ │ ├── mime-type.md
│ │ │ ├── not-exists.md
│ │ │ ├── sha1.md
│ │ │ ├── size.md
│ │ │ ├── upload-file.md
│ │ │ ├── upload.md
│ │ │ └── word-count.md
│ │ ├── greater-than.md
│ │ ├── hex.md
│ │ ├── hostname.md
│ │ ├── iban.md
│ │ ├── identical.md
│ │ ├── in-array.md
│ │ ├── ip.md
│ │ ├── is-countable.md
│ │ ├── isbn.md
│ │ ├── isinstanceof.md
│ │ ├── less-than.md
│ │ ├── not-empty.md
│ │ ├── regex.md
│ │ ├── sitemap.md
│ │ ├── step.md
│ │ ├── string-length.md
│ │ ├── timezone.md
│ │ ├── undisclosed-password.md
│ │ ├── uri.md
│ │ └── uuid.md
│ └── writing-validators.md
├── mkdocs.yml
├── phpcs.xml
├── phpunit.xml.dist
├── src/
│ ├── AbstractValidator.php
│ ├── Barcode/
│ │ ├── AbstractAdapter.php
│ │ ├── AdapterInterface.php
│ │ ├── Codabar.php
│ │ ├── Code128.php
│ │ ├── Code25.php
│ │ ├── Code25interleaved.php
│ │ ├── Code39.php
│ │ ├── Code39ext.php
│ │ ├── Code93.php
│ │ ├── Code93ext.php
│ │ ├── Ean12.php
│ │ ├── Ean13.php
│ │ ├── Ean14.php
│ │ ├── Ean18.php
│ │ ├── Ean2.php
│ │ ├── Ean5.php
│ │ ├── Ean8.php
│ │ ├── Gtin12.php
│ │ ├── Gtin13.php
│ │ ├── Gtin14.php
│ │ ├── Identcode.php
│ │ ├── Intelligentmail.php
│ │ ├── Issn.php
│ │ ├── Itf14.php
│ │ ├── Leitcode.php
│ │ ├── Planet.php
│ │ ├── Postnet.php
│ │ ├── Royalmail.php
│ │ ├── Sscc.php
│ │ ├── Upca.php
│ │ └── Upce.php
│ ├── Barcode.php
│ ├── Between.php
│ ├── Bitwise.php
│ ├── Callback.php
│ ├── ConfigProvider.php
│ ├── CreditCard.php
│ ├── Csrf.php
│ ├── Date.php
│ ├── DateStep.php
│ ├── Db/
│ │ ├── AbstractDb.php
│ │ ├── NoRecordExists.php
│ │ └── RecordExists.php
│ ├── Digits.php
│ ├── EmailAddress.php
│ ├── Exception/
│ │ ├── BadMethodCallException.php
│ │ ├── ExceptionInterface.php
│ │ ├── ExtensionNotLoadedException.php
│ │ ├── InvalidArgumentException.php
│ │ ├── InvalidMagicMimeFileException.php
│ │ └── RuntimeException.php
│ ├── Explode.php
│ ├── File/
│ │ ├── Count.php
│ │ ├── Crc32.php
│ │ ├── ExcludeExtension.php
│ │ ├── ExcludeMimeType.php
│ │ ├── Exists.php
│ │ ├── Extension.php
│ │ ├── FileInformationTrait.php
│ │ ├── FilesSize.php
│ │ ├── Hash.php
│ │ ├── ImageSize.php
│ │ ├── IsCompressed.php
│ │ ├── IsImage.php
│ │ ├── Md5.php
│ │ ├── MimeType.php
│ │ ├── NotExists.php
│ │ ├── Sha1.php
│ │ ├── Size.php
│ │ ├── Upload.php
│ │ ├── UploadFile.php
│ │ └── WordCount.php
│ ├── GpsPoint.php
│ ├── GreaterThan.php
│ ├── Hex.php
│ ├── Hostname/
│ │ ├── Biz.php
│ │ ├── Cn.php
│ │ ├── Com.php
│ │ └── Jp.php
│ ├── Hostname.php
│ ├── Iban.php
│ ├── Identical.php
│ ├── InArray.php
│ ├── Ip.php
│ ├── IsCountable.php
│ ├── IsInstanceOf.php
│ ├── Isbn/
│ │ ├── Isbn10.php
│ │ └── Isbn13.php
│ ├── Isbn.php
│ ├── LessThan.php
│ ├── Module.php
│ ├── NotEmpty.php
│ ├── Regex.php
│ ├── Sitemap/
│ │ ├── Changefreq.php
│ │ ├── Lastmod.php
│ │ ├── Loc.php
│ │ └── Priority.php
│ ├── StaticValidator.php
│ ├── Step.php
│ ├── StringLength.php
│ ├── Timezone.php
│ ├── Translator/
│ │ ├── TranslatorAwareInterface.php
│ │ └── TranslatorInterface.php
│ ├── UndisclosedPassword.php
│ ├── Uri.php
│ ├── Uuid.php
│ ├── ValidatorChain.php
│ ├── ValidatorInterface.php
│ ├── ValidatorPluginManager.php
│ ├── ValidatorPluginManagerAwareInterface.php
│ ├── ValidatorPluginManagerFactory.php
│ └── ValidatorProviderInterface.php
└── test/
├── AbstractTest.php
├── BarcodeTest.php
├── BetweenTest.php
├── BitwiseTest.php
├── CallbackTest.php
├── CreditCardTest.php
├── CsrfTest.php
├── DateStepTest.php
├── DateTest.php
├── Db/
│ ├── AbstractDbTest.php
│ ├── NoRecordExistsTest.php
│ ├── RecordExistsTest.php
│ └── TestAsset/
│ ├── ConcreteDbValidator.php
│ └── TrustingSql92Platform.php
├── DigitsTest.php
├── EmailAddressTest.php
├── ExplodeTest.php
├── File/
│ ├── CountTest.php
│ ├── Crc32Test.php
│ ├── ExcludeExtensionTest.php
│ ├── ExcludeMimeTypeTest.php
│ ├── ExistsTest.php
│ ├── ExtensionTest.php
│ ├── FileInformationTraitTest.php
│ ├── FilesSizeTest.php
│ ├── HashTest.php
│ ├── ImageSizeTest.php
│ ├── IsCompressedTest.php
│ ├── IsImageTest.php
│ ├── Md5Test.php
│ ├── MimeTypeTest.php
│ ├── NotExistsTest.php
│ ├── Sha1Test.php
│ ├── SizeTest.php
│ ├── TestAsset/
│ │ └── FileInformation.php
│ ├── UploadFileTest.php
│ ├── UploadTest.php
│ ├── WordCountTest.php
│ └── _files/
│ ├── magic.7.mime
│ ├── magic.lte.5.3.10.mime
│ ├── magic.mime
│ ├── testsize.mo
│ ├── testsize2.mo
│ ├── testsize3.mo
│ ├── testsize4.mo
│ └── wordcount.txt
├── GPSPointTest.php
├── GreaterThanTest.php
├── HexTest.php
├── HostnameTest.php
├── IbanTest.php
├── IdenticalTest.php
├── InArrayTest.php
├── IpTest.php
├── IsCountableTest.php
├── IsInstanceOfTest.php
├── IsbnTest.php
├── LessThanTest.php
├── MessageTest.php
├── NotEmptyTest.php
├── RegexTest.php
├── Sitemap/
│ ├── ChangefreqTest.php
│ ├── LastmodTest.php
│ ├── LocTest.php
│ └── PriorityTest.php
├── StaticValidatorTest.php
├── StepTest.php
├── StringLengthTest.php
├── TestAsset/
│ ├── ArrayTranslator.php
│ ├── ConcreteValidator.php
│ ├── CreditCardValidatorExtension.php
│ ├── EmailValidatorWithExposedIsReserved.php
│ ├── HttpClientException.php
│ ├── SessionManager.php
│ └── Translator.php
├── TimezoneTest.php
├── UndisclosedPasswordTest.php
├── UriTest.php
├── UuidTest.php
├── ValidatorChainTest.php
├── ValidatorPluginManagerCompatibilityTest.php
├── ValidatorPluginManagerFactoryTest.php
├── ValidatorPluginManagerTest.php
└── _files/
├── MyBarcode1.php
├── MyBarcode2.php
├── MyBarcode3.php
├── MyBarcode4.php
└── MyBarcode5.php
Condensed preview — 273 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (3,334K chars).
[
{
"path": ".coveralls.yml",
"chars": 61,
"preview": "coverage_clover: clover.xml\njson_path: coveralls-upload.json\n"
},
{
"path": ".gitattributes",
"chars": 267,
"preview": "/.coveralls.yml export-ignore\n/.gitattributes export-ignore\n/.gitignore export-ignore\n/.travis.yml export-ignore\n/compos"
},
{
"path": ".gitignore",
"chars": 106,
"preview": "/clover.xml\n/coveralls-upload.json\n/docs/html/\n/phpunit.xml\n/vendor/\n/zf-mkdoc-theme.tgz\n/zf-mkdoc-theme/\n"
},
{
"path": ".travis.yml",
"chars": 2141,
"preview": "language: php\n\nbranches:\n except:\n - /^release-.*$/\n - /^ghgfk-.*$/\n\ncache:\n directories:\n - $HOME/.composer/"
},
{
"path": "CHANGELOG.md",
"chars": 19590,
"preview": "# Changelog\n\nAll notable changes to this project will be documented in this file, in reverse chronological order by rele"
},
{
"path": "LICENSE.md",
"chars": 1516,
"preview": "Copyright (c) 2005-2019, Zend Technologies USA, Inc.\nAll rights reserved.\n\nRedistribution and use in source and binary f"
},
{
"path": "README.md",
"chars": 1108,
"preview": "# zend-validator\n\n> ## Repository abandoned 2019-12-31\n>\n> This repository has moved to [laminas/laminas-validator](http"
},
{
"path": "bin/update_hostname_validator.php",
"chars": 5571,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "composer.json",
"chars": 3416,
"preview": "{\n \"name\": \"zendframework/zend-validator\",\n \"description\": \"Validation classes for a wide range of domains, and th"
},
{
"path": "docs/CODE_OF_CONDUCT.md",
"chars": 2360,
"preview": "# Contributor Code of Conduct\n\nThis project adheres to [The Code Manifesto](http://codemanifesto.com)\nas its guidelines "
},
{
"path": "docs/CONTRIBUTING.md",
"chars": 5411,
"preview": "# CONTRIBUTING\n\n## RESOURCES\n\nIf you wish to contribute to this project, please be sure to\nread/subscribe to the followi"
},
{
"path": "docs/ISSUE_TEMPLATE.md",
"chars": 763,
"preview": " - [ ] I was not able to find an [open](https://github.com/zendframework/zend-validator/issues?q=is%3Aopen) or [closed]("
},
{
"path": "docs/PULL_REQUEST_TEMPLATE.md",
"chars": 1148,
"preview": "Provide a narrative description of what you are trying to accomplish:\n\n- [ ] Are you fixing a bug?\n - [ ] Detail how th"
},
{
"path": "docs/SUPPORT.md",
"chars": 1002,
"preview": "# Getting Support\n\nZend Framework offers three support channels:\n\n- For real-time questions, use our\n [chat](https://ze"
},
{
"path": "docs/book/index.md",
"chars": 15,
"preview": "../../README.md"
},
{
"path": "docs/book/intro.md",
"chars": 8842,
"preview": "# Introduction\n\nzend-validator provides a set of commonly needed validators. It also provides a\nsimple validator chainin"
},
{
"path": "docs/book/messages.md",
"chars": 3932,
"preview": "# Validation Messages\n\nEach validator based on `Zend\\Validator\\ValidatorInterface` provides one or\nmultiple messages in "
},
{
"path": "docs/book/set.md",
"chars": 1512,
"preview": "# Standard Validation Classes\n\nThe following validators come with the zend-validator distribution.\n\n- [Barcode](validato"
},
{
"path": "docs/book/validator-chains.md",
"chars": 3633,
"preview": "# Validator Chains\n\n## Basic Usage\n\n> ### Installation requirements\n>\n> The validator chain depends on the zend-servicem"
},
{
"path": "docs/book/validators/barcode.md",
"chars": 12036,
"preview": "# Barcode Validator\n\n`Zend\\Validator\\Barcode` allows you to check if a given value can be represented\nas a barcode.\n\n## "
},
{
"path": "docs/book/validators/between.md",
"chars": 1625,
"preview": "# Between Validator\n\n`Zend\\Validator\\Between` allows you to validate if a given value is between two\nother values.\n\n> ##"
},
{
"path": "docs/book/validators/callback.md",
"chars": 4434,
"preview": "# Callback Validator\n\n`Zend\\Validator\\Callback` allows you to provide a callback with which to\nvalidate a given value.\n\n"
},
{
"path": "docs/book/validators/credit-card.md",
"chars": 5264,
"preview": "# CreditCard Validator\n\n`Zend\\Validator\\CreditCard` allows you to validate if a given value could be a\ncredit card numbe"
},
{
"path": "docs/book/validators/date.md",
"chars": 1898,
"preview": "# Date Validator\n\n`Zend\\Validator\\Date` allows you to validate if a given value contains a date.\n\n## Supported options\n\n"
},
{
"path": "docs/book/validators/db.md",
"chars": 5623,
"preview": "# Db\\\\RecordExists and Db\\\\NoRecordExists Validators\n\n`Zend\\Validator\\Db\\RecordExists` and `Zend\\Validator\\Db\\NoRecordEx"
},
{
"path": "docs/book/validators/digits.md",
"chars": 1072,
"preview": "# Digits Validator\n\n`Zend\\Validator\\Digits` validates if a given value contains only digits.\n\n> ### Installation require"
},
{
"path": "docs/book/validators/email-address.md",
"chars": 8172,
"preview": "# EmailAddress Validator\n\n`Zend\\Validator\\EmailAddress` allows you to validate an email address. The\nvalidator first spl"
},
{
"path": "docs/book/validators/explode.md",
"chars": 1412,
"preview": "# Explode Validator\n\n`Zend\\Validator\\Explode` executes a validator for each item exploded from an\narray.\n\n## Supported o"
},
{
"path": "docs/book/validators/file/count.md",
"chars": 797,
"preview": "# Count\n\n`Zend\\Validator\\File\\Count` allows you to validate that the number of files\nuploaded matches criteria, includin"
},
{
"path": "docs/book/validators/file/crc32.md",
"chars": 1298,
"preview": "# Crc32\n\n`Zend\\Validator\\File\\Crc32` allows you to validate if a given file's hashed\ncontents matches the supplied crc32"
},
{
"path": "docs/book/validators/file/exclude-extension.md",
"chars": 319,
"preview": "# ExcludeExtension\n\n`Zend\\Validator\\File\\ExcludeExtension` checks the extension of files. It will\nassert `false` when a "
},
{
"path": "docs/book/validators/file/exclude-mime-type.md",
"chars": 346,
"preview": "ExcludeMimeType\n===============\n\n`Zend\\Validator\\File\\ExcludeMimeType` checks the MIME type of files. It will\nassert `fa"
},
{
"path": "docs/book/validators/file/exists.md",
"chars": 868,
"preview": "# Exists\n\n`Zend\\Validator\\File\\Exists` checks for the existence of files in specified\ndirectories.\n\nThis validator is in"
},
{
"path": "docs/book/validators/file/extension.md",
"chars": 1426,
"preview": "# Extension\n\n`Zend\\Validator\\File\\Extension` checks the extension of files. It will assert\n`true` when a given file matc"
},
{
"path": "docs/book/validators/file/files-size.md",
"chars": 1217,
"preview": "# FilesSize\n\n`Zend\\Validator\\File\\FilesSize` allows validating the total size of all file\nuploads in aggregate, allowing"
},
{
"path": "docs/book/validators/file/hash.md",
"chars": 1411,
"preview": "# Hash\n\n`Zend\\Validator\\File\\Hash` allows you to validate if a given file's hashed\ncontents matches the supplied hash(es"
},
{
"path": "docs/book/validators/file/image-size.md",
"chars": 1610,
"preview": "# ImageSize\n\n`Zend\\Validator\\File\\ImageSize` checks the size of image files. Minimum and/or\nmaximum dimensions can be se"
},
{
"path": "docs/book/validators/file/intro.md",
"chars": 910,
"preview": "# File Validation Classes\n\nZend Framework comes with a set of classes for validating both files and\nuploaded files, such"
},
{
"path": "docs/book/validators/file/is-compressed.md",
"chars": 635,
"preview": "# IsCompressed\n\n`Zend\\Validator\\File\\IsCompressed` checks if a file is a compressed archive,\nsuch as zip or gzip. This v"
},
{
"path": "docs/book/validators/file/is-image.md",
"chars": 595,
"preview": "# IsImage\n\n`Zend\\Validator\\File\\IsImage` checks if a file is an image, such as jpg or png.\nThis validator is based on th"
},
{
"path": "docs/book/validators/file/md5.md",
"chars": 1338,
"preview": "# Md5\n\n`Zend\\Validator\\File\\Md5` allows you to validate if a given file's hashed\ncontents matches the supplied md5 hash("
},
{
"path": "docs/book/validators/file/mime-type.md",
"chars": 2326,
"preview": "# MimeType\n\n`Zend\\Validator\\File\\MimeType` checks the MIME type of files. It will assert\n`true` when a given file matche"
},
{
"path": "docs/book/validators/file/not-exists.md",
"chars": 1043,
"preview": "# NotExists\n\n`Zend\\Validator\\File\\NotExists` checks for the existence of files in specified\ndirectories.\n\nThis validator"
},
{
"path": "docs/book/validators/file/sha1.md",
"chars": 1363,
"preview": "# Sha1\n\n`Zend\\Validator\\File\\Sha1` allows you to validate if a given file's hashed\ncontents matches the supplied sha1 ha"
},
{
"path": "docs/book/validators/file/size.md",
"chars": 989,
"preview": "# Size\n\n`Zend\\Validator\\File\\Size` checks for the size of a file.\n\n## Supported Options\n\nThe following set of options ar"
},
{
"path": "docs/book/validators/file/upload-file.md",
"chars": 1192,
"preview": "# UploadFile\n\n`Zend\\Validator\\File\\UploadFile` checks whether a single file has been uploaded\nvia a form `POST` and will"
},
{
"path": "docs/book/validators/file/upload.md",
"chars": 1476,
"preview": "# Upload\n\n`Zend\\Validator\\File\\Upload` validates that a file upload operation was\nsuccessful.\n\n## Supported Options\n\n`Ze"
},
{
"path": "docs/book/validators/file/word-count.md",
"chars": 795,
"preview": "# WordCount\n\n`Zend\\Validator\\File\\WordCount` validates that the number of words within a file\nmatch the specified criter"
},
{
"path": "docs/book/validators/greater-than.md",
"chars": 1264,
"preview": "# GreaterThan Validator\n\n`Zend\\Validator\\GreaterThan` allows you to validate if a given value is greater\nthan a minimum "
},
{
"path": "docs/book/validators/hex.md",
"chars": 702,
"preview": "# Hex Validator\n\n`Zend\\Validator\\Hex` allows you to validate if a given value contains only\nhexadecimal characters. Thes"
},
{
"path": "docs/book/validators/hostname.md",
"chars": 5020,
"preview": "# Hostname Validator\n\n`Zend\\Validator\\Hostname` allows you to validate a hostname against a set of\nknown specifications."
},
{
"path": "docs/book/validators/iban.md",
"chars": 1681,
"preview": "# Iban Validator\n\n`Zend\\Validator\\Iban` validates if a given value could be a IBAN number. IBAN is\nthe abbreviation for "
},
{
"path": "docs/book/validators/identical.md",
"chars": 7179,
"preview": "# Identical Validator\n\n`Zend\\Validator\\Identical` allows you to validate if a given value is identical\nwith a set token."
},
{
"path": "docs/book/validators/in-array.md",
"chars": 5063,
"preview": "# InArray Validator\n\n`Zend\\Validator\\InArray` allows you to validate if a given value is contained\nwithin an array. It i"
},
{
"path": "docs/book/validators/ip.md",
"chars": 2108,
"preview": "# Ip Validator\n\n`Zend\\Validator\\Ip` allows you to validate if a given value is an IP address. It\nsupports the IPv4, IPv6"
},
{
"path": "docs/book/validators/is-countable.md",
"chars": 4627,
"preview": "# IsCountable Validator\n\n- **Since 2.10.0**\n\n`Zend\\Validator\\IsCountable` allows you to validate that a value can be cou"
},
{
"path": "docs/book/validators/isbn.md",
"chars": 1862,
"preview": "# Isbn Validator\n\n`Zend\\Validator\\Isbn` allows you to validate an ISBN-10 or ISBN-13 value.\n\n## Supported options\n\nThe f"
},
{
"path": "docs/book/validators/isinstanceof.md",
"chars": 1141,
"preview": "# IsInstanceOf Validator\n\n`Zend\\Validator\\IsInstanceOf` allows you to validate whether a given object is\nan instance of "
},
{
"path": "docs/book/validators/less-than.md",
"chars": 1240,
"preview": "# LessThan Validator\n\n`Zend\\Validator\\LessThan` allows you to validate if a given value is less than a\nmaximum value.\n\n>"
},
{
"path": "docs/book/validators/not-empty.md",
"chars": 3230,
"preview": "# NotEmpty Validator\n\nThis validator allows you to validate if a given value is not empty. This is\noften useful when wor"
},
{
"path": "docs/book/validators/regex.md",
"chars": 1204,
"preview": "# Regex Validator\n\nThis validator allows you to validate if a given string conforms a defined\nregular expression.\n\n## Su"
},
{
"path": "docs/book/validators/sitemap.md",
"chars": 2562,
"preview": "# Sitemap Validators\n\nThe following validators conform to the\n[Sitemap XML protocol](http://www.sitemaps.org/protocol.ph"
},
{
"path": "docs/book/validators/step.md",
"chars": 1001,
"preview": "# Step Validator\n\n`Zend\\Validator\\Step` allows you to validate if a given value is a valid step\nvalue. This validator re"
},
{
"path": "docs/book/validators/string-length.md",
"chars": 4379,
"preview": "# StringLength Validator\n\nThis validator allows you to validate if a given string is between a defined\nlength.\n\n> ### Su"
},
{
"path": "docs/book/validators/timezone.md",
"chars": 1051,
"preview": "# Timezone Validator\n\n`Zend\\Validator\\Timezone` allows validating if an input string represents a\ntimezone.\n\n## Supporte"
},
{
"path": "docs/book/validators/undisclosed-password.md",
"chars": 3322,
"preview": "# Undisclosed Password Validator\n\n- **Since 2.13.0**\n\n`Zend\\Validator\\UndisclosedPassword` allows you to validate if a g"
},
{
"path": "docs/book/validators/uri.md",
"chars": 969,
"preview": "# Uri Validator\n\n`Zend\\Validator\\Uri` allows you to validate a URI using the `Zend\\Uri\\Uri`\nhandler to parse the URI. Th"
},
{
"path": "docs/book/validators/uuid.md",
"chars": 1294,
"preview": "# UUID Validator\n\n`Zend\\Validator\\Uuid` allows validating [Universally Unique IDentifiers](https://en.wikipedia.org/wiki"
},
{
"path": "docs/book/writing-validators.md",
"chars": 7614,
"preview": "# Writing Validators\n\nzend-validator supplies a set of commonly needed validators, but many\napplications have needs for "
},
{
"path": "mkdocs.yml",
"chars": 3008,
"preview": "docs_dir: docs/book\nsite_dir: docs/html\nnav:\n - Home: index.md\n - Introduction: intro.md\n - Reference:\n "
},
{
"path": "phpcs.xml",
"chars": 228,
"preview": "<?xml version=\"1.0\"?>\n<ruleset name=\"Zend Framework coding standard\">\n <rule ref=\"./vendor/zendframework/zend-coding"
},
{
"path": "phpunit.xml.dist",
"chars": 1242,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:noNam"
},
{
"path": "src/AbstractValidator.php",
"chars": 16662,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/AbstractAdapter.php",
"chars": 7528,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/AdapterInterface.php",
"chars": 1578,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Codabar.php",
"chars": 1843,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code128.php",
"chars": 15570,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code25.php",
"chars": 639,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code25interleaved.php",
"chars": 669,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code39.php",
"chars": 1790,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code39ext.php",
"chars": 595,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code93.php",
"chars": 2410,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Code93ext.php",
"chars": 595,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean12.php",
"chars": 601,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean13.php",
"chars": 601,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean14.php",
"chars": 601,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean18.php",
"chars": 601,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean2.php",
"chars": 598,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean5.php",
"chars": 613,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Ean8.php",
"chars": 960,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Gtin12.php",
"chars": 602,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Gtin13.php",
"chars": 602,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Gtin14.php",
"chars": 602,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Identcode.php",
"chars": 914,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Intelligentmail.php",
"chars": 639,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Issn.php",
"chars": 2205,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Itf14.php",
"chars": 601,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Leitcode.php",
"chars": 609,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Planet.php",
"chars": 611,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Postnet.php",
"chars": 618,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Royalmail.php",
"chars": 2891,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Sscc.php",
"chars": 600,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Upca.php",
"chars": 600,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode/Upce.php",
"chars": 963,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Barcode.php",
"chars": 5396,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Between.php",
"chars": 5812,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Bitwise.php",
"chars": 4322,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Callback.php",
"chars": 3799,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/ConfigProvider.php",
"chars": 969,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "src/CreditCard.php",
"chars": 10632,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Csrf.php",
"chars": 8365,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Date.php",
"chars": 5683,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/DateStep.php",
"chars": 16006,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Db/AbstractDb.php",
"chars": 8449,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Db/NoRecordExists.php",
"chars": 982,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Db/RecordExists.php",
"chars": 977,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Digits.php",
"chars": 1836,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/EmailAddress.php",
"chars": 19000,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/BadMethodCallException.php",
"chars": 442,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/ExceptionInterface.php",
"chars": 380,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/ExtensionNotLoadedException.php",
"chars": 410,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/InvalidArgumentException.php",
"chars": 446,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/InvalidMagicMimeFileException.php",
"chars": 420,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Exception/RuntimeException.php",
"chars": 430,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Explode.php",
"chars": 5387,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Count.php",
"chars": 6939,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Crc32.php",
"chars": 2985,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/ExcludeExtension.php",
"chars": 2493,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/ExcludeMimeType.php",
"chars": 3203,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Exists.php",
"chars": 5095,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Extension.php",
"chars": 6150,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/FileInformationTrait.php",
"chars": 4808,
"preview": "<?php\n/**\n * @see https://github.com/zendframework/zend-validator for the canonical source repository\n * @copyrigh"
},
{
"path": "src/File/FilesSize.php",
"chars": 5808,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Hash.php",
"chars": 4677,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/ImageSize.php",
"chars": 10722,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/IsCompressed.php",
"chars": 2783,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/IsImage.php",
"chars": 3356,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Md5.php",
"chars": 2956,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/MimeType.php",
"chars": 12262,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/NotExists.php",
"chars": 2110,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Sha1.php",
"chars": 2970,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Size.php",
"chars": 10065,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/Upload.php",
"chars": 8975,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/UploadFile.php",
"chars": 5473,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/File/WordCount.php",
"chars": 5850,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/GpsPoint.php",
"chars": 3504,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/GreaterThan.php",
"chars": 3633,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hex.php",
"chars": 1237,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hostname/Biz.php",
"chars": 251232,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hostname/Cn.php",
"chars": 189132,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hostname/Com.php",
"chars": 12951,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hostname/Jp.php",
"chars": 62012,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Hostname.php",
"chars": 60389,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Iban.php",
"chars": 9397,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Identical.php",
"chars": 5074,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/InArray.php",
"chars": 7004,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Ip.php",
"chars": 6232,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/IsCountable.php",
"chars": 5513,
"preview": "<?php\n/**\n * @see https://github.com/zendframework/zend-validator for the canonical source repository\n * @copyrigh"
},
{
"path": "src/IsInstanceOf.php",
"chars": 2453,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Isbn/Isbn10.php",
"chars": 1222,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zend-validator"
},
{
"path": "src/Isbn/Isbn13.php",
"chars": 1257,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zend-validator"
},
{
"path": "src/Isbn.php",
"chars": 5030,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zend-validator"
},
{
"path": "src/LessThan.php",
"chars": 3729,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Module.php",
"chars": 1194,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "src/NotEmpty.php",
"chars": 7913,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Regex.php",
"chars": 3663,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Sitemap/Changefreq.php",
"chars": 1893,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Sitemap/Lastmod.php",
"chars": 2031,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Sitemap/Loc.php",
"chars": 1644,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Sitemap/Priority.php",
"chars": 1648,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/StaticValidator.php",
"chars": 2389,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Step.php",
"chars": 4051,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/StringLength.php",
"chars": 5968,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Timezone.php",
"chars": 4786,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Translator/TranslatorAwareInterface.php",
"chars": 1866,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *;\n * @link http://github.com/zendframework/zf2 for the c"
},
{
"path": "src/Translator/TranslatorInterface.php",
"chars": 597,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/UndisclosedPassword.php",
"chars": 4739,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "src/Uri.php",
"chars": 5064,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/Uuid.php",
"chars": 1679,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "src/ValidatorChain.php",
"chars": 8990,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/ValidatorInterface.php",
"chars": 1285,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/ValidatorPluginManager.php",
"chars": 25736,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/ValidatorPluginManagerAwareInterface.php",
"chars": 732,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "src/ValidatorPluginManagerFactory.php",
"chars": 2292,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "src/ValidatorProviderInterface.php",
"chars": 973,
"preview": "<?php\n/**\n * @link http://github.com/zendframework/zend-validator for the canonical source repository\n * @copyright"
},
{
"path": "test/AbstractTest.php",
"chars": 11658,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/BarcodeTest.php",
"chars": 17071,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/BetweenTest.php",
"chars": 9971,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/BitwiseTest.php",
"chars": 8125,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/CallbackTest.php",
"chars": 4365,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/CreditCardTest.php",
"chars": 10384,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/CsrfTest.php",
"chars": 9268,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/DateStepTest.php",
"chars": 9397,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/DateTest.php",
"chars": 7367,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/Db/AbstractDbTest.php",
"chars": 3197,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/Db/NoRecordExistsTest.php",
"chars": 7304,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/Db/RecordExistsTest.php",
"chars": 11535,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/Db/TestAsset/ConcreteDbValidator.php",
"chars": 834,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/Db/TestAsset/TrustingSql92Platform.php",
"chars": 574,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
},
{
"path": "test/DigitsTest.php",
"chars": 2800,
"preview": "<?php\n/**\n * Zend Framework (http://framework.zend.com/)\n *\n * @link http://github.com/zendframework/zf2 for the ca"
}
]
// ... and 73 more files (download for full content)
About this extraction
This page contains the full source code of the zendframework/zend-validator GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 273 files (2.9 MB), approximately 778.2k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.