From 6b49370c2690b2a1933d04d69b9413577fa85a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Sun, 15 Mar 2020 10:59:12 +0100 Subject: [PATCH 1/5] Adds new documentation for IsInt validator --- docs/book/validators/is-int.md | 111 +++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 112 insertions(+) create mode 100755 docs/book/validators/is-int.md diff --git a/docs/book/validators/is-int.md b/docs/book/validators/is-int.md new file mode 100755 index 00000000..db0502bb --- /dev/null +++ b/docs/book/validators/is-int.md @@ -0,0 +1,111 @@ +# IsInt + +`Laminas\I18n\Validator\IsInt` validates if a given value **is an integer**, using +the locale provided. + +Integer values are often written differently based on country or region. For +example, using English, you may write `1234` or `1,234`; both are integer +values, but the grouping is optional. In German, you'd write `1.234`, and in +French, `1 234`. + +`Laminas\I18n\Validator\IsInt` will use a provided locale when evaluating the +validity of an integer value. In such cases, it doesn't simply strip the +separator, but instead validates that the correct separator as defined by the +locale is used. + +## Basic Usage + +```php +$validator = new Laminas\I18n\Validator\IsInt(); + +$validator->isValid(1234); // returns true +$validator->isValid(1234.5); // returns false +$validator->isValid('1,234'); // returns true +``` + +By default, if no locale is provided, `IsInt` will use the system locale +provide by PHP's `Locale` class and the `getDefault()` method. + +(The above example assumes that the environment locale is set to `en`.) + +Using a notation not specific to the locale results in a `false` evaulation. + +## Using Locale + +```php fct_label="Constructor Usage" +$validator = new Laminas\I18n\Validator\IsInt(['locale' => 'en_US']); + +$validator->isValid(1234); // true +``` + +```php fct_label="Setter Usage" +$validator = new Laminas\I18n\Validator\IsInt(); +$validator->setLocale('en_US'); + +$validator->isValid(1234); // true +``` + +```php fct_label="Locale Class Usage" +Locale::setDefault('en_US'); + +$validator = new Laminas\I18n\Validator\IsInt(); + +$validator->isValid(1234); // true +``` + +### Get Current Value + +To get the current value of this option, use the `getLocale()` method. + +```php +$validator = new Laminas\I18n\Validator\IsInt(['locale' => 'en_US']); + +echo $validator->getLocale(); // 'en_US' +``` + +### Default Value + +By default, if no locale is provided, `IsInt` will use the system locale +provide by PHP's `Locale::getDefault()`. + +## Strict Validation + +By default, the value's data type is not enforced. + +```php fct_label="Default (Without Strict)" +$validator = new Laminas\I18n\Validator\IsInt(); + +$validator->isValid(1234); // true +$validator->isValid('1234'); // true +``` + +To enforced a strict validation set the `strict` option to `true`. + +```php fct_label="Constructor Usage" +$validator = new Laminas\I18n\Validator\IsInt(['strict' => true]); + +$validator->isValid(1234); // true +$validator->isValid('1234'); // false +``` + +```php fct_label="Setter Usage" +$validator = new Laminas\I18n\Validator\IsInt(); +$validator->setStrict(true) + +$validator->isValid(1234); // true +$validator->isValid('1234'); // false +``` + +### Get Current Value + +To get the current value of this option, use the `getStrict()` method. + +```php +$validator = new Laminas\I18n\Validator\IsInt(['strict' => true]); + +echo $validator->getStrict(); // true +``` + +### Default Value + +The default value of this option is `false`. diff --git a/mkdocs.yml b/mkdocs.yml index 70536a1a..3999ec38 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,6 +10,7 @@ nav: - Validators: - 'Standard Validators': validators.md - DateTime: validators/date-time.md + - IsInt: validators/is-int.md - PhoneNumber: validators/phone-number.md site_name: laminas-i18n site_description: 'Provide translations for your application, and filter and validate internationalized values.' From f66639902ccb83932e667123bc8ad328924e3be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Sun, 15 Mar 2020 11:10:00 +0100 Subject: [PATCH 2/5] Removes old documentation for IsInt validator --- docs/book/validators.md | 81 ----------------------------------------- 1 file changed, 81 deletions(-) diff --git a/docs/book/validators.md b/docs/book/validators.md index eecdb414..44136f5f 100644 --- a/docs/book/validators.md +++ b/docs/book/validators.md @@ -181,87 +181,6 @@ instead. Users pulling their `Float` validator instance from the validator plugin manager receive an `IsFloat` instance instead starting in 2.4.0. -## IsInt - -`Laminas\I18n\Validator\IsInt` validates if a given value is an integer, using the -locale provided. - -### Supported Options - -The following options are supported for `Laminas\I18n\Validator\IsInt`: - -- `locale`: Sets the locale to use when validating localized integers. -- `strict`: Sets whether or not the value's data type should be checked. - -### Basic integer validation - -When no locale is provided to the validator, it uses the system locale: - -```php -$validator = new Laminas\I18n\Validator\IsInt(); - -$validator->isValid(1234); // returns true -$validator->isValid(1234.5); // returns false -$validator->isValid('1,234'); // returns true -``` - -(The above example assumes that the environment locale is set to `en`.) - -### Strict validation - -By default, the value's data type is not enforced. - -```php -$validator = new Laminas\I18n\Validator\IsInt(); - -$validator->isValid(1234); // returns true -$validator->isValid('1234'); // returns true -``` - -```php -$validator = new Laminas\I18n\Validator\IsInt(); -$validator->setStrict(true); - -$validator->isValid(1234); // returns true -$validator->isValid('1234'); // returns false -``` - -### Localized integer validation - -Integer values are often written differently based on country or region. For -example, using English, you may write "1234" or "1,234"; both are integer -values, but the grouping is optional. In German, you'd write "1.234", and in -French, "1 234". - -`Laminas\I18n\Validator\IsInt` will use a provided locale when evaluating the -validity of an integer value. In such cases, it doesn't simply strip the -validator, but instead validates that the correct separator as defined by the -locale is used. - -```php -$validator = new Laminas\I18n\Validator\IsInt(['locale' => 'de']); - -$validator->isValid(1234); // returns true -$validator->isValid("1,234"); // returns false -$validator->isValid("1.234"); // returns true -``` - -By using a locale, your input is validated based on the locale provided. Using a -notation not specific to the locale results in a `false` evaulation. - -The default validation locale can also be set after instantiation using -`setLocale()`, and retrieved using `getLocale()`. - -### Migration from 2.0-2.3 to 2.4+ - -Version 2.4 adds support for PHP 7. In PHP 7, `int` is a reserved keyword, which -required renaming the `Int` validator. If you were using the `Int` validator -directly previously, you will now receive an `E_USER_DEPRECATED` notice on -instantiation. Please update your code to refer to the `IsInt` class instead. - -Users pulling their `Int` validator instance from the validator plugin manager -receive an `IsInt` instance instead starting in 2.4.0. - ## PostCode `Laminas\I18n\Validator\PostCode` allows you to determine if a given value is a From a2a81bcf9e03cdc625e89c24424a4670b5a8e3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Sun, 15 Mar 2020 11:20:42 +0100 Subject: [PATCH 3/5] Fixes spelling mistake in section of basic usage --- docs/book/validators/is-int.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/validators/is-int.md b/docs/book/validators/is-int.md index db0502bb..1f96560c 100755 --- a/docs/book/validators/is-int.md +++ b/docs/book/validators/is-int.md @@ -24,7 +24,7 @@ $validator->isValid('1,234'); // returns true ``` By default, if no locale is provided, `IsInt` will use the system locale -provide by PHP's `Locale` class and the `getDefault()` method. +provided by PHP's `Locale` class and the `getDefault()` method. (The above example assumes that the environment locale is set to `en`.) From 6edaf253e7ca8e7bf853bce0703d469647b16f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Sun, 15 Mar 2020 11:21:48 +0100 Subject: [PATCH 4/5] Fixes wording in introduction section --- docs/book/validators/is-int.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/book/validators/is-int.md b/docs/book/validators/is-int.md index 1f96560c..848d065f 100755 --- a/docs/book/validators/is-int.md +++ b/docs/book/validators/is-int.md @@ -10,8 +10,8 @@ French, `1 234`. `Laminas\I18n\Validator\IsInt` will use a provided locale when evaluating the validity of an integer value. In such cases, it doesn't simply strip the -separator, but instead validates that the correct separator as defined by the -locale is used. +separator, but instead validates that the correct separator as defined by used +locale. ## Basic Usage From e049ac1148ceb51e5b9235eb58938005ee84c82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Sun, 15 Mar 2020 10:25:11 +0000 Subject: [PATCH 5/5] Fixes typos in documentation --- docs/book/validators/is-int.md | 2 +- docs/book/validators/phone-number.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/book/validators/is-int.md b/docs/book/validators/is-int.md index 848d065f..6cd6eada 100755 --- a/docs/book/validators/is-int.md +++ b/docs/book/validators/is-int.md @@ -66,7 +66,7 @@ echo $validator->getLocale(); // 'en_US' ### Default Value By default, if no locale is provided, `IsInt` will use the system locale -provide by PHP's `Locale::getDefault()`. +provided by PHP's `Locale::getDefault()`. ## Strict Validation diff --git a/docs/book/validators/phone-number.md b/docs/book/validators/phone-number.md index 8a4fcc80..11d4d800 100755 --- a/docs/book/validators/phone-number.md +++ b/docs/book/validators/phone-number.md @@ -12,7 +12,7 @@ var_dump($validator->isValid('+4930123456')); // true ``` By default, if no country code is provided, `PhoneNumber` will use the system -locale provide by PHP's `Locale::getDefault()` and `Locale::getRegion()` to +locale provided by PHP's `Locale::getDefault()` and `Locale::getRegion()` to extract the country code. (The above example assumes that the environment locale is set to `de_DE`.) @@ -55,7 +55,7 @@ echo $validator->getCountry(); // 'US' ### Default Value By default, if no country is provided, `PhoneNumber` will use the system locale -provide by PHP's `Locale::getDefault()` and `Locale::getRegion()` to extract +provided by PHP's `Locale::getDefault()` and `Locale::getRegion()` to extract the region code. ## Using Allowed Phone Number Patterns