├── .github ├── dependabot.yml └── workflows │ ├── dependabot-auto-merge.yml │ ├── fix-php-code-style-issues.yml │ ├── phpstan.yml │ ├── run-tests.yml │ └── update-changelog.yml ├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── lang ├── de │ └── validation.php └── en │ └── validation.php ├── phpstan-baseline.neon ├── phpstan.neon.dist ├── phpunit.xml ├── src ├── IsoCodesValidationServiceProvider.php └── IsoCodesValidator.php └── tests ├── IsoCodesValidatorTest.php ├── TestCase.php └── fixtures ├── invalid.php ├── invalid_wit_dot_notation.php ├── invalid_with_references.php ├── valid.php ├── valid_wit_dot_notation.php └── valid_with_references.php /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Please see the documentation for all configuration options: 2 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 3 | 4 | version: 2 5 | updates: 6 | 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | labels: 12 | - "dependencies" 13 | 14 | - package-ecosystem: composer 15 | directory: "/" 16 | schedule: 17 | interval: daily 18 | time: "04:00" 19 | open-pull-requests-limit: 10 20 | labels: 21 | - "dependencies" 22 | -------------------------------------------------------------------------------- /.github/workflows/dependabot-auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto merge 2 | on: pull_request_target 3 | 4 | permissions: 5 | pull-requests: write 6 | contents: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.actor == 'dependabot[bot]' }} 12 | steps: 13 | 14 | - name: Dependabot metadata 15 | id: metadata 16 | uses: dependabot/fetch-metadata@v2.4.0 17 | with: 18 | github-token: "${{ secrets.GITHUB_TOKEN }}" 19 | 20 | - name: Auto-merge Dependabot PRs for semver-minor updates 21 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} 22 | run: gh pr merge --auto --merge "$PR_URL" 23 | env: 24 | PR_URL: ${{github.event.pull_request.html_url}} 25 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 26 | 27 | - name: Auto-merge Dependabot PRs for semver-patch updates 28 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} 29 | run: gh pr merge --auto --merge "$PR_URL" 30 | env: 31 | PR_URL: ${{github.event.pull_request.html_url}} 32 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 33 | -------------------------------------------------------------------------------- /.github/workflows/fix-php-code-style-issues.yml: -------------------------------------------------------------------------------- 1 | name: Fix PHP code style issues 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.php' 7 | 8 | permissions: 9 | contents: write 10 | 11 | jobs: 12 | php-code-styling: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v4 18 | with: 19 | ref: ${{ github.head_ref }} 20 | 21 | - name: Fix PHP code style issues 22 | uses: aglipanci/laravel-pint-action@2.5 23 | 24 | - name: Commit changes 25 | uses: stefanzweifel/git-auto-commit-action@v5 26 | with: 27 | commit_message: Fix styling 28 | -------------------------------------------------------------------------------- /.github/workflows/phpstan.yml: -------------------------------------------------------------------------------- 1 | name: PHPStan 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.php' 7 | - 'phpstan.neon.dist' 8 | - '.github/workflows/phpstan.yml' 9 | 10 | jobs: 11 | phpstan: 12 | name: phpstan 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Setup PHP 18 | uses: shivammathur/setup-php@v2 19 | with: 20 | php-version: '7.4' 21 | coverage: none 22 | 23 | - name: Install composer dependencies 24 | uses: ramsey/composer-install@v3 25 | 26 | - name: Run PHPStan 27 | run: ./vendor/bin/phpstan --error-format=github 28 | -------------------------------------------------------------------------------- /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | fail-fast: true 14 | matrix: 15 | os: [ ubuntu-latest ] 16 | php: [ 7.4, 7.3 ] 17 | laravel: [ 7.*, 6.*, 5.8.* ] 18 | stability: [ prefer-stable ] 19 | include: 20 | - laravel: 7.* 21 | testbench: 5.* 22 | carbon: 2.* 23 | - laravel: 6.* 24 | testbench: 4.* 25 | carbon: 2.* 26 | - laravel: 5.8.* 27 | testbench: 3.* 28 | carbon: 2.* 29 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} 30 | steps: 31 | - name: Checkout code 32 | uses: actions/checkout@v4 33 | 34 | - name: Setup PHP 35 | uses: shivammathur/setup-php@v2 36 | with: 37 | php-version: ${{ matrix.php }} 38 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo 39 | coverage: xdebug 40 | 41 | - name: Setup problem matchers 42 | run: | 43 | echo "::add-matcher::${{ runner.tool_cache }}/php.json" 44 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" 45 | 46 | - name: Install dependencies 47 | run: | 48 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update 49 | composer update --${{ matrix.stability }} --prefer-dist --no-interaction 50 | 51 | - name: List Installed Dependencies 52 | run: composer show -D 53 | 54 | - name: Execute tests and coverage 55 | run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml 56 | 57 | - name: Upload coverage results to Coveralls 58 | uses: coverallsapp/github-action@v2 59 | env: 60 | github-token: ${{ secrets.COVERALLS_REPO_TOKEN }} 61 | # Note: This is the only path that the Coveralls GitHub Action supports. 62 | # So we cannot use something like .Build/coverage/clover.xml here. 63 | file: build/logs/clover.xml -------------------------------------------------------------------------------- /.github/workflows/update-changelog.yml: -------------------------------------------------------------------------------- 1 | name: "Update Changelog" 2 | 3 | on: 4 | release: 5 | types: [released] 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | update: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout code 16 | uses: actions/checkout@v4 17 | with: 18 | ref: master 19 | 20 | - name: Update Changelog 21 | uses: stefanzweifel/changelog-updater-action@v1 22 | with: 23 | latest-version: ${{ github.event.release.name }} 24 | release-notes: ${{ github.event.release.body }} 25 | 26 | - name: Commit updated CHANGELOG 27 | uses: stefanzweifel/git-auto-commit-action@v5 28 | with: 29 | branch: master 30 | commit_message: Update CHANGELOG 31 | file_pattern: CHANGELOG.md 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Composer Related 2 | composer.lock 3 | /vendor 4 | 5 | # Caches 6 | .phpunit.cache 7 | .phpunit.result.cache 8 | /build 9 | 10 | # IDE Helper 11 | _ide_helper.php 12 | _ide_helper_models.php 13 | .phpstorm.meta.php 14 | 15 | # Editors 16 | /.idea 17 | /.fleet 18 | /.vscode -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | build: 2 | nodes: 3 | analysis: 4 | tests: 5 | override: 6 | - php-scrutinizer-run 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.1 5 | - 7.2 6 | - 7.3 7 | 8 | matrix: 9 | include: 10 | - php: 7.1 11 | env: dependencies=highest 12 | - php: 7.2 13 | env: dependencies=highest 14 | - php: 7.3 15 | env: dependencies=highest 16 | 17 | before_script: 18 | - composer self-update -q 19 | - if [ -n "$GITHUB_TOKEN" ]; then composer config github-oauth.github.com ${GITHUB_TOKEN}; fi; 20 | - if [ -z "$dependencies" ]; then composer install; fi; 21 | - if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest -n; fi; 22 | - if [ "$dependencies" = "highest" ]; then composer update -n; fi; 23 | 24 | script: 25 | - mkdir -p build/logs 26 | - vendor/bin/phpunit --coverage-clover build/logs/clover.xml 27 | 28 | branches: 29 | only: 30 | - master 31 | - stable 32 | 33 | after_success: 34 | - travis_retry php vendor/bin/coveralls -v 35 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes for the Laravel 5 IsoCodes Validation will be documented in this file 4 | 5 | ## 3.0.0 6 | - Fix issue #8: missing function replaceVat 7 | - Laravel 5.8 8 | - Upgrade to phpunit 7.5.x 9 | - Add php 7.3 to travis-ci 10 | - Add support for arrays with dot notations to all validation methods 11 | ```php 12 | $payload = [ 13 | 'data' => [ 14 | [ 15 | 'country' => 'DE', 16 | 'zipcode' => 63741 17 | ], 18 | [ 19 | 'country' => 'AT', 20 | 'zipcode' => 1180 21 | ] 22 | ] 23 | ]; 24 | 25 | $validator = Validator::make($payload, [ 26 | 'data.*.zipcode' => 'zipcode:data.*.country' 27 | ]); 28 | ``` 29 | - Refactor: fix scrutinizer issues 30 | - Refactor: add (external) fixtures to tests to reduce number of lines 31 | - Refactor: remove unused function params 32 | 33 | ## 2.0.0 34 | - Laravel 5.5 compatibility with Auto-Discovery 35 | - Require php 7.0+ 36 | - Upgrade to phpunit 6.5.x 37 | - Add php 7.2 to travis-ci 38 | 39 | ## 1.2.0 40 | Added support for following validation rules 41 | - BSN 42 | - GDTI 43 | - GLN 44 | - GRAI 45 | - GSRN 46 | - ISMN 47 | - ISWC 48 | - UDI 49 | - UPCA 50 | 51 | ## 1.1.0 52 | - Laravel 5.4 compatibility 53 | 54 | ## 1.0.0 55 | - Stable first release 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # GNU General Public License v3.0 only 2 | 3 | Copyright (C) 2016 Peter Haak 2016 4 | 5 | > This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version. 6 | 7 | >This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 8 | 9 | > You should have received a copy of the GNU General Public License along with this program. If not, see . 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel 5 IsoCodes Validation 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/pixelpeter/laravel5-isocodes-validation.svg?style=flat-square)](https://packagist.org/packages/pixelpeter/laravel5-isocodes-validation) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/pixelpeter/laravel5-isocodes-validation.svg?style=flat-square)](https://packagist.org/packages/pixelpeter/laravel5-isocodes-validation) 5 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 6 | [![Coverage Status](https://coveralls.io/repos/github/pixelpeter/laravel5-isocodes-validation/badge.svg?branch=master)](https://coveralls.io/github/pixelpeter/laravel5-isocodes-validation?branch=master) 7 | [![Tests](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/run-tests.yml) 8 | [![Fix PHP code style issues](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/fix-php-code-style-issues.yml) 9 | [![PHPStan](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/phpstan.yml/badge.svg)](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/phpstan.yml) 10 | [![dependabot-auto-merge](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/dependabot-auto-merge.yml/badge.svg)](https://github.com/pixelpeter/laravel5-isocodes-validation/actions/workflows/dependabot-auto-merge.yml) 11 | 12 | A simple Laravel 5 wrapper for the [IsoCodes Validation library](https://github.com/ronanguilloux/IsoCodes) from ronanguilloux. 13 | 14 | For a **Laravel 8** compatible version please use https://github.com/pixelpeter/laravel-isocodes-validation 15 | 16 | ## Installation 17 | 18 | ### Step 1: Install Through Composer 19 | ``` bash 20 | composer require pixelpeter/laravel5-isocodes-validation 21 | ``` 22 | 23 | ### Step 2: Add the Service Provider 24 | *(not needed starting with v2.x because of auto discovery)* 25 | 26 | Add the service provider in `app/config/app.php` 27 | ```php 28 | 'provider' => [ 29 | ... 30 | Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider::class, 31 | ... 32 | ]; 33 | ``` 34 | 35 | ## Usage 36 | 37 | ### Simple examples 38 | 39 | ```php 40 | // Checking out your e-commerce shopping cart? 41 | $payload = [ 42 | 'creditcard' => '12345679123456' 43 | ]; 44 | $rules = [ 45 | 'creditcard' => 'creditcard' 46 | ]; 47 | 48 | $validator = Validator::make($payload, $rules); 49 | ``` 50 | 51 | ### Examples with reference parameter 52 | Some rules need a reference to be validated against (e.g. `country` for `zipcode`). 53 | 54 | Just pass the name of the field holding the reference to the rule. 55 | 56 | ```php 57 | // Sending letters to the Labrador Islands ? 58 | $payload = [ 59 | 'zipcode' => 'A0A 1A0', 60 | 'country' => 'CA' 61 | ]; 62 | $rules = [ 63 | 'zipcode' => 'zipcode:country' 64 | ]; 65 | 66 | $validator = Validator::make($payload, $rules); 67 | 68 | // Publishing books? 69 | $payload = [ 70 | 'isbn' => '2-2110-4199-X', 71 | 'isbntype' => 13 72 | ]; 73 | $rules = [ 74 | 'zipcode' => 'isbn:isbntype' 75 | ]; 76 | 77 | $validator = Validator::make($payload, $rules); 78 | ``` 79 | 80 | ### Example with arrays and dot notation 81 | *(added in v3.x)* 82 | 83 | As suggested by @otr-tomek I've added support for all validation methods using arrays in dot notation as an input. 84 | 85 | ```php 86 | $payload = [ 87 | 'data' => [ 88 | [ 89 | 'country' => 'DE', 90 | 'zipcode' => 63741 91 | ], 92 | [ 93 | 'country' => 'AT', 94 | 'zipcode' => 1180 95 | ] 96 | ] 97 | ]; 98 | 99 | $validator = Validator::make($payload, [ 100 | 'data.*.zipcode' => 'zipcode:data.*.country' 101 | ]); 102 | ``` 103 | 104 | ### Validation error messages 105 | Error messages can contain the name and value of the field and the value of the reference 106 | ```php 107 | $payload = [ 108 | 'phonenumber' => 'invalid', 109 | 'country' => 'GB' 110 | ]; 111 | $rules = [ 112 | 'phonenumber' => 'phonenumber:country' 113 | ]; 114 | 115 | $validator = Validator::make($payload, $rules); 116 | 117 | print $validator->errors()->first(); // The value "invalid" of phonenumber is not valid for "GB". 118 | ``` 119 | 120 | ### More Examples 121 | Refer to [IsoCodes Validation library](https://github.com/ronanguilloux/IsoCodes) for more examples and documentation. 122 | 123 | ## Testing 124 | Run the tests with: 125 | ```bash 126 | vendor/bin/phpunit 127 | ``` 128 | 129 | ## License 130 | 131 | GNU General Public License v3.0 only. Please see [License File](LICENSE.md) for more information. 132 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pixelpeter/laravel5-isocodes-validation", 3 | "description": "Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux", 4 | "keywords": [ 5 | "laravel", 6 | "iso", 7 | "isocode", 8 | "validation" 9 | ], 10 | "homepage": "https://github.com/pixelpeter/laravel5-isocodes-validation", 11 | "license": "GPL-3.0-or-later", 12 | "authors": [ 13 | { 14 | "name": "Peter Haak", 15 | "email": "info@pixelpeter.de", 16 | "homepage": "https://pixelpeter.de/", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php" : "^7.3|^7.4", 22 | "ronanguilloux/isocodes": "^2.2.3" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Pixelpeter\\IsoCodesValidation\\": "src" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Pixelpeter\\IsoCodesValidation\\Test\\": "tests" 32 | }, 33 | "classmap": [ 34 | "tests/TestCase.php" 35 | ] 36 | }, 37 | "require-dev": { 38 | "phpunit/phpunit": "^8.3", 39 | "mockery/mockery": "^1.2", 40 | "laravel/laravel": "5.8.*|6.*|7.*", 41 | "phpstan/phpstan": "^1.12", 42 | "phpstan/extension-installer": "^1.4" 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "Pixelpeter\\IsoCodesValidation\\IsoCodesValidationServiceProvider" 48 | ] 49 | } 50 | }, 51 | "config": { 52 | "allow-plugins": { 53 | "phpstan/extension-installer": true 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lang/de/validation.php: -------------------------------------------------------------------------------- 1 | 'Der Wert ":value" von :attribute ist kein gültiger BBAN Code.', 5 | 'bsn' => 'Der Wert ":value" von :attribute ist kein gültiger BSN.', 6 | 'cif' => 'Der Wert ":value" von :attribute ist kein gültiger CIF Code.', 7 | 'creditcard' => 'Der Wert ":value" von :attribute ist keine gültige Kreditkartennummer.', 8 | 'ean8' => 'Der Wert ":value" von :attribute ist kein gültiger EAN8 Code.', 9 | 'ean13' => 'Der Wert ":value" von :attribute ist kein gültiger EAN13 Code.', 10 | 'gdti' => 'Der Wert ":value" von :attribute ist kein gültiger Global Document Type Identifier (GDTI).', 11 | 'gln' => 'Der Wert ":value" von :attribute ist keine gültige Global Location Number (GLN).', 12 | 'grai' => 'Der Wert ":value" von :attribute ist kein gültiger Global Returnable Asset Identifier.', 13 | 'gsrn' => 'Der Wert ":value" von :attribute ist keine gültige Global Service Relation Number (GS1).', 14 | 'gtin8' => 'Der Wert ":value" von :attribute ist kein gültiger GTIN-8 Code.', 15 | 'gtin12' => 'Der Wert ":value" von :attribute ist kein gültiger GTIN-12 Code.', 16 | 'gtin13' => 'Der Wert ":value" von :attribute ist kein gültiger GTIN-13 Code.', 17 | 'gtin14' => 'Der Wert ":value" von :attribute ist kein gültiger GTIN-14 Code.', 18 | 'iban' => 'Der Wert ":value" von :attribute ist keine gültige IBAN.', 19 | 'insee' => 'Der Wert ":value" von :attribute ist kein gültiger INSEE Code.', 20 | 'ipaddress' => 'Der Wert ":value" von :attribute ist keine gültige IP Adresse.', 21 | 'isbn' => 'Der Wert ":value" von :attribute ist keine gültige ISBN.', 22 | 'isin' => 'Der Wert ":value" von :attribute ist kein gültiger ISIN.', 23 | 'ismn' => 'Der Wert ":value" von :attribute ist keine gültige International Standard Music Number or ISMN (ISO 10957)', 24 | 'iswc' => 'Der Wert ":value" von :attribute ist kein gültiger International Standard Musical Work Code (ISWC)', 25 | 'mac' => 'Der Wert ":value" von :attribute ist keine gültige MAC Adresse.', 26 | 'nif' => 'Der Wert ":value" von :attribute ist kein gültiger NIF.', 27 | 'organisme_type12_norme_b2' => 'Der Wert ":value" von :attribute ist kein gültiger Organisme Type12 Norme B2.', 28 | 'phonenumber' => 'Der Wert ":value" von :attribute ist ungültig für ":country".', 29 | 'sedol' => 'Der Wert ":value" von :attribute ist kein gültiger SEDOL.', 30 | 'siren' => 'Der Wert ":value" von :attribute ist kein gültiger SIREN Code.', 31 | 'siret' => 'Der Wert ":value" von :attribute ist kein gültiger SIRET Code.', 32 | 'sscc' => 'Der Wert ":value" von :attribute ist kein gültiger SSCC.', 33 | 'ssn' => 'Der Wert ":value" von :attribute ist keine gültige SSN.', 34 | 'structured_communication' => 'Der Wert ":value" von :attribute ist kein gültiger Structured Communication Code.', 35 | 'swift_bic' => 'Der Wert ":value" von :attribute ist kein gültiger SWIFT/BIC.', 36 | 'udi' => 'Der Wert ":value" von :attribute ist kein gültiger UDI.', 37 | 'uknin' => 'Der Wert ":value" von :attribute ist keine gültige UK National Insurance Number.', 38 | 'upca' => 'Der Wert ":value" von :attribute ist kein gültiger UPCA.', 39 | 'vat' => 'Der Wert ":value" von :attribute ist keine gültige VAT.', 40 | 'zipcode' => 'Der Wert ":value" von :attribute ist ungültig für ":country".', 41 | ]; 42 | -------------------------------------------------------------------------------- /lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The value ":value" of :attribute is not a valid BBAN code.', 5 | 'bsn' => 'The value ":value" of :attribute is not a valid BSN.', 6 | 'cif' => 'The value ":value" of :attribute is not a valid CIF code.', 7 | 'creditcard' => 'The value ":value" of :attribute is not a valid credit card number.', 8 | 'ean8' => 'The value ":value" of :attribute is not a valid EAN8 code.', 9 | 'ean13' => 'The value ":value" of :attribute is not a valid EAN13 code.', 10 | 'gdti' => 'The value ":value" of :attribute is not a valid Global Document Type Identifier (GDTI).', 11 | 'gln' => 'The value ":value" of :attribute is not a valid Global Location Number (GLN).', 12 | 'grai' => 'The value ":value" of :attribute is not a valid Global Returnable Asset Identifier.', 13 | 'gsrn' => 'The value ":value" of :attribute is not a valid Global Service Relation Number (GS1).', 14 | 'gtin8' => 'The value ":value" of :attribute is not a valid GTIN-8 code.', 15 | 'gtin12' => 'The value ":value" of :attribute is not a valid GTIN-12 code.', 16 | 'gtin13' => 'The value ":value" of :attribute is not a valid GTIN-13 code.', 17 | 'gtin14' => 'The value ":value" of :attribute is not a valid GTIN-14 code.', 18 | 'iban' => 'The value ":value" of :attribute is not a valid IBAN.', 19 | 'insee' => 'The value ":value" of :attribute is not a valid INSEE code.', 20 | 'ipaddress' => 'The value ":value" of :attribute is not a valid ip address.', 21 | 'isbn' => 'The value ":value" of :attribute is not a valid ISBN.', 22 | 'isin' => 'The value ":value" of :attribute is not a valid ISIN.', 23 | 'ismn' => 'The value ":value" of :attribute is not a valid International Standard Music Number or ISMN (ISO 10957)', 24 | 'iswc' => 'The value ":value" of :attribute is not a valid International Standard Musical Work Code (ISWC)', 25 | 'mac' => 'The value ":value" of :attribute is not a valid MAC address.', 26 | 'nif' => 'The value ":value" of :attribute is not a valid NIF.', 27 | 'organisme_type12_norme_b2' => 'The value ":value" of :attribute is not a valid Organisme Type12 Norme B2.', 28 | 'phonenumber' => 'The value ":value" of :attribute is not valid for ":country".', 29 | 'sedol' => 'The value ":value" of :attribute is not a valid SEDOL.', 30 | 'siren' => 'The value ":value" of :attribute is not a valid SIREN code.', 31 | 'siret' => 'The value ":value" of :attribute is not a valid SIRET code.', 32 | 'sscc' => 'The value ":value" of :attribute is not a valid SSCC.', 33 | 'ssn' => 'The value ":value" of :attribute is not a valid SSN.', 34 | 'structured_communication' => 'The value ":value" of :attribute is not a valid structured communication code.', 35 | 'swift_bic' => 'The value ":value" of :attribute is not a valid SWIFT/BIC.', 36 | 'udi' => 'The value ":value" of :attribute is not a valid UDI.', 37 | 'uknin' => 'The value ":value" of :attribute is not a valid UK National Insurance Number.', 38 | 'upca' => 'The value ":value" of :attribute is not a valid UPCA.', 39 | 'vat' => 'The value ":value" of :attribute is not a valid VAT.', 40 | 'zipcode' => 'The value ":value" of :attribute is not valid for ":country".', 41 | ]; 42 | -------------------------------------------------------------------------------- /phpstan-baseline.neon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pixelpeter/laravel5-isocodes-validation/274c7731c53df9fc9c607c2e9074ec5df40ee833/phpstan-baseline.neon -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | 4 | parameters: 5 | level: 5 6 | paths: 7 | - src 8 | tmpDir: build/phpstan 9 | 10 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/ 14 | 15 | 16 | 17 | 18 | src/ 19 | 20 | ./src/WoocommerceServiceProvider.php 21 | ./src/Facades/Woocommerce.php 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/IsoCodesValidationServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadTranslationsFrom( 19 | __DIR__.'/../lang', 20 | 'validation' 21 | ); 22 | 23 | // registering intervention validator extension 24 | $this->app['validator']->resolver(function ($translator, $data, $rules, $messages, $customAttributes) { 25 | // set the validation error messages 26 | foreach (get_class_methods('Pixelpeter\IsoCodesValidation\IsoCodesValidator') as $method) { 27 | $key = $this->getTranslationKeyFromMethodName($method); 28 | 29 | $messages[$key] = $this->getErrorMessage($translator, $messages, $key); 30 | } 31 | 32 | return new IsoCodesValidator($translator, $data, $rules, $messages, $customAttributes); 33 | }); 34 | } 35 | 36 | /** 37 | * Return translation key for correspondent method name 38 | * 39 | * @param string $name 40 | * @return string 41 | */ 42 | private function getTranslationKeyFromMethodName($name) 43 | { 44 | return Str::snake(substr($name, 8)); 45 | } 46 | 47 | /** 48 | * Return the matching error message for the key 49 | * 50 | * @param string $key 51 | * @return string 52 | */ 53 | private function getErrorMessage($translator, $messages, $key) 54 | { 55 | // return error messages passed directly to the validator 56 | if (isset($messages[$key])) { 57 | return $messages[$key]; 58 | } 59 | 60 | // return error message from validation translation file 61 | if ($translator->has("validation.{$key}")) { 62 | return $translator->get("validation.{$key}"); 63 | } 64 | 65 | // return packages default message 66 | return $translator->get("validation::validation.{$key}"); 67 | } 68 | 69 | /** 70 | * Register the application services. 71 | * 72 | * @return void 73 | */ 74 | public function register() 75 | { 76 | // 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/IsoCodesValidator.php: -------------------------------------------------------------------------------- 1 | runIsoCodesValidator(\IsoCodes\Bban::class, $value); 19 | } 20 | 21 | /** 22 | * Validate a BSN (Dutch citizen service number) 23 | * 24 | * @return mixed 25 | */ 26 | public function validateBsn(/** @scrutinizer ignore-unused */ $attribute, $value) 27 | { 28 | return $this->runIsoCodesValidator(\IsoCodes\Bsn::class, $value); 29 | } 30 | 31 | /** 32 | * Validate a CIF code 33 | * 34 | * @return mixed 35 | */ 36 | public function validateCif(/** @scrutinizer ignore-unused */ $attribute, $value) 37 | { 38 | return $this->runIsoCodesValidator(\IsoCodes\Cif::class, $value); 39 | } 40 | 41 | /** 42 | * Validate a credit card number 43 | * 44 | * @return mixed 45 | */ 46 | public function validateCreditcard(/** @scrutinizer ignore-unused */ $attribute, $value) 47 | { 48 | return $this->runIsoCodesValidator(\IsoCodes\CreditCard::class, $value); 49 | } 50 | 51 | /** 52 | * Validate a EAN-8 code 53 | * 54 | * @return mixed 55 | */ 56 | public function validateEan8(/** @scrutinizer ignore-unused */ $attribute, $value) 57 | { 58 | return $this->runIsoCodesValidator(\IsoCodes\Ean8::class, $value); 59 | } 60 | 61 | /** 62 | * Validate a EAN-13 code 63 | * 64 | * @return mixed 65 | */ 66 | public function validateEan13(/** @scrutinizer ignore-unused */ $attribute, $value) 67 | { 68 | return $this->runIsoCodesValidator(\IsoCodes\Ean13::class, $value); 69 | } 70 | 71 | /** 72 | * Validate a Global Document Type Identifier (GDTI) 73 | * 74 | * @return mixed 75 | */ 76 | public function validateGdti(/** @scrutinizer ignore-unused */ $attribute, $value) 77 | { 78 | return $this->runIsoCodesValidator(\IsoCodes\Gdti::class, $value); 79 | } 80 | 81 | /** 82 | * Validate a Global Location Number (GLN) 83 | * 84 | * @return mixed 85 | */ 86 | public function validateGln(/** @scrutinizer ignore-unused */ $attribute, $value) 87 | { 88 | return $this->runIsoCodesValidator(\IsoCodes\Gln::class, $value); 89 | } 90 | 91 | /** 92 | * Validate a Global Returnable Asset Identifier 93 | * 94 | * @return mixed 95 | */ 96 | public function validateGrai(/** @scrutinizer ignore-unused */ $attribute, $value) 97 | { 98 | return $this->runIsoCodesValidator(\IsoCodes\Grai::class, $value); 99 | } 100 | 101 | /** 102 | * Validate a Global Service Relation Number (GS1) 103 | * 104 | * @return mixed 105 | */ 106 | public function validateGsrn(/** @scrutinizer ignore-unused */ $attribute, $value) 107 | { 108 | return $this->runIsoCodesValidator(\IsoCodes\Gsrn::class, $value); 109 | } 110 | 111 | /** 112 | * Validate a GTIN-8 code 113 | * 114 | * @return mixed 115 | */ 116 | public function validateGtin8(/** @scrutinizer ignore-unused */ $attribute, $value) 117 | { 118 | return $this->runIsoCodesValidator(\IsoCodes\Gtin8::class, $value); 119 | } 120 | 121 | /** 122 | * Validate a GTIN-12 code 123 | * 124 | * @return mixed 125 | */ 126 | public function validateGtin12(/** @scrutinizer ignore-unused */ $attribute, $value) 127 | { 128 | return $this->runIsoCodesValidator(\IsoCodes\Gtin12::class, $value); 129 | } 130 | 131 | /** 132 | * Validate a GTIN-13 code 133 | * 134 | * @return mixed 135 | */ 136 | public function validateGtin13(/** @scrutinizer ignore-unused */ $attribute, $value) 137 | { 138 | return $this->runIsoCodesValidator(\IsoCodes\Gtin13::class, $value); 139 | } 140 | 141 | /** 142 | * Validate a GTIN-14 code 143 | * 144 | * @return mixed 145 | */ 146 | public function validateGtin14(/** @scrutinizer ignore-unused */ $attribute, $value) 147 | { 148 | return $this->runIsoCodesValidator(\IsoCodes\Gtin14::class, $value); 149 | } 150 | 151 | /** 152 | * Validate an IBAN 153 | * 154 | * @return mixed 155 | */ 156 | public function validateIban(/** @scrutinizer ignore-unused */ $attribute, $value) 157 | { 158 | return $this->runIsoCodesValidator(\IsoCodes\Iban::class, $value); 159 | } 160 | 161 | /** 162 | * Validate a "numéro de sécurité sociale" (INSEE) 163 | * 164 | * @return mixed 165 | */ 166 | public function validateInsee(/** @scrutinizer ignore-unused */ $attribute, $value) 167 | { 168 | return $this->runIsoCodesValidator(\IsoCodes\Insee::class, $value); 169 | } 170 | 171 | /** 172 | * Validate an IP address 173 | * 174 | * @return mixed 175 | */ 176 | public function validateIpaddress(/** @scrutinizer ignore-unused */ $attribute, $value) 177 | { 178 | return $this->runIsoCodesValidator(\IsoCodes\IP::class, $value); 179 | } 180 | 181 | /** 182 | * Validate an ISBN 183 | * 184 | * @return mixed 185 | */ 186 | public function validateIsbn($attribute, $value, $parameters) 187 | { 188 | $this->requireParameterCount(1, $parameters, 'isbn'); 189 | $type = $this->prepareReference($attribute, $parameters); 190 | 191 | return $this->runIsoCodesValidator(\IsoCodes\Isbn::class, $value, $type); 192 | } 193 | 194 | /** 195 | * Validate an "International Securities Identification Number" (ISIN) 196 | * 197 | * @return mixed 198 | */ 199 | public function validateIsin(/** @scrutinizer ignore-unused */ $attribute, $value) 200 | { 201 | return $this->runIsoCodesValidator(\IsoCodes\Isin::class, $value); 202 | } 203 | 204 | /** 205 | * Validate an "International Standard Music Number" or ISMN (ISO 10957) 206 | * 207 | * @return mixed 208 | */ 209 | public function validateIsmn(/** @scrutinizer ignore-unused */ $attribute, $value) 210 | { 211 | return $this->runIsoCodesValidator(\IsoCodes\Ismn::class, $value); 212 | } 213 | 214 | /** 215 | * Validate an "International Standard Musical Work Code" (ISWC) 216 | * 217 | * @return mixed 218 | */ 219 | public function validateIswc(/** @scrutinizer ignore-unused */ $attribute, $value) 220 | { 221 | return $this->runIsoCodesValidator(\IsoCodes\Iswc::class, $value); 222 | } 223 | 224 | /** 225 | * Validate a MAC address 226 | * 227 | * @return mixed 228 | */ 229 | public function validateMac(/** @scrutinizer ignore-unused */ $attribute, $value) 230 | { 231 | return $this->runIsoCodesValidator(\IsoCodes\Mac::class, $value); 232 | } 233 | 234 | /** 235 | * Validate a "Número de Identificación Fiscal" (NIF) 236 | * 237 | * @return mixed 238 | */ 239 | public function validateNif(/** @scrutinizer ignore-unused */ $attribute, $value) 240 | { 241 | return $this->runIsoCodesValidator(\IsoCodes\Nif::class, $value); 242 | } 243 | 244 | /** 245 | * Validate a "Organisme Type12 Norme B2" 246 | * 247 | * @return mixed 248 | */ 249 | public function validateOrganismeType12NormeB2($attribute, $value, $parameters) 250 | { 251 | $this->requireParameterCount(1, $parameters, 'organisme_type12_norme_b2'); 252 | $clef = $this->prepareReference($attribute, $parameters); 253 | 254 | return $this->runIsoCodesValidator(\IsoCodes\OrganismeType12NormeB2::class, $value, $clef); 255 | } 256 | 257 | /** 258 | * Validate a phone number 259 | * 260 | * @return mixed 261 | */ 262 | public function validatePhonenumber($attribute, $value, $parameters) 263 | { 264 | $this->requireParameterCount(1, $parameters, 'phonenumber'); 265 | $country = $this->prepareReference($attribute, $parameters); 266 | 267 | return $this->runIsoCodesValidator(\IsoCodes\PhoneNumber::class, $value, $country); 268 | } 269 | 270 | /** 271 | * Validate a Stock Exchange Daily Official List (SEDOL) 272 | * 273 | * @return mixed 274 | */ 275 | public function validateSedol(/** @scrutinizer ignore-unused */ $attribute, $value) 276 | { 277 | return $this->runIsoCodesValidator(\IsoCodes\Sedol::class, $value); 278 | } 279 | 280 | /** 281 | * Validate "Système d’Identification du Répertoire des Entreprises" (SIREN) 282 | * 283 | * @return mixed 284 | */ 285 | public function validateSiren(/** @scrutinizer ignore-unused */ $attribute, $value) 286 | { 287 | return $this->runIsoCodesValidator(\IsoCodes\Siren::class, $value); 288 | } 289 | 290 | /** 291 | * Validate "Système d’Identification du Répertoire des ETablissements" (SIRET) 292 | * 293 | * @return mixed 294 | */ 295 | public function validateSiret(/** @scrutinizer ignore-unused */ $attribute, $value) 296 | { 297 | return $this->runIsoCodesValidator(\IsoCodes\Siret::class, $value); 298 | } 299 | 300 | /** 301 | * Validate a European/International Article Number (SSCC) 302 | * 303 | * @return mixed 304 | */ 305 | public function validateSscc(/** @scrutinizer ignore-unused */ $attribute, $value) 306 | { 307 | return $this->runIsoCodesValidator(\IsoCodes\Sscc::class, $value); 308 | } 309 | 310 | /** 311 | * Validate a Social Security Number (SSN) 312 | * 313 | * @return mixed 314 | */ 315 | public function validateSsn(/** @scrutinizer ignore-unused */ $attribute, $value) 316 | { 317 | return $this->runIsoCodesValidator(\IsoCodes\Ssn::class, $value); 318 | } 319 | 320 | /** 321 | * Validate structured communication 322 | * 323 | * @return mixed 324 | */ 325 | public function validateStructuredCommunication(/** @scrutinizer ignore-unused */ $attribute, $value) 326 | { 327 | return $this->runIsoCodesValidator(\IsoCodes\StructuredCommunication::class, $value); 328 | } 329 | 330 | /** 331 | * Validate a SWIFT/BIC 332 | * 333 | * @return mixed 334 | */ 335 | public function validateSwiftBic(/** @scrutinizer ignore-unused */ $attribute, $value) 336 | { 337 | return $this->runIsoCodesValidator(\IsoCodes\SwiftBic::class, $value); 338 | } 339 | 340 | /** 341 | * Validate a Unique Device Identification 342 | * 343 | * @return mixed 344 | */ 345 | public function validateUdi(/** @scrutinizer ignore-unused */ $attribute, $value) 346 | { 347 | return $this->runIsoCodesValidator(\IsoCodes\Udi::class, $value); 348 | } 349 | 350 | /** 351 | * Validate a UK National Insurance Number 352 | * 353 | * @return mixed 354 | */ 355 | public function validateUknin(/** @scrutinizer ignore-unused */ $attribute, $value) 356 | { 357 | return $this->runIsoCodesValidator(\IsoCodes\Uknin::class, $value); 358 | } 359 | 360 | /** 361 | * Validate a Universal Product Code 362 | * 363 | * @return mixed 364 | */ 365 | public function validateUpca(/** @scrutinizer ignore-unused */ $attribute, $value) 366 | { 367 | return $this->runIsoCodesValidator(\IsoCodes\Upca::class, $value); 368 | } 369 | 370 | /** 371 | * Validate Value Added Tax (VAT) 372 | * 373 | * @return mixed 374 | */ 375 | public function validateVat(/** @scrutinizer ignore-unused */ $attribute, $value) 376 | { 377 | return $this->runIsoCodesValidator(\IsoCodes\Vat::class, $value); 378 | } 379 | 380 | /** 381 | * Validate a zip code 382 | * 383 | * @return mixed 384 | */ 385 | public function validateZipcode($attribute, $value, $parameters) 386 | { 387 | $this->requireParameterCount(1, $parameters, 'zipcode'); 388 | $country = $this->prepareReference($attribute, $parameters); 389 | 390 | return $this->runIsoCodesValidator(\IsoCodes\ZipCode::class, $value, $country); 391 | } 392 | 393 | /** 394 | * Prepare/get the reference when defined in dot notation 395 | * 396 | * @return mixed 397 | */ 398 | protected function prepareReference($attribute, $parameters) 399 | { 400 | if ($keys = $this->getExplicitKeys($attribute)) { 401 | $parameters = $this->replaceAsterisksInParameters($parameters, $keys); 402 | } 403 | 404 | return Arr::get($this->data, $parameters[0], $parameters[0]); 405 | } 406 | 407 | /** 408 | * Execute the validation function 409 | * and catch every other Exception from underlying libraries 410 | * so we will only display the Laravel validation error 411 | * 412 | * @param mixed $reference 413 | * @return mixed 414 | */ 415 | protected function runIsoCodesValidator($validator, $value, $reference = '') 416 | { 417 | try { 418 | if (empty($reference)) { 419 | return call_user_func($validator.'::validate', $value); 420 | } 421 | 422 | return call_user_func($validator.'::validate', $value, $reference); 423 | } catch (Exception $e) { 424 | // do nothing 425 | } 426 | } 427 | 428 | /** 429 | * Replace all country place-holders 430 | * 431 | * @param $parameter 432 | * @return mixed 433 | */ 434 | protected function countryReplacer($message, $reference) 435 | { 436 | return str_replace(':country', $reference, $message); 437 | } 438 | 439 | /** 440 | * Replace all value place-holders 441 | * 442 | * @return mixed 443 | */ 444 | protected function valueReplacer($message, $attribute) 445 | { 446 | return str_replace(':value', $this->getValue($attribute), $message); 447 | } 448 | 449 | /** 450 | * Replace all place-holders for the bban rule 451 | * 452 | * @param $rule 453 | * @param $parameter 454 | * @return mixed 455 | */ 456 | public function replaceBban($message, $attribute) 457 | { 458 | return $this->valueReplacer($message, $attribute); 459 | } 460 | 461 | /** 462 | * Replace all place-holders for the bsn rule 463 | * 464 | * @param $rule 465 | * @param $parameter 466 | * @return mixed 467 | */ 468 | public function replaceBsn($message, $attribute) 469 | { 470 | return $this->valueReplacer($message, $attribute); 471 | } 472 | 473 | /** 474 | * Replace all place-holders for the cif rule 475 | * 476 | * @param $rule 477 | * @param $parameter 478 | * @return mixed 479 | */ 480 | public function replaceCif($message, $attribute) 481 | { 482 | return $this->valueReplacer($message, $attribute); 483 | } 484 | 485 | /** 486 | * Replace all place-holders for the creditcard rule 487 | * 488 | * @param $rule 489 | * @param $parameter 490 | * @return mixed 491 | */ 492 | public function replaceCreditcard($message, $attribute) 493 | { 494 | return $this->valueReplacer($message, $attribute); 495 | } 496 | 497 | /** 498 | * Replace all place-holders for the ena8 rule 499 | * 500 | * @param $rule 501 | * @param $parameter 502 | * @return mixed 503 | */ 504 | public function replaceEan8($message, $attribute) 505 | { 506 | return $this->valueReplacer($message, $attribute); 507 | } 508 | 509 | /** 510 | * Replace all place-holders for the ean13 rule 511 | * 512 | * @param $rule 513 | * @param $parameter 514 | * @return mixed 515 | */ 516 | public function replaceEan13($message, $attribute) 517 | { 518 | return $this->valueReplacer($message, $attribute); 519 | } 520 | 521 | /** 522 | * Replace all place-holders for the gdti rule 523 | * 524 | * @param $rule 525 | * @param $parameter 526 | * @return mixed 527 | */ 528 | public function replaceGdti($message, $attribute) 529 | { 530 | return $this->valueReplacer($message, $attribute); 531 | } 532 | 533 | /** 534 | * Replace all place-holders for the gln rule 535 | * 536 | * @param $rule 537 | * @param $parameter 538 | * @return mixed 539 | */ 540 | public function replaceGln($message, $attribute) 541 | { 542 | return $this->valueReplacer($message, $attribute); 543 | } 544 | 545 | /** 546 | * Replace all place-holders for the grai rule 547 | * 548 | * @param $rule 549 | * @param $parameter 550 | * @return mixed 551 | */ 552 | public function replaceGrai($message, $attribute) 553 | { 554 | return $this->valueReplacer($message, $attribute); 555 | } 556 | 557 | /** 558 | * Replace all place-holders for the gsrn rule 559 | * 560 | * @param $rule 561 | * @param $parameter 562 | * @return mixed 563 | */ 564 | public function replaceGsrn($message, $attribute) 565 | { 566 | return $this->valueReplacer($message, $attribute); 567 | } 568 | 569 | /** 570 | * Replace all place-holders for the gitin8 rule 571 | * 572 | * @param $rule 573 | * @param $parameter 574 | * @return mixed 575 | */ 576 | public function replaceGtin8($message, $attribute) 577 | { 578 | return $this->valueReplacer($message, $attribute); 579 | } 580 | 581 | /** 582 | * Replace all place-holders for the gtin12 rule 583 | * 584 | * @param $rule 585 | * @param $parameter 586 | * @return mixed 587 | */ 588 | public function replaceGtin12($message, $attribute) 589 | { 590 | return $this->valueReplacer($message, $attribute); 591 | } 592 | 593 | /** 594 | * Replace all place-holders for the gtin13 rule 595 | * 596 | * @param $rule 597 | * @param $parameter 598 | * @return mixed 599 | */ 600 | public function replaceGtin13($message, $attribute) 601 | { 602 | return $this->valueReplacer($message, $attribute); 603 | } 604 | 605 | /** 606 | * Replace all place-holders for the gtin14 rule 607 | * 608 | * @param $rule 609 | * @param $parameter 610 | * @return mixed 611 | */ 612 | public function replaceGtin14($message, $attribute) 613 | { 614 | return $this->valueReplacer($message, $attribute); 615 | } 616 | 617 | /** 618 | * Replace all place-holders for the iban rule 619 | * 620 | * @param $rule 621 | * @param $parameter 622 | * @return mixed 623 | */ 624 | public function replaceIban($message, $attribute) 625 | { 626 | return $this->valueReplacer($message, $attribute); 627 | } 628 | 629 | /** 630 | * Replace all place-holders for the insee rule 631 | * 632 | * @param $rule 633 | * @param $parameter 634 | * @return mixed 635 | */ 636 | public function replaceInsee($message, $attribute) 637 | { 638 | return $this->valueReplacer($message, $attribute); 639 | } 640 | 641 | /** 642 | * Replace all place-holders for the ipaddress rule 643 | * 644 | * @param $rule 645 | * @param $parameter 646 | * @return mixed 647 | */ 648 | public function replaceIpaddress($message, $attribute) 649 | { 650 | return $this->valueReplacer($message, $attribute); 651 | } 652 | 653 | /** 654 | * Replace all place-holders for the isbn rule 655 | * 656 | * @param $rule 657 | * @param $parameter 658 | * @return mixed 659 | */ 660 | public function replaceIsbn($message, $attribute) 661 | { 662 | return $this->valueReplacer($message, $attribute); 663 | } 664 | 665 | /** 666 | * Replace all place-holders for the isin rule 667 | * 668 | * @param $rule 669 | * @param $parameter 670 | * @return mixed 671 | */ 672 | public function replaceIsin($message, $attribute) 673 | { 674 | return $this->valueReplacer($message, $attribute); 675 | } 676 | 677 | /** 678 | * Replace all place-holders for the ismn rule 679 | * 680 | * @param $rule 681 | * @param $parameter 682 | * @return mixed 683 | */ 684 | public function replaceIsmn($message, $attribute) 685 | { 686 | return $this->valueReplacer($message, $attribute); 687 | } 688 | 689 | /** 690 | * Replace all place-holders for the iswc rule 691 | * 692 | * @param $rule 693 | * @param $parameter 694 | * @return mixed 695 | */ 696 | public function replaceIswc($message, $attribute) 697 | { 698 | return $this->valueReplacer($message, $attribute); 699 | } 700 | 701 | /** 702 | * Replace all place-holders for the mac rule 703 | * 704 | * @param $rule 705 | * @param $parameter 706 | * @return mixed 707 | */ 708 | public function replaceMac($message, $attribute) 709 | { 710 | return $this->valueReplacer($message, $attribute); 711 | } 712 | 713 | /** 714 | * Replace all place-holders for the nif rule 715 | * 716 | * @param $rule 717 | * @param $parameter 718 | * @return mixed 719 | */ 720 | public function replaceNif($message, $attribute) 721 | { 722 | return $this->valueReplacer($message, $attribute); 723 | } 724 | 725 | /** 726 | * Replace all place-holders for the organisme_type12_norme_b2 rule 727 | * 728 | * @param $rule 729 | * @param $parameter 730 | * @return mixed 731 | */ 732 | public function replaceOrganismeType12NormeB2($message, $attribute) 733 | { 734 | return $this->valueReplacer($message, $attribute); 735 | } 736 | 737 | /** 738 | * Replace all place-holders for the phonenumber rule 739 | * 740 | * @return mixed 741 | */ 742 | protected function replacePhonenumber($message, $attribute, /** @scrutinizer ignore-unused */ $rule, $parameter) 743 | { 744 | $reference = $this->prepareReference($attribute, $parameter); 745 | 746 | $message = $this->valueReplacer($message, $attribute); 747 | $message = $this->countryReplacer($message, $reference); 748 | 749 | return $message; 750 | } 751 | 752 | /** 753 | * Replace all place-holders for the sedol rule 754 | * 755 | * @param $rule 756 | * @param $parameter 757 | * @return mixed 758 | */ 759 | public function replaceSedol($message, $attribute) 760 | { 761 | return $this->valueReplacer($message, $attribute); 762 | } 763 | 764 | /** 765 | * Replace all place-holders for the siren rule 766 | * 767 | * @param $rule 768 | * @param $parameter 769 | * @return mixed 770 | */ 771 | public function replaceSiren($message, $attribute) 772 | { 773 | return $this->valueReplacer($message, $attribute); 774 | } 775 | 776 | /** 777 | * Replace all place-holders for the siret rule 778 | * 779 | * @param $rule 780 | * @param $parameter 781 | * @return mixed 782 | */ 783 | public function replaceSiret($message, $attribute) 784 | { 785 | return $this->valueReplacer($message, $attribute); 786 | } 787 | 788 | /** 789 | * Replace all place-holders for the sscc rule 790 | * 791 | * @param $rule 792 | * @param $parameter 793 | * @return mixed 794 | */ 795 | public function replaceSscc($message, $attribute) 796 | { 797 | return $this->valueReplacer($message, $attribute); 798 | } 799 | 800 | /** 801 | * Replace all place-holders for the ssn rule 802 | * 803 | * @param $rule 804 | * @param $parameter 805 | * @return mixed 806 | */ 807 | public function replaceSSn($message, $attribute) 808 | { 809 | return $this->valueReplacer($message, $attribute); 810 | } 811 | 812 | /** 813 | * Replace all place-holders for the structured_communication rule 814 | * 815 | * @param $rule 816 | * @param $parameter 817 | * @return mixed 818 | */ 819 | public function replaceStructuredCommunication($message, $attribute) 820 | { 821 | return $this->valueReplacer($message, $attribute); 822 | } 823 | 824 | /** 825 | * Replace all place-holders for the swift_bic rule 826 | * 827 | * @param $rule 828 | * @param $parameter 829 | * @return mixed 830 | */ 831 | public function replaceSwiftBic($message, $attribute) 832 | { 833 | return $this->valueReplacer($message, $attribute); 834 | } 835 | 836 | /** 837 | * Replace all place-holders for the udi rule 838 | * 839 | * @param $rule 840 | * @param $parameter 841 | * @return mixed 842 | */ 843 | public function replaceUdi($message, $attribute) 844 | { 845 | return $this->valueReplacer($message, $attribute); 846 | } 847 | 848 | /** 849 | * Replace all place-holders for the uknin rule 850 | * 851 | * @param $rule 852 | * @param $parameter 853 | * @return mixed 854 | */ 855 | public function replaceUknin($message, $attribute) 856 | { 857 | return $this->valueReplacer($message, $attribute); 858 | } 859 | 860 | /** 861 | * Replace all place-holders for the upca rule 862 | * 863 | * @param $rule 864 | * @param $parameter 865 | * @return mixed 866 | */ 867 | public function replaceUpca($message, $attribute) 868 | { 869 | return $this->valueReplacer($message, $attribute); 870 | } 871 | 872 | /** 873 | * Replace all place-holders for the vat rule 874 | * 875 | * @param $rule 876 | * @param $parameter 877 | * @return mixed 878 | */ 879 | public function replaceVat($message, $attribute) 880 | { 881 | return $this->valueReplacer($message, $attribute); 882 | } 883 | 884 | /** 885 | * Replace all place-holders for the zipcode rule 886 | * 887 | * @return mixed 888 | */ 889 | public function replaceZipcode($message, $attribute, /** @scrutinizer ignore-unused */ $rule, $parameter) 890 | { 891 | $reference = $this->prepareReference($attribute, $parameter); 892 | 893 | $message = $this->valueReplacer($message, $attribute); 894 | $message = $this->countryReplacer($message, $reference); 895 | 896 | return $message; 897 | } 898 | } 899 | -------------------------------------------------------------------------------- /tests/IsoCodesValidatorTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($expected, $validator->errors()->first()); 22 | } 23 | 24 | /** 25 | * Test each validator returns true for valid data 26 | * 27 | * @test 28 | * 29 | * @dataProvider validDataProvider 30 | * 31 | * @param $payload 32 | * @param $rules 33 | */ 34 | public function it_validates_correctly($field, $value) 35 | { 36 | $validator = Validator::make([$field => $value], [$field => $field]); 37 | 38 | $this->assertTrue($validator->passes()); 39 | } 40 | 41 | /** 42 | * Test each validator with a reference value returns true for valid data 43 | * 44 | * @test 45 | * 46 | * @dataProvider validDataWithReferencesProvider 47 | * 48 | * @param $payload 49 | * @param $rules 50 | */ 51 | public function it_validates_correctly_with_references($field, $value, $referenceField = '', $referenceValue = '') 52 | { 53 | $payload = [ 54 | $field => $value, 55 | $referenceField => $referenceValue, 56 | ]; 57 | 58 | $rules = [ 59 | $field => "{$field}:{$referenceField}", 60 | ]; 61 | 62 | $validator = Validator::make($payload, $rules); 63 | 64 | $this->assertTrue($validator->passes()); 65 | } 66 | 67 | /** 68 | * DataProvider for simple rules 69 | * 70 | * @return array 71 | */ 72 | public function validDataProvider() 73 | { 74 | return include_once __DIR__.'/fixtures/valid.php'; 75 | } 76 | 77 | /** 78 | * DataProvider for failing tests 79 | * 80 | * @return array 81 | */ 82 | public function invalidDataProvider() 83 | { 84 | return include_once __DIR__.'/fixtures/invalid.php'; 85 | } 86 | 87 | /** 88 | * DataProvider for rules with references 89 | * 90 | * @return array 91 | */ 92 | public function validDataWithReferencesProvider() 93 | { 94 | return include_once __DIR__.'/fixtures/valid_with_references.php'; 95 | } 96 | 97 | /** 98 | * DataProvider for arrays with dot notation 99 | * 100 | * @return array 101 | */ 102 | public function validDataWithDotNotationProvider() 103 | { 104 | return include_once __DIR__.'/fixtures/valid_wit_dot_notation.php'; 105 | } 106 | 107 | /** 108 | * DataProvider for arrays with dot notation 109 | * 110 | * @return array 111 | */ 112 | public function invalidDataWithDotNotationProvider() 113 | { 114 | return include_once __DIR__.'/fixtures/invalid_wit_dot_notation.php'; 115 | } 116 | 117 | /** 118 | * Test validator can work on arrays with dot notation 119 | * and returns true for valid data 120 | * 121 | * @test 122 | * 123 | * @dataProvider validDataWithDotNotationProvider 124 | */ 125 | public function it_validates_correctly_with_dot_notation($data, $rule) 126 | { 127 | $payload = [ 128 | 'data' => $data, 129 | ]; 130 | 131 | $validator = Validator::make($payload, $rule); 132 | 133 | $this->assertTrue($validator->passes()); 134 | $this->assertEmpty($validator->errors()->all()); 135 | } 136 | 137 | /** 138 | * Test the correct error messages ist returned 139 | * on arrays with dot notation 140 | * 141 | * @test 142 | * 143 | * @dataProvider invalidDataWithDotNotationProvider 144 | */ 145 | public function validator_returns_correct_error_message_with_dot_notation($data, $rule, $error_message) 146 | { 147 | $payload = [ 148 | 'data' => $data, 149 | ]; 150 | 151 | $validator = Validator::make($payload, $rule); 152 | 153 | $this->assertTrue($validator->fails()); 154 | $this->assertCount(2, $validator->errors()->all()); 155 | $this->assertEquals($error_message[0], $validator->errors()->first()); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | register(\Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider::class); 24 | 25 | $app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 26 | 27 | return $app; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/fixtures/invalid.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'bban' => 'invalid', 8 | ], 9 | 'rules' => [ 10 | 'bban' => 'bban', 11 | ], 12 | 'message' => 'The value "invalid" of bban is not a valid BBAN code.', 13 | ], 14 | // BSN 15 | [ 16 | 'payload' => [ 17 | 'bsn' => 'invalid', 18 | ], 19 | 'rules' => [ 20 | 'bsn' => 'bsn', 21 | ], 22 | 'message' => 'The value "invalid" of bsn is not a valid BSN.', 23 | ], 24 | // CIF 25 | [ 26 | 'payload' => [ 27 | 'cif' => 'invalid', 28 | ], 29 | 'rules' => [ 30 | 'cif' => 'cif', 31 | ], 32 | 'message' => 'The value "invalid" of cif is not a valid CIF code.', 33 | ], 34 | // CREDITCARD 35 | [ 36 | 'payload' => [ 37 | 'creditcard' => 'invalid', 38 | ], 39 | 'rules' => [ 40 | 'creditcard' => 'creditcard', 41 | ], 42 | 'message' => 'The value "invalid" of creditcard is not a valid credit card number.', 43 | ], 44 | // EAN8 45 | [ 46 | 'payload' => [ 47 | 'ean8' => 'invalid', 48 | ], 49 | 'rules' => [ 50 | 'ean8' => 'ean8', 51 | ], 52 | 'message' => 'The value "invalid" of ean8 is not a valid EAN8 code.', 53 | ], 54 | // EAN13 55 | [ 56 | 'payload' => [ 57 | 'ean13' => 'invalid', 58 | ], 59 | 'rules' => [ 60 | 'ean13' => 'ean13', 61 | ], 62 | 'message' => 'The value "invalid" of ean13 is not a valid EAN13 code.', 63 | ], 64 | // GDTI 65 | [ 66 | 'payload' => [ 67 | 'gdti' => 'invalid', 68 | ], 69 | 'rules' => [ 70 | 'gdti' => 'gdti', 71 | ], 72 | 'message' => 'The value "invalid" of gdti is not a valid Global Document Type Identifier (GDTI).', 73 | ], 74 | // GLN 75 | [ 76 | 'payload' => [ 77 | 'gln' => 'invalid', 78 | ], 79 | 'rules' => [ 80 | 'gln' => 'gln', 81 | ], 82 | 'message' => 'The value "invalid" of gln is not a valid Global Location Number (GLN).', 83 | ], 84 | // GRAI 85 | [ 86 | 'payload' => [ 87 | 'grai' => 'invalid', 88 | ], 89 | 'rules' => [ 90 | 'grai' => 'grai', 91 | ], 92 | 'message' => 'The value "invalid" of grai is not a valid Global Returnable Asset Identifier.', 93 | ], 94 | // GSRN 95 | [ 96 | 'payload' => [ 97 | 'gsrn' => 'invalid', 98 | ], 99 | 'rules' => [ 100 | 'gsrn' => 'gsrn', 101 | ], 102 | 'message' => 'The value "invalid" of gsrn is not a valid Global Service Relation Number (GS1).', 103 | ], 104 | // GTIN8 105 | [ 106 | 'payload' => [ 107 | 'gtin8' => 'invalid', 108 | ], 109 | 'rules' => [ 110 | 'gtin8' => 'gtin8', 111 | ], 112 | 'message' => 'The value "invalid" of gtin8 is not a valid GTIN-8 code.', 113 | ], 114 | // GTIN12 115 | [ 116 | 'payload' => [ 117 | 'gtin12' => 'invalid', 118 | ], 119 | 'rules' => [ 120 | 'gtin12' => 'gtin12', 121 | ], 122 | 'message' => 'The value "invalid" of gtin12 is not a valid GTIN-12 code.', 123 | ], 124 | // GTIN13 125 | [ 126 | 'payload' => [ 127 | 'gtin13' => 'invalid', 128 | ], 129 | 'rules' => [ 130 | 'gtin13' => 'gtin13', 131 | ], 132 | 'message' => 'The value "invalid" of gtin13 is not a valid GTIN-13 code.', 133 | ], 134 | // GTIN14 135 | [ 136 | 'payload' => [ 137 | 'gtin14' => 'invalid', 138 | ], 139 | 'rules' => [ 140 | 'gtin14' => 'gtin14', 141 | ], 142 | 'message' => 'The value "invalid" of gtin14 is not a valid GTIN-14 code.', 143 | ], 144 | // IBAN 145 | [ 146 | 'payload' => [ 147 | 'iban' => 'invalid', 148 | ], 149 | 'rules' => [ 150 | 'iban' => 'iban', 151 | ], 152 | 'message' => 'The value "invalid" of iban is not a valid IBAN.', 153 | ], 154 | // INSEE 155 | [ 156 | 'payload' => [ 157 | 'insee' => 'invalid', 158 | ], 159 | 'rules' => [ 160 | 'insee' => 'insee', 161 | ], 162 | 'message' => 'The value "invalid" of insee is not a valid INSEE code.', 163 | ], 164 | // IP 165 | [ 166 | 'payload' => [ 167 | 'ipaddress' => 'invalid', 168 | ], 169 | 'rules' => [ 170 | 'ipaddress' => 'ipaddress', 171 | ], 172 | 'message' => 'The value "invalid" of ipaddress is not a valid ip address.', 173 | ], 174 | // ISBN 175 | [ 176 | 'payload' => [ 177 | 'isbn' => 'invalid', 178 | 'type' => 13, 179 | ], 180 | 'rules' => [ 181 | 'isbn' => 'isbn:type', 182 | ], 183 | 'message' => 'The value "invalid" of isbn is not a valid ISBN.', 184 | ], 185 | // ISIN 186 | [ 187 | 'payload' => [ 188 | 'isin' => 'invalid', 189 | ], 190 | 'rules' => [ 191 | 'isin' => 'isin', 192 | ], 193 | 'message' => 'The value "invalid" of isin is not a valid ISIN.', 194 | ], 195 | // ISMN 196 | [ 197 | 'payload' => [ 198 | 'ismn' => 'invalid', 199 | ], 200 | 'rules' => [ 201 | 'ismn' => 'ismn', 202 | ], 203 | 'message' => 'The value "invalid" of ismn is not a valid International Standard Music Number or ISMN (ISO 10957)', 204 | ], 205 | // ISWC 206 | [ 207 | 'payload' => [ 208 | 'iswc' => 'invalid', 209 | ], 210 | 'rules' => [ 211 | 'iswc' => 'iswc', 212 | ], 213 | 'message' => 'The value "invalid" of iswc is not a valid International Standard Musical Work Code (ISWC)', 214 | ], 215 | // MAC 216 | [ 217 | 'payload' => [ 218 | 'mac' => 'invalid', 219 | ], 220 | 'rules' => [ 221 | 'mac' => 'mac', 222 | ], 223 | 'message' => 'The value "invalid" of mac is not a valid MAC address.', 224 | ], 225 | // NIF 226 | [ 227 | 'payload' => [ 228 | 'nif' => 'invalid', 229 | ], 230 | 'rules' => [ 231 | 'nif' => 'nif', 232 | ], 233 | 'message' => 'The value "invalid" of nif is not a valid NIF.', 234 | ], 235 | // ORGANISME_TYPE12_NORME_B2 236 | [ 237 | 'payload' => [ 238 | 'organisme_type12_norme_b2' => 'invalid', 239 | 'clef' => 2, 240 | ], 241 | 'rules' => [ 242 | 'organisme_type12_norme_b2' => 'organisme_type12_norme_b2:clef', 243 | ], 244 | 'message' => 'The value "invalid" of organisme type12 norme b2 is not a valid Organisme Type12 Norme B2.', 245 | ], 246 | // PHONE NUMBER 247 | [ 248 | 'payload' => [ 249 | 'country' => 'GB', 250 | 'phonenumber' => 'invalid', 251 | ], 252 | 'rules' => [ 253 | 'phonenumber' => 'phonenumber:country', 254 | ], 255 | 'message' => 'The value "invalid" of phonenumber is not valid for "GB".', 256 | ], 257 | // SEDOL 258 | [ 259 | 'payload' => [ 260 | 'sedol' => 'invalid', 261 | ], 262 | 'rules' => [ 263 | 'sedol' => 'sedol', 264 | ], 265 | 'message' => 'The value "invalid" of sedol is not a valid SEDOL.', 266 | ], 267 | // SIREN 268 | [ 269 | 'payload' => [ 270 | 'siren' => 'invalid', 271 | ], 272 | 'rules' => [ 273 | 'siren' => 'siren', 274 | ], 275 | 'message' => 'The value "invalid" of siren is not a valid SIREN code.', 276 | ], 277 | // SIRET 278 | [ 279 | 'payload' => [ 280 | 'siret' => 'invalid', 281 | ], 282 | 'rules' => [ 283 | 'siret' => 'siret', 284 | ], 285 | 'message' => 'The value "invalid" of siret is not a valid SIRET code.', 286 | ], 287 | // SSCC 288 | [ 289 | 'payload' => [ 290 | 'sscc' => 'invalid', 291 | ], 292 | 'rules' => [ 293 | 'sscc' => 'sscc', 294 | ], 295 | 'message' => 'The value "invalid" of sscc is not a valid SSCC.', 296 | ], 297 | // SSN 298 | [ 299 | 'payload' => [ 300 | 'ssn' => 'invalid', 301 | ], 302 | 'rules' => [ 303 | 'ssn' => 'ssn', 304 | ], 305 | 'message' => 'The value "invalid" of ssn is not a valid SSN.', 306 | ], 307 | // STRUCTURED_COMMUNICATION 308 | [ 309 | 'payload' => [ 310 | 'structured_communication' => 'invalid', 311 | ], 312 | 'rules' => [ 313 | 'structured_communication' => 'structured_communication', 314 | ], 315 | 'message' => 'The value "invalid" of structured communication is not a valid structured communication code.', 316 | ], 317 | // SWIFT_BIC 318 | [ 319 | 'payload' => [ 320 | 'swift_bic' => 'invalid', 321 | ], 322 | 'rules' => [ 323 | 'swift_bic' => 'swift_bic', 324 | ], 325 | 'message' => 'The value "invalid" of swift bic is not a valid SWIFT/BIC.', 326 | ], 327 | // UDI 328 | [ 329 | 'payload' => [ 330 | 'udi' => 'invalid', 331 | ], 332 | 'rules' => [ 333 | 'udi' => 'udi', 334 | ], 335 | 'message' => 'The value "invalid" of udi is not a valid UDI.', 336 | ], 337 | // UKNIN 338 | [ 339 | 'payload' => [ 340 | 'uknin' => 'invalid', 341 | ], 342 | 'rules' => [ 343 | 'uknin' => 'uknin', 344 | ], 345 | 'message' => 'The value "invalid" of uknin is not a valid UK National Insurance Number.', 346 | ], 347 | // UPCA 348 | [ 349 | 'payload' => [ 350 | 'upca' => 'invalid', 351 | ], 352 | 'rules' => [ 353 | 'upca' => 'upca', 354 | ], 355 | 'message' => 'The value "invalid" of upca is not a valid UPCA.', 356 | ], 357 | // VAT 358 | [ 359 | 'payload' => [ 360 | 'vat' => 'invalid', 361 | ], 362 | 'rules' => [ 363 | 'vat' => 'vat', 364 | ], 365 | 'message' => 'The value "invalid" of vat is not a valid VAT.', 366 | ], 367 | // ZIPCODE 368 | [ 369 | 'payload' => [ 370 | 'country' => 'GB', 371 | 'zipcode' => 63741, 372 | ], 373 | 'rules' => [ 374 | 'zipcode' => 'zipcode:country', 375 | ], 376 | 'message' => 'The value "63741" of zipcode is not valid for "GB".', 377 | ], 378 | ]; 379 | -------------------------------------------------------------------------------- /tests/fixtures/invalid_wit_dot_notation.php: -------------------------------------------------------------------------------- 1 | [ 6 | [ 7 | 'country' => 'DE', 8 | 'zipcode' => 'invalid', 9 | ], 10 | [ 11 | 'country' => 'AT', 12 | 'zipcode' => 'invalid', 13 | ], 14 | ], 15 | 'rule' => [ 16 | 'data.*.zipcode' => 'zipcode:data.*.country', 17 | ], 18 | 'errors' => [ 19 | 'The value "invalid" of data.0.zipcode is not valid for "DE".', 20 | ], 21 | ], 22 | [ 23 | 'data' => [ 24 | [ 25 | 'country' => 'DE', 26 | 'phonenumber' => 'invalid', 27 | ], 28 | [ 29 | 'country' => 'US', 30 | 'phonenumber' => 'invalid', 31 | ], 32 | ], 33 | 'rule' => [ 34 | 'data.*.phonenumber' => 'phonenumber:data.*.country', 35 | ], 36 | 'errors' => [ 37 | 'The value "invalid" of data.0.phonenumber is not valid for "DE".', 38 | ], 39 | ], 40 | [ 41 | 'data' => [ 42 | [ 43 | 'type' => 10, 44 | 'isbn' => 'invalid', 45 | ], 46 | [ 47 | 'type' => 13, 48 | 'isbn' => 'invalid', 49 | ], 50 | ], 51 | 'rule' => [ 52 | 'data.*.isbn' => 'isbn:data.*.type', 53 | ], 54 | 'errors' => [ 55 | 'The value "invalid" of data.0.isbn is not a valid ISBN.', 56 | ], 57 | ], 58 | [ 59 | 'data' => [ 60 | [ 61 | 'clef' => 2, 62 | 'organisme_type12_norme_b2' => 'invalid', 63 | ], 64 | [ 65 | 'clef' => 2, 66 | 'organisme_type12_norme_b2' => 'invalid', 67 | ], 68 | ], 69 | 'rule' => [ 70 | 'data.*.organisme_type12_norme_b2' => 'organisme_type12_norme_b2:data.*.clef', 71 | ], 72 | 'errors' => [ 73 | 'The value "invalid" of data.0.organisme_type12_norme_b2 is not a valid Organisme Type12 Norme B2.', 74 | ], 75 | ], 76 | ]; 77 | -------------------------------------------------------------------------------- /tests/fixtures/invalid_with_references.php: -------------------------------------------------------------------------------- 1 | [ 6 | [ 7 | 'country' => 'DE', 8 | 'zipcode' => 63741, 9 | ], 10 | [ 11 | 'country' => 'AT', 12 | 'zipcode' => 1180, 13 | ], 14 | ], 15 | 'rule' => [ 16 | 'data.*.zipcode' => 'zipcode:data.*.country', 17 | ], 18 | ], 19 | [ 20 | 'data' => [ 21 | [ 22 | 'country' => 'DE', 23 | 'phonenumber' => '035384-08723', 24 | ], 25 | [ 26 | 'country' => 'US', 27 | 'phonenumber' => '+1-650-798-2800', 28 | ], 29 | ], 30 | 'rule' => [ 31 | 'data.*.phonenumber' => 'phonenumber:data.*.country', 32 | ], 33 | ], 34 | [ 35 | 'data' => [ 36 | [ 37 | 'type' => 10, 38 | 'isbn' => '3-598-21500-2', 39 | ], 40 | [ 41 | 'type' => 13, 42 | 'isbn' => '978-88-8183-718-2', 43 | ], 44 | ], 45 | 'rule' => [ 46 | 'data.*.isbn' => 'isbn:data.*.type', 47 | ], 48 | ], 49 | [ 50 | 'data' => [ 51 | [ 52 | 'clef' => 2, 53 | 'organisme_type12_norme_b2' => '76031208', 54 | ], 55 | [ 56 | 'clef' => 2, 57 | 'organisme_type12_norme_b2' => '76031208', 58 | ], 59 | ], 60 | 'rule' => [ 61 | 'data.*.organisme_type12_norme_b2' => 'organisme_type12_norme_b2:data.*.clef', 62 | ], 63 | ], 64 | ]; 65 | 66 | // ['organisme_type12_norme_b2', '76031208', 'clef', 2], 67 | -------------------------------------------------------------------------------- /tests/fixtures/valid_with_references.php: -------------------------------------------------------------------------------- 1 |