Repository: mattkingshott/axiom Branch: master Commit: 2cabdfa4e00f Files: 65 Total size: 98.4 KB Directory structure: gitextract_md4qeru_/ ├── .github/ │ ├── .php-cs-fixer.php │ └── workflows/ │ ├── style.yml │ └── tests.yml ├── .gitignore ├── .php-cs-fixer.cache ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml ├── src/ │ ├── Rules/ │ │ ├── CitizenIdentification.php │ │ ├── CountryCode.php │ │ ├── Decimal.php │ │ ├── DisposableEmail.php │ │ ├── Domain.php │ │ ├── EncodedImage.php │ │ ├── EvenNumber.php │ │ ├── FileExists.php │ │ ├── HexColor.php │ │ ├── ISBN.php │ │ ├── LanguageCode.php │ │ ├── LocationCoordinates.php │ │ ├── Lowercase.php │ │ ├── MacAddress.php │ │ ├── MaxWords.php │ │ ├── Missing.php │ │ ├── MonetaryFigure.php │ │ ├── OddNumber.php │ │ ├── RecordOwner.php │ │ ├── StrongPassword.php │ │ ├── TelephoneNumber.php │ │ ├── Titlecase.php │ │ ├── Uppercase.php │ │ └── WithoutWhitespace.php │ ├── Support/ │ │ ├── Iso3166Alpha2.php │ │ ├── Iso3166Alpha3.php │ │ ├── Iso6391Alpha2.php │ │ └── Iso6391Alpha3.php │ └── Types/ │ └── Rule.php ├── support/ │ ├── assets/ │ │ └── image.tiff │ └── migrations/ │ ├── 2014_10_12_000000_create_users_table.php │ └── 2015_10_12_000001_create_posts_table.php └── tests/ ├── CitizenIdentificationTest.php ├── CountryCodeTest.php ├── DecimalTest.php ├── DisposableEmailTest.php ├── DomainTest.php ├── EncodedImageTest.php ├── EvenNumber.php ├── FileExistsTest.php ├── HexColorTest.php ├── ISBNTest.php ├── LanguageCodeTest.php ├── LocationCoordinatesTest.php ├── LowercaseTest.php ├── MacAddress.php ├── MaxWordsTest.php ├── MissingTest.php ├── MonetaryFigureTest.php ├── OddNumberTest.php ├── RecordOwnerTest.php ├── StrongPasswordTest.php ├── TelephoneNumberTest.php ├── TitlecaseTest.php ├── UppercaseTest.php └── WithoutWhitespaceTest.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/.php-cs-fixer.php ================================================ notPath(dirname(__DIR__, 1) . '/bootstrap/*') ->notPath(dirname(__DIR__, 1) . '/storage/*') ->notPath(dirname(__DIR__, 1) . '/vendor') ->notPath(dirname(__DIR__, 1) . '/resources/view/mail/*') ->in([ dirname(__DIR__, 1) . '/src', dirname(__DIR__, 1) . '/tests', ]) ->name('*.php') ->notName('*.blade.php') ->ignoreDotFiles(true) ->ignoreVCS(true); return (new PhpCsFixer\Config()) ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], 'ordered_imports' => ['sort_algorithm' => 'length'], 'no_unused_imports' => true, 'not_operator_with_successor_space' => true, 'trailing_comma_in_multiline' => ['elements' => ['arrays']], 'phpdoc_scalar' => true, 'unary_operator_spaces' => true, 'binary_operator_spaces' => [ 'operators' => ['=' => 'align', '=>' => 'align'], ], 'blank_line_before_statement' => [ 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], ], 'phpdoc_single_line_var_spacing' => true, 'phpdoc_var_without_name' => true, 'class_attributes_separation' => [ 'elements' => [ 'method' => 'one', 'property' => 'one', ], ], 'method_argument_space' => [ 'on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => true, ], 'method_chaining_indentation' => true, 'object_operator_without_whitespace' => true, 'no_superfluous_phpdoc_tags' => true, 'function_declaration' => [ 'closure_function_spacing' => 'none', ], ]) ->setFinder($finder); ================================================ FILE: .github/workflows/style.yml ================================================ name: styling on: [push] jobs: style: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Run PHP CS Fixer uses: docker://oskarstark/php-cs-fixer-ga with: args: --config=.github/.php-cs-fixer.php --allow-risky=yes - name: Extract branch name shell: bash run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" id: extract_branch - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v2.3.0 with: commit_message: Fix styling branch: ${{ steps.extract_branch.outputs.branch }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ================================================ FILE: .github/workflows/tests.yml ================================================ name: tests on: [push, pull_request] jobs: phpunit: runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: os: [ubuntu-latest] php: [8.0] laravel: [8.*] dependency-version: [prefer-stable] include: - laravel: 8.* testbench: 6.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - name: Cache composer dependencies uses: actions/cache@v1 with: path: ~/.composer/cache/files key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick coverage: none - name: Run composer run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - name: Run tests run: vendor/bin/phpunit ================================================ FILE: .gitignore ================================================ build composer.lock vendor .DS_Store coverage .phpunit.result.cache .idea .php_cs.cache ================================================ FILE: .php-cs-fixer.cache ================================================ {"php":"8.1.12","version":"3.13.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":{"closure_function_spacing":"none"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"length"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":{"elements":["arrays"]},"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":{"operators":{"=":"align","=>":"align"}},"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one","property":"one"}},"method_chaining_indentation":true,"object_operator_without_whitespace":true,"no_superfluous_phpdoc_tags":true},"hashes":{"src\/Types\/Rule.php":"f9bf5c42f39c2c66885642062544f9ae","src\/Support\/Iso3166Alpha2.php":"977a855bb9b105ca5419f3ec40218f1f","src\/Support\/Iso6391Alpha2.php":"0d338792e3be972d4b04949a87e2825d","src\/Support\/Iso6391Alpha3.php":"f7b12294d0754242083378b1ad781d13","src\/Support\/Iso3166Alpha3.php":"e61f7a9197f01a97738c98cb45a810c4","src\/Rules\/Uppercase.php":"f9c7d4e41b30a979704c09da1de352aa","src\/Rules\/OddNumber.php":"127c80a2273da899dbfb40b5ee0f2f20","src\/Rules\/WithoutWhitespace.php":"0452e02c5dbce7c62a60d54afc597c00","src\/Rules\/LanguageCode.php":"811cca348dce882fe8103c320528fda7","src\/Rules\/HexColor.php":"a3085f26f7515a70c455062373f95ffc","src\/Rules\/EvenNumber.php":"8a7ede45e64335e094edc709f80f2363","src\/Rules\/CountryCode.php":"d5988befd25a6f27723f13725f46c969","src\/Rules\/MacAddress.php":"4b0f37bf8f01146a2f3ea44b047cc6e2","src\/Rules\/Missing.php":"1b561aa4f9c28e118b35c0d306e27f85","src\/Rules\/TelephoneNumber.php":"4477f8103bf10814c8f54464625c7703","src\/Rules\/FileExists.php":"adac5de044852641e4ad22611c41656c","src\/Rules\/DisposableEmail.php":"bf135848034f3ddfb129d3720233e5e5","src\/Rules\/Lowercase.php":"5b629fe98b41c8b8b191ea01f4104f01","src\/Rules\/MonetaryFigure.php":"83d45cbc19f3ce41550c827b7d5a9730","src\/Rules\/EncodedImage.php":"e387707eb1db81eaeb498f291a93af08","src\/Rules\/Domain.php":"e1357d4136b335e12a376d95729de996","src\/Rules\/StrongPassword.php":"d414d601649e5600216aedce2db61e98","src\/Rules\/RecordOwner.php":"c67fc6fbe3d8512f1e02ebbd77bfe9d8","src\/Rules\/Decimal.php":"ce2d2a7a78a0a472b529420a33c2aeed","src\/Rules\/CitizenIdentification.php":"650686d27727e1cd99342589d3fc7172","src\/Rules\/MaxWords.php":"67471f9303a67921a9b7fe9ead48fc95","src\/Rules\/Titlecase.php":"493e62b25b28952c5e7e08202e644bd1","src\/Rules\/LocationCoordinates.php":"087a31db1e6d89256b9fccedc6fde831","src\/Rules\/ISBN.php":"91fc0dd80d661e62572b5513d2cdafce","tests\/TitlecaseTest.php":"44818cd053258daaaa9c3fd8a24954e0","tests\/EncodedImageTest.php":"7e467b19ea98d9a30e90f15237f94666","tests\/TelephoneNumberTest.php":"b849a62d71b6b8d755fdfabc2b05efe4","tests\/StrongPasswordTest.php":"c625d322e42a24eec283c24082f15c92","tests\/MaxWordsTest.php":"3845fe73f45cc1ecf531b9d7d01969c6","tests\/LocationCoordinatesTest.php":"b0c195e0905872f82ea2053f7f842407","tests\/ISBNTest.php":"8f1e2b1bd3cb90a62a64e1c9e84e6e2a","tests\/DisposableEmailTest.php":"9e3eeeb2798b7cfbb5464263941cf593","tests\/UppercaseTest.php":"aa629098e7730edd79ffef17774457d6","tests\/MissingTest.php":"a73231ec3647e657e6647bc9f98049a9","tests\/EvenNumber.php":"62d66c4156664bea8e22eb9dc16e3f0b","tests\/CountryCodeTest.php":"c5931a09a59d1c4301bb395514176ab2","tests\/MonetaryFigureTest.php":"23b5d3a7e1a5ada65457ea83782bd215","tests\/MacAddress.php":"c5e0832ee35e456b1d2b782a798f7317","tests\/WithoutWhitespaceTest.php":"5e48e97dd571af93ce4c6f7e6e7667c4","tests\/FileExistsTest.php":"669c72bdce17d6e539ccb63c8d4f0e49","tests\/DecimalTest.php":"c69a10f7515876c7102509b7e8740b6a","tests\/LanguageCodeTest.php":"49d8063cf5ca0312791cab23a79eb208","tests\/RecordOwnerTest.php":"21cfdccbab1756768bbc6fac8594438e","tests\/DomainTest.php":"f239784278efaefdb1579d5bf507c78c","tests\/LowercaseTest.php":"374d9354b640d243422616627322a896","tests\/HexColorTest.php":"dfa9062e0e64db1c87c868be848b0762","tests\/OddNumberTest.php":"190eb439f5cd5949fe590cefa174fb78","tests\/CitizenIdentificationTest.php":"940fc4740f2686c1211d6a3a2ef53511"}} ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright © Caneara and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Axiom This package provides a library of reusable validation rules for your Laravel projects. Use them to augment the existing set provided by Laravel itself. ## Installation Pull in the package using composer ```bash composer require caneara/axiom ``` ## Upgrading Axiom includes several breaking changes from the original package, so you'll need to follow these steps if you were using the old version: 1. Ensure that you are using PHP 7.4 or later. 2. Remove `alphametric/laravel-validation-rules` from your `composer.json` file. 3. Run `composer update` to remove the package from your `vendor` directory. 4. Install Axiom by running `composer require caneara/axiom`. 5. Replace all instances of `use Alphametric\Validation` with `use Axiom`. 6. The `EndsWith` rule has been removed as Laravel now natively supports this. 7. The `Equals` rule has been removed. Instead, you should use Laravel's native `in` rule with a single option. 8. The `DoesNotExist` rule has been renamed to `Missing`. ## Usage As per the Laravel [documentation](https://laravel.com/docs/master/validation#using-rule-objects), simply import the relevant validation class wherever you require it, and then include it within the rules for a particular field: ```php use Axiom\Rules\StrongPassword; // ... $request->validate([ 'password' => ['bail', 'required', new StrongPassword], ]); ``` **IMPORTANT**: As with all custom rules, you cannot use a pipe-delimited string. You must instead use an `array` e.g. ```php 'password' => ['bail', 'required', new StrongPassword] // correct 'password' => 'bail|required|new StrongPassword' // wrong ``` If the validation fails, the package will attempt to respond with a localized error message (see message keys below). If the key does not exist, it will fall back to a hard-coded English language version. ## Available rules The following validation rules are currently available: | Rule | Message Key | Description | | --------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------- | | StrongPassword | validation.strong_password | Requires the presence of a "strong" password - see class for details | | TelephoneNumber | validation.telephone_number | Requires the presence of a valid telephone number - see class for details | | RecordOwner | validation.record_owner | Requires the authenticated user's id to match the user_id column on a given database record e.g. owner:posts,id | | MonetaryFigure | validation.monetary_figure | Requires the presence of a monetary figure e.g $72.33 - see class for details | | DisposableEmail | validation.disposable_email | Requires the presence of an email address which is not disposable | | Missing | validation.missing | Requires that the given value is not present in a given database table / column - see class for details | | Decimal | validation.decimal | Requires that the given value is a decimal with an appropriate format - see class for details | | EncodedImage | validation.encoded_image | Requires that the given value is a base64-encoded image of a given mime types - see class for details | | LocationCoordinates | validation.location_coordinates | Requires that the given value is a comma-separated set of latitude and longitude coordinates | | FileExists | validation.file_exists | Requires that the given value is a path to an existing file - see class for details | | MacAddress | validation.mac_address | Requires that the given value is a valid MAC address | | ISBN | validation.isbn | Requires that the given value is a valid ISBN-10 or ISBN-13 number | | EvenNumber | validation.even_number | Requires that the given value is an even number (decimals are first converted using intval) | | OddNumber | validation.odd_number | Requires that the given value is an odd number (decimals are first converted using intval) | | Lowercase | validation.lowercase | Requires that the given value is a lower case string | | Uppercase | validation.uppercase | Requires that the given value is a upper case string | | Titlecase | validation.titlecase | Requires that the given value is a title case string | | Domain | validation.domain | Requires that the given value be a domain e.g. google.com, www.google.com | | CitizenIdentification | validation.citizen_identification | Requires that the given value be a citizen identification number of USA, UK, France, Brazil or Vietnam (see class for details) | | WithoutWhitespace | validation.without_whitespace | Requires that the given value not include any whitespace characters | | MaxWords | validation.max_words | Requires that the given value cannot contain more words than specified | | HexColor | validation.hex_color | Requires that the given value is a valid hex color eg. #fff, #0f0f0f, #00ff0080 | ## Contributing Thank you for considering a contribution to Axiom. You are welcome to submit a PR containing improvements, however if they are substantial in nature, please also be sure to include a test or tests. ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. ================================================ FILE: composer.json ================================================ { "name": "caneara/axiom", "description": "A package that provides a library of reusable Laravel validation rules.", "keywords": [ "axiom", "php", "laravel", "validation", "rules" ], "type": "library", "license": "MIT", "homepage": "https://github.com/caneara/axiom", "autoload": { "psr-4": { "Axiom\\": "src" } }, "autoload-dev": { "psr-4": { "Axiom\\Tests\\": "tests" } }, "require": { "php": "^7.4|^8.0" }, "require-dev": { "orchestra/testbench": "^6.0", "phpunit/phpunit": "^9.0" }, "scripts": { "test": "vendor/bin/phpunit" }, "minimum-stability": "stable" } ================================================ FILE: phpunit.xml ================================================ src/ tests ================================================ FILE: src/Rules/CitizenIdentification.php ================================================ parameters[0] ?? 2) === 2 ? Iso3166Alpha2::$codes : Iso3166Alpha3::$codes; switch (mb_strtoupper($this->parameters[0] ?? 'USA')) { case 'US': case 'USA': return $this->verifyUnitedStates($value); case 'GB': case 'GBR': return $this->verifyUnitedKingdom($value); case 'FR': case 'FRA': return $this->verifyFrance($value); case 'BR': case 'BRA': return $this->verifyBrazil($value); case 'VI': case 'VN': return $this->verifyVietnam($value); default: return false; } } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'citizen_identification', 'The :attribute must be a valid form of identification' ); } /** * Verify whether the given value is a valid French citizen number. * **/ protected function verifyFrance($value) : bool { return preg_match('/^[1,2][ ]?[0-9]{2}[ ]?[0,1,2,3,5][0-9][ ]?[0-9A-Z]{5}[ ]?[0-9]{3}[ ]?[0-9]{2}$/', $value) > 0; } /** * Verify whether the given value is a valid United Kingdom citizen number. * **/ protected function verifyUnitedKingdom($value) : bool { return preg_match('/^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/', $value) > 0; } /** * Verify whether the given value is a valid United States citizen number. * **/ protected function verifyUnitedStates($value) : bool { return preg_match('/^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$/', $value) > 0; } /** * Verify whether the given value is a valid Brazil citizen number. * **/ protected function verifyBrazil($value) : bool { $value = preg_replace('/[^0-9]/is', '', $value); if (strlen($value) !== 11 || preg_match('/(\d)\1{10}/', $value)) { return false; } for ($t = 9; $t < 11; $t++) { for ($d = 0, $c = 0; $c < $t; $c++) { $d += $value[$c] * (($t + 1) - $c); } $d = ((10 * $d) % 11) % 10; if ($value[$c] != $d) { return false; } } return true; } /** * Verify whether the given value is a valid Vietnam citizen number. * **/ protected function verifyVietnam($value) : bool { $state = '0\d{2}'; // state code $century = ceil(date('Y') / 100); // current century $minNumGender = 0; //century: 20, male: 0, female: 1 // 20: begin century $maxNumGender = 1 + ($century - 20) * 2; //ex: century: 21, male: 2, female: 3. max: century: 25, male: 8, female: 9 $numBirth = '\d{2}'; // last 2 number of birth year $numRand = '\d{6}'; // 6 random number return preg_match('/^'.$state.'['.$minNumGender.'-'.$maxNumGender.']'.$numBirth.$numRand.'$/', $value) > 0; } } ================================================ FILE: src/Rules/CountryCode.php ================================================ parameters[0] ?? 2) === 2 ? Iso3166Alpha2::$codes : Iso3166Alpha3::$codes; return array_key_exists(strtoupper($value), $array); } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'country_code', 'The :attribute must be a valid ISO 3166-1 alpha-' . ($this->parameters[0] ?? 2) . ' country code' ); } } ================================================ FILE: src/Rules/Decimal.php ================================================ parameters[0])) . '.' . mt_rand(1, (int) str_repeat('9', $this->parameters[1])); } /** * Determine if the validation rule passes. * * The rule has two parameters: * 1. The maximum number of digits before the decimal point. * 2. The maximum number of digits after the decimal point. * **/ public function passes($attribute, $value) : bool { return preg_match( "/^[0-9]{1,{$this->parameters[0]}}(\.[0-9]{1,{$this->parameters[1]}})$/", $value ) > 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'decimal', 'The :attribute must be an appropriately formatted decimal e.g. ' . $this->example() ); } } ================================================ FILE: src/Rules/DisposableEmail.php ================================================ parameters[0] ?? false) ? false : true; } } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'disposable_email', 'The :attribute must be a valid, non-disposable domain' ); } } ================================================ FILE: src/Rules/Domain.php ================================================ 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'domain', 'The :attribute must be a valid domain without an http protocol e.g. google.com, www.google.com' ); } } ================================================ FILE: src/Rules/EncodedImage.php ================================================ file = tmpfile(); fwrite($this->file, base64_decode(Str::after($data, 'base64,'))); return new UploadedFile( stream_get_meta_data($this->file)['uri'], 'image', 'text/plain', null, true, true ); } /** * Determine if the validation rule passes. * * The rule requires at least a single parameter, which is * the expected mime types of the file e.g. png, jpeg etc. * You can also supply multiple mime types as an array. * **/ public function passes($attribute, $value) : bool { $valid_mime = false; foreach ($this->parameters as $mime) { if (Str::startsWith($value, "data:image/$mime;base64,")) { $valid_mime = true; break; } } if ($valid_mime) { $result = validator(['file' => $this->createTemporaryFile($value)], ['file' => 'image'])->passes(); fclose($this->file); return $result; } return false; } /** * Get the validation error message. * **/ public function message() : string { $mimes = $this->parameters; if (count($mimes) === 1) { return $this->getLocalizedErrorMessage( 'encoded_image', 'The :attribute must be a valid ' . $mimes[0] . ' image' ); } $mimes[count($mimes) - 1] = 'or ' . $mimes[count($mimes) - 1]; return $this->getLocalizedErrorMessage( 'encoded_image', 'The :attribute must be a valid ' . implode(', ', $mimes) . ' image' ); } } ================================================ FILE: src/Rules/EvenNumber.php ================================================ getLocalizedErrorMessage( 'even_number', 'The :attribute must be an even number' ); } } ================================================ FILE: src/Rules/FileExists.php ================================================ parameters[1] ?? '', '/'); $file = ltrim($value, '/'); return Storage::disk($this->parameters[0])->exists("$path/$file"); } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'file_exists', 'The file specified for :attribute does not exist' ); } } ================================================ FILE: src/Rules/HexColor.php ================================================ '/^#([a-fA-F0-9]{3})$/i', 7 => '/^#([a-fA-F0-9]{6})$/i', 9 => '/^#([a-fA-F0-9]{6}[0-9]{2})$/i', ]; /** * Determines if the rule passes. * * @param string $attribute * * @return bool */ public function passes($attribute, $value) { if (! is_string($value) || ! in_array(strlen($value), array_keys($this->formats))) { return false; } $match = preg_match($this->formats[strlen($value)], $value); return $match > 0; } /** * Message returned on validation failure. * * @return array|string */ public function message() { return $this->getLocalizedErrorMessage( 'hex_color', 'The :attribute has to be a valid hex color.' ); } } ================================================ FILE: src/Rules/ISBN.php ================================================ 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'ISBN', 'The :attribute must be a valid ISBN 10 or ISBN 13 number' ); } } ================================================ FILE: src/Rules/LanguageCode.php ================================================ parameters[0] ?? 2) === 2 ? Iso6391Alpha2::$codes : Iso6391Alpha3::$codes; return array_key_exists(strtoupper($value), $array); } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'language_code', 'The :attribute must be a valid ISO 639-1 alpha-' . ($this->parameters[0] ?? 2) . ' language code' ); } } ================================================ FILE: src/Rules/LocationCoordinates.php ================================================ 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'location_coordinates', 'The :attribute must be a valid set of latitude and longitude coordinates, with a limit of 8 digits after a decimal point' ); } } ================================================ FILE: src/Rules/Lowercase.php ================================================ getLocalizedErrorMessage( 'lowercase', 'The :attribute must be entirely lowercase text' ); } } ================================================ FILE: src/Rules/MacAddress.php ================================================ 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'mac_address', 'The :attribute must be a valid MAC address' ); } } ================================================ FILE: src/Rules/MaxWords.php ================================================ parameters[0]; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'max_words', 'The :attribute cannot be longer than ' . $this->parameters[0] . ' words.' ); } } ================================================ FILE: src/Rules/Missing.php ================================================ parameters[0]) ->where($this->parameters[1], $value) ->doesntExist(); } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'missing', 'The :attribute already exists' ); } } ================================================ FILE: src/Rules/MonetaryFigure.php ================================================ parameters[0] . mt_rand(1, (int) str_repeat('9', $this->parameters[1])) . '.' . mt_rand(1, (int) str_repeat('9', $this->parameters[2])); } /** * Determine if the validation rule passes. * * The monetary figure requires three parameters: * 1. The currency symbol required e.g. '$', '£', '€'. * 2. The maximum number of digits before the decimal point. * 3. The maximum number of digits after the decimal point. * **/ public function passes($attribute, $value) : bool { return preg_match( "/^\\{$this->parameters[0]}[0-9]{1,{$this->parameters[1]}}(\.[0-9]{1,{$this->parameters[2]}})?$/", $value ) > 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'monetary_figure', 'The :attribute must be a monetary figure e.g. ' . $this->example() ); } } ================================================ FILE: src/Rules/OddNumber.php ================================================ getLocalizedErrorMessage( 'odd_number', 'The :attribute must be an odd number' ); } } ================================================ FILE: src/Rules/RecordOwner.php ================================================ parameters[0]) ->where($this->parameters[1], $value) ->where('user_id', Auth::id()) ->exists(); } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'record_owner', 'You do not have permission to interact with this resource' ); } } ================================================ FILE: src/Rules/StrongPassword.php ================================================ ,.\/~`±§+-]).{12,30}$/', $value ) > 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'strong_password', 'The :attribute must be 12–30 characters, and include a number, a symbol, a lower and a upper case letter' ); } } ================================================ FILE: src/Rules/TelephoneNumber.php ================================================ 0; } /** * Get the validation error message. * **/ public function message() : string { return $this->getLocalizedErrorMessage( 'telephone_number', 'The :attribute must be a valid telephone number (7 - 15 digits in length)' ); } } ================================================ FILE: src/Rules/Titlecase.php ================================================ getLocalizedErrorMessage( 'titlecase', 'Each word in :attribute must begin with a capital letter' ); } } ================================================ FILE: src/Rules/Uppercase.php ================================================ getLocalizedErrorMessage( 'uppercase', 'The :attribute must be entirely uppercase text' ); } } ================================================ FILE: src/Rules/WithoutWhitespace.php ================================================ getLocalizedErrorMessage( 'without_whitespace', 'The :attribute must be an unbroken string of text, it cannot include spaces' ); } } ================================================ FILE: src/Support/Iso3166Alpha2.php ================================================ 'Andorra', 'AE' => 'United Arab Emirates', 'AF' => 'Afghanistan', 'AG' => 'Antigua and Barbuda', 'AI' => 'Anguilla', 'AL' => 'Albania', 'AM' => 'Armenia', 'AO' => 'Angola', 'AQ' => 'Antarctica', 'AR' => 'Argentina', 'AS' => 'American Samoa', 'AT' => 'Austria', 'AU' => 'Australia', 'AW' => 'Aruba', 'AX' => 'Åland Islands', 'AZ' => 'Azerbaijan', 'BA' => 'Bosnia and Herzegovina', 'BB' => 'Barbados', 'BD' => 'Bangladesh', 'BE' => 'Belgium', 'BF' => 'Burkina Faso', 'BG' => 'Bulgaria', 'BH' => 'Bahrain', 'BI' => 'Burundi', 'BJ' => 'Benin', 'BL' => 'Saint Barthélemy', 'BM' => 'Bermuda', 'BN' => 'Brunei Darussalam', 'BO' => 'Bolivia, Plurinational State of', 'BQ' => 'Bonaire, Sint Eustatius and Saba', 'BR' => 'Brazil', 'BS' => 'Bahamas', 'BT' => 'Bhutan', 'BV' => 'Bouvet Island', 'BW' => 'Botswana', 'BY' => 'Belarus', 'BZ' => 'Belize', 'CA' => 'Canada', 'CC' => 'Cocos (Keeling) Islands', 'CD' => 'Congo, the Democratic Republic of the', 'CF' => 'Central African Republic', 'CG' => 'Congo', 'CH' => 'Switzerland', 'CI' => 'Côte d\'Ivoire', 'CK' => 'Cook Islands', 'CL' => 'Chile', 'CM' => 'Cameroon', 'CN' => 'China', 'CO' => 'Colombia', 'CR' => 'Costa Rica', 'CU' => 'Cuba', 'CV' => 'Cabo Verde', 'CW' => 'Curaçao', 'CX' => 'Christmas Island', 'CY' => 'Cyprus', 'CZ' => 'Czechia', 'DE' => 'Germany', 'DJ' => 'Djibouti', 'DK' => 'Denmark', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'DZ' => 'Algeria', 'EC' => 'Ecuador', 'EE' => 'Estonia', 'EG' => 'Egypt', 'EH' => 'Western Sahara', 'ER' => 'Eritrea', 'ES' => 'Spain', 'ET' => 'Ethiopia', 'FI' => 'Finland', 'FJ' => 'Fiji', 'FK' => 'Falkland Islands (Malvinas)', 'FM' => 'Micronesia, Federated States of', 'FO' => 'Faroe Islands', 'FR' => 'France', 'GA' => 'Gabon', 'GB' => 'United Kingdom of Great Britain and Northern Ireland', 'GD' => 'Grenada', 'GE' => 'Georgia', 'GF' => 'French Guiana', 'GG' => 'Guernsey', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GL' => 'Greenland', 'GM' => 'Gambia', 'GN' => 'Guinea', 'GP' => 'Guadeloupe', 'GQ' => 'Equatorial Guinea', 'GR' => 'Greece', 'GS' => 'South Georgia and the South Sandwich Islands', 'GT' => 'Guatemala', 'GU' => 'Guam', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HK' => 'Hong Kong', 'HM' => 'Heard Island and McDonald Islands', 'HN' => 'Honduras', 'HR' => 'Croatia', 'HT' => 'Haiti', 'HU' => 'Hungary', 'ID' => 'Indonesia', 'IE' => 'Ireland', 'IL' => 'Israel', 'IM' => 'Isle of Man', 'IN' => 'India', 'IO' => 'British Indian Ocean Territory', 'IQ' => 'Iraq', 'IR' => 'Iran, Islamic Republic of', 'IS' => 'Iceland', 'IT' => 'Italy', 'JE' => 'Jersey', 'JM' => 'Jamaica', 'JO' => 'Jordan', 'JP' => 'Japan', 'KE' => 'Kenya', 'KG' => 'Kyrgyzstan', 'KH' => 'Cambodia', 'KI' => 'Kiribati', 'KM' => 'Comoros', 'KN' => 'Saint Kitts and Nevis', 'KP' => 'Korea, Democratic People\'s Republic of', 'KR' => 'Korea, Republic of', 'KW' => 'Kuwait', 'KY' => 'Cayman Islands', 'KZ' => 'Kazakhstan', 'LA' => 'Lao People\'s Democratic Republic', 'LB' => 'Lebanon', 'LC' => 'Saint Lucia', 'LI' => 'Liechtenstein', 'LK' => 'Sri Lanka', 'LR' => 'Liberia', 'LS' => 'Lesotho', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'LV' => 'Latvia', 'LY' => 'Libya', 'MA' => 'Morocco', 'MC' => 'Monaco', 'MD' => 'Moldova, Republic of', 'ME' => 'Montenegro', 'MF' => 'Saint Martin (French part)', 'MG' => 'Madagascar', 'MH' => 'Marshall Islands', 'MK' => 'Macedonia, the former Yugoslav Republic of', 'ML' => 'Mali', 'MM' => 'Myanmar', 'MN' => 'Mongolia', 'MO' => 'Macao', 'MP' => 'Northern Mariana Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MS' => 'Montserrat', 'MT' => 'Malta', 'MU' => 'Mauritius', 'MV' => 'Maldives', 'MW' => 'Malawi', 'MX' => 'Mexico', 'MY' => 'Malaysia', 'MZ' => 'Mozambique', 'NA' => 'Namibia', 'NC' => 'New Caledonia', 'NE' => 'Niger', 'NF' => 'Norfolk Island', 'NG' => 'Nigeria', 'NI' => 'Nicaragua', 'NL' => 'Netherlands', 'NO' => 'Norway', 'NP' => 'Nepal', 'NR' => 'Nauru', 'NU' => 'Niue', 'NZ' => 'New Zealand', 'OM' => 'Oman', 'PA' => 'Panama', 'PE' => 'Peru', 'PF' => 'French Polynesia', 'PG' => 'Papua New Guinea', 'PH' => 'Philippines', 'PK' => 'Pakistan', 'PL' => 'Poland', 'PM' => 'Saint Pierre and Miquelon', 'PN' => 'Pitcairn', 'PR' => 'Puerto Rico', 'PS' => 'Palestine, State of', 'PT' => 'Portugal', 'PW' => 'Palau', 'PY' => 'Paraguay', 'QA' => 'Qatar', 'RE' => 'Réunion', 'RO' => 'Romania', 'RS' => 'Serbia', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'SA' => 'Saudi Arabia', 'SB' => 'Solomon Islands', 'SC' => 'Seychelles', 'SD' => 'Sudan', 'SE' => 'Sweden', 'SG' => 'Singapore', 'SH' => 'Saint Helena, Ascension and Tristan da Cunha', 'SI' => 'Slovenia', 'SJ' => 'Svalbard and Jan Mayen', 'SK' => 'Slovakia', 'SL' => 'Sierra Leone', 'SM' => 'San Marino', 'SN' => 'Senegal', 'SO' => 'Somalia', 'SR' => 'Suriname', 'SS' => 'South Sudan', 'ST' => 'Sao Tome and Principe', 'SV' => 'El Salvador', 'SX' => 'Sint Maarten (Dutch part)', 'SY' => 'Syrian Arab Republic', 'SZ' => 'Eswatini', 'TC' => 'Turks and Caicos Islands', 'TD' => 'Chad', 'TF' => 'French Southern Territories', 'TG' => 'Togo', 'TH' => 'Thailand', 'TJ' => 'Tajikistan', 'TK' => 'Tokelau', 'TL' => 'Timor-Leste', 'TM' => 'Turkmenistan', 'TN' => 'Tunisia', 'TO' => 'Tonga', 'TR' => 'Turkey', 'TT' => 'Trinidad and Tobago', 'TV' => 'Tuvalu', 'TW' => 'Taiwan, Province of China', 'TZ' => 'Tanzania, United Republic of', 'UA' => 'Ukraine', 'UG' => 'Uganda', 'UM' => 'United States Minor Outlying Islands', 'US' => 'United States of America', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VA' => 'Holy See', 'VC' => 'Saint Vincent and the Grenadines', 'VE' => 'Venezuela, Bolivarian Republic of', 'VG' => 'Virgin Islands, British', 'VI' => 'Virgin Islands, U.S.', 'VN' => 'Viet Nam', 'VU' => 'Vanuatu', 'WF' => 'Wallis and Futuna', 'WS' => 'Samoa', 'YE' => 'Yemen', 'YT' => 'Mayotte', 'XK' => 'Republic of Kosovo', 'ZA' => 'South Africa', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe', ]; } ================================================ FILE: src/Support/Iso3166Alpha3.php ================================================ 'Aruba', 'AFG' => 'Afghanistan', 'AGO' => 'Angola', 'AIA' => 'Anguilla', 'ALA' => 'Åland Islands', 'ALB' => 'Albania', 'AND' => 'Andorra', 'ARE' => 'United Arab Emirates', 'ARG' => 'Argentina', 'ARM' => 'Armenia', 'ASM' => 'American Samoa', 'ATA' => 'Antarctica', 'ATF' => 'French Southern Territories', 'ATG' => 'Antigua and Barbuda', 'AUS' => 'Australia', 'AUT' => 'Austria', 'AZE' => 'Azerbaijan', 'BDI' => 'Burundi', 'BEL' => 'Belgium', 'BEN' => 'Benin', 'BES' => 'Bonaire, Sint Eustatius and Saba', 'BFA' => 'Burkina Faso', 'BGD' => 'Bangladesh', 'BGR' => 'Bulgaria', 'BHR' => 'Bahrain', 'BHS' => 'Bahamas', 'BIH' => 'Bosnia and Herzegovina', 'BLM' => 'Saint Barthélemy', 'BLR' => 'Belarus', 'BLZ' => 'Belize', 'BMU' => 'Bermuda', 'BOL' => 'Bolivia, Plurinational State of', 'BRA' => 'Brazil', 'BRB' => 'Barbados', 'BRN' => 'Brunei Darussalam', 'BTN' => 'Bhutan', 'BVT' => 'Bouvet Island', 'BWA' => 'Botswana', 'CAF' => 'Central African Republic', 'CAN' => 'Canada', 'CCK' => 'Cocos (Keeling) Islands', 'CHE' => 'Switzerland', 'CHL' => 'Chile', 'CHN' => 'China', 'CIV' => 'Côte d\'Ivoire', 'CMR' => 'Cameroon', 'COD' => 'Congo, the Democratic Republic of the', 'COG' => 'Congo', 'COK' => 'Cook Islands', 'COL' => 'Colombia', 'COM' => 'Comoros', 'CPV' => 'Cabo Verde', 'CRI' => 'Costa Rica', 'CUB' => 'Cuba', 'CUW' => 'Curaçao', 'CXR' => 'Christmas Island', 'CYM' => 'Cayman Islands', 'CYP' => 'Cyprus', 'CZE' => 'Czech Republic', 'DEU' => 'Germany', 'DJI' => 'Djibouti', 'DMA' => 'Dominica', 'DNK' => 'Denmark', 'DOM' => 'Dominican Republic', 'DZA' => 'Algeria', 'ECU' => 'Ecuador', 'EGY' => 'Egypt', 'ERI' => 'Eritrea', 'ESH' => 'Western Sahara', 'ESP' => 'Spain', 'EST' => 'Estonia', 'ETH' => 'Ethiopia', 'FIN' => 'Finland', 'FJI' => 'Fiji', 'FLK' => 'Falkland Islands (Malvinas)', 'FRA' => 'France', 'FRO' => 'Faroe Islands', 'FSM' => 'Micronesia, Federated States of', 'GAB' => 'Gabon', 'GBR' => 'United Kingdom of Great Britain and Northern Ireland', 'GEO' => 'Georgia', 'GGY' => 'Guernsey', 'GHA' => 'Ghana', 'GIB' => 'Gibraltar', 'GIN' => 'Guinea', 'GLP' => 'Guadeloupe', 'GMB' => 'Gambia', 'GNB' => 'Guinea-Bissau', 'GNQ' => 'Equatorial Guinea', 'GRC' => 'Greece', 'GRD' => 'Grenada', 'GRL' => 'Greenland', 'GTM' => 'Guatemala', 'GUF' => 'French Guiana', 'GUM' => 'Guam', 'GUY' => 'Guyana', 'HKG' => 'Hong Kong', 'HMD' => 'Heard Island and McDonald Islands', 'HND' => 'Honduras', 'HRV' => 'Croatia', 'HTI' => 'Haiti', 'HUN' => 'Hungary', 'IDN' => 'Indonesia', 'IMN' => 'Isle of Man', 'IND' => 'India', 'IOT' => 'British Indian Ocean Territory', 'IRL' => 'Ireland', 'IRN' => 'Iran, Islamic Republic of', 'IRQ' => 'Iraq', 'ISL' => 'Iceland', 'ISR' => 'Israel', 'ITA' => 'Italy', 'JAM' => 'Jamaica', 'JEY' => 'Jersey', 'JOR' => 'Jordan', 'JPN' => 'Japan', 'KAZ' => 'Kazakhstan', 'KEN' => 'Kenya', 'KGZ' => 'Kyrgyzstan', 'KHM' => 'Cambodia', 'KIR' => 'Kiribati', 'KNA' => 'Saint Kitts and Nevis', 'KOR' => 'Korea, Republic of', 'KWT' => 'Kuwait', 'LAO' => 'Lao People\'s Democratic Republic', 'LBN' => 'Lebanon', 'LBR' => 'Liberia', 'LBY' => 'Libya', 'LCA' => 'Saint Lucia', 'LIE' => 'Liechtenstein', 'LKA' => 'Sri Lanka', 'LSO' => 'Lesotho', 'LTU' => 'Lithuania', 'LUX' => 'Luxembourg', 'LVA' => 'Latvia', 'MAC' => 'Macao', 'MAF' => 'Saint Martin (French part)', 'MAR' => 'Morocco', 'MCO' => 'Monaco', 'MDA' => 'Moldova', 'MDG' => 'Madagascar', 'MDV' => 'Maldives', 'MEX' => 'Mexico', 'MHL' => 'Marshall Islands', 'MKD' => 'Macedonia, the former Yugoslav Republic of', 'MLI' => 'Mali', 'MLT' => 'Malta', 'MMR' => 'Myanmar', 'MNE' => 'Montenegro', 'MNG' => 'Mongolia', 'MNP' => 'Northern Mariana Islands', 'MOZ' => 'Mozambique', 'MRT' => 'Mauritania', 'MSR' => 'Montserrat', 'MTQ' => 'Martinique', 'MUS' => 'Mauritius', 'MWI' => 'Malawi', 'MYS' => 'Malaysia', 'MYT' => 'Mayotte', 'NAM' => 'Namibia', 'NCL' => 'New Caledonia', 'NER' => 'Niger', 'NFK' => 'Norfolk Island', 'NGA' => 'Nigeria', 'NIC' => 'Nicaragua', 'NIU' => 'Niue', 'NLD' => 'Netherlands', 'NOR' => 'Norway', 'NPL' => 'Nepal', 'NRU' => 'Nauru', 'NZL' => 'New Zealand', 'OMN' => 'Oman', 'PAK' => 'Pakistan', 'PAN' => 'Panama', 'PCN' => 'Pitcairn', 'PER' => 'Peru', 'PHL' => 'Philippines', 'PLW' => 'Palau', 'PNG' => 'Papua New Guinea', 'POL' => 'Poland', 'PRI' => 'Puerto Rico', 'PRK' => 'Korea, Democratic People\'s Republic of', 'PRT' => 'Portugal', 'PRY' => 'Paraguay', 'PSE' => 'Palestine, State of', 'PYF' => 'French Polynesia', 'QAT' => 'Qatar', 'REU' => 'Réunion', 'ROU' => 'Romania', 'RUS' => 'Russian Federation', 'RWA' => 'Rwanda', 'SAU' => 'Saudi Arabia', 'SDN' => 'Sudan', 'SEN' => 'Senegal', 'SGP' => 'Singapore', 'SGS' => 'South Georgia and the South Sandwich Islands', 'SHN' => 'Saint Helena, Ascension and Tristan da Cunha', 'SJM' => 'Svalbard and Jan Mayen', 'SLB' => 'Solomon Islands', 'SLE' => 'Sierra Leone', 'SLV' => 'El Salvador', 'SMR' => 'San Marino', 'SOM' => 'Somalia', 'SPM' => 'Saint Pierre and Miquelon', 'SRB' => 'Serbia', 'SSD' => 'South Sudan', 'STP' => 'Sao Tome and Principe', 'SUR' => 'Suriname', 'SVK' => 'Slovakia', 'SVN' => 'Slovenia', 'SWE' => 'Sweden', 'SWZ' => 'Eswatini', 'SXM' => 'Sint Maarten (Dutch part)', 'SYC' => 'Seychelles', 'SYR' => 'Syrian Arab Republic', 'TCA' => 'Turks and Caicos Islands', 'TCD' => 'Chad', 'TGO' => 'Togo', 'THA' => 'Thailand', 'TJK' => 'Tajikistan', 'TKL' => 'Tokelau', 'TKM' => 'Turkmenistan', 'TLS' => 'Timor-Leste', 'TON' => 'Tonga', 'TTO' => 'Trinidad and Tobago', 'TUN' => 'Tunisia', 'TUR' => 'Turkey', 'TUV' => 'Tuvalu', 'TWN' => 'Taiwan, Province of China', 'TZA' => 'Tanzania, United Republic of', 'UGA' => 'Uganda', 'UKR' => 'Ukraine', 'UMI' => 'United States Minor Outlying Islands', 'URY' => 'Uruguay', 'USA' => 'United States of America', 'UZB' => 'Uzbekistan', 'VAT' => 'Holy See', 'VCT' => 'Saint Vincent and the Grenadines', 'VEN' => 'Venezuela, Bolivarian Republic of', 'VGB' => 'Virgin Islands, British', 'VIR' => 'Virgin Islands, U.S.', 'VNM' => 'Viet Nam', 'VUT' => 'Vanuatu', 'WLF' => 'Wallis and Futuna', 'WSM' => 'Samoa', 'YEM' => 'Yemen', 'ZAF' => 'South Africa', 'ZMB' => 'Zambia', 'ZWE' => 'Zimbabwe', ]; } ================================================ FILE: src/Support/Iso6391Alpha2.php ================================================ 'Abkhazian', 'AA' => 'Afar', 'AF' => 'Afrikaans', 'AK' => 'Akan', 'SQ' => 'Albanian', 'AM' => 'Amharic', 'AR' => 'Arabic', 'AN' => 'Aragonese', 'HY' => 'Armenian', 'AS' => 'Assamese', 'AV' => 'Avaric', 'AE' => 'Avestan', 'AY' => 'Aymara', 'AZ' => 'Azerbaijani', 'BM' => 'Bambara', 'BA' => 'Bashkir', 'EU' => 'Basque', 'BE' => 'Belarusian', 'BN' => 'Bengali', 'BH' => 'Bihari languages', 'BI' => 'Bislama', 'BS' => 'Bosnian', 'BR' => 'Breton', 'BG' => 'Bulgarian', 'MY' => 'Burmese', 'CA' => 'Catalan, Valencian', 'KM' => 'Central Khmer', 'CH' => 'Chamorro', 'CE' => 'Chechen', 'NY' => 'Chichewa, Chewa, Nyanja', 'ZH' => 'Chinese', 'CU' => 'Church Slavonic, Old Bulgarian, Old Church Slavonic', 'CV' => 'Chuvash', 'KW' => 'Cornish', 'CO' => 'Corsican', 'CR' => 'Cree', 'HR' => 'Croatian', 'CS' => 'Czech', 'DA' => 'Danish', 'DV' => 'Divehi, Dhivehi, Maldivian', 'NL' => 'Dutch, Flemish', 'DZ' => 'Dzongkha', 'EN' => 'English', 'EO' => 'Esperanto', 'ET' => 'Estonian', 'EE' => 'Ewe', 'FO' => 'Faroese', 'FJ' => 'Fijian', 'FI' => 'Finnish', 'FR' => 'French', 'FF' => 'Fulah', 'GD' => 'Gaelic, Scottish Gaelic', 'GL' => 'Galician', 'LG' => 'Ganda', 'KA' => 'Georgian', 'DE' => 'German', 'KI' => 'Gikuyu, Kikuyu', 'EL' => 'Greek (Modern)', 'KL' => 'Greenlandic, Kalaallisut', 'GN' => 'Guarani', 'GU' => 'Gujarati', 'HT' => 'Haitian, Haitian Creole', 'HA' => 'Hausa', 'HE' => 'Hebrew', 'HZ' => 'Herero', 'HI' => 'Hindi', 'HO' => 'Hiri Motu', 'HU' => 'Hungarian', 'IS' => 'Icelandic', 'IO' => 'Ido', 'IG' => 'Igbo', 'ID' => 'Indonesian', 'IA' => 'Interlingua (International Auxiliary Language Association)', 'IE' => 'Interlingue', 'IU' => 'Inuktitut', 'IK' => 'Inupiaq', 'GA' => 'Irish', 'IT' => 'Italian', 'JA' => 'Japanese', 'JV' => 'Javanese', 'KN' => 'Kannada', 'KR' => 'Kanuri', 'KS' => 'Kashmiri', 'KK' => 'Kazakh', 'RW' => 'Kinyarwanda', 'KV' => 'Komi', 'KG' => 'Kongo', 'KO' => 'Korean', 'KJ' => 'Kwanyama, Kuanyama', 'KU' => 'Kurdish', 'KY' => 'Kyrgyz', 'LO' => 'Lao', 'LA' => 'Latin', 'LV' => 'Latvian', 'LB' => 'Letzeburgesch, Luxembourgish', 'LI' => 'Limburgish, Limburgan, Limburger', 'LN' => 'Lingala', 'LT' => 'Lithuanian', 'LU' => 'Luba-Katanga', 'MK' => 'Macedonian', 'MG' => 'Malagasy', 'MS' => 'Malay', 'ML' => 'Malayalam', 'MT' => 'Maltese', 'GV' => 'Manx', 'MI' => 'Maori', 'MR' => 'Marathi', 'MH' => 'Marshallese', 'RO' => 'Moldovan, Moldavian, Romanian', 'MN' => 'Mongolian', 'NA' => 'Nauru', 'NV' => 'Navajo, Navaho', 'ND' => 'Northern Ndebele', 'NG' => 'Ndonga', 'NE' => 'Nepali', 'SE' => 'Northern Sami', 'NO' => 'Norwegian', 'NB' => 'Norwegian Bokmål', 'NN' => 'Norwegian Nynorsk', 'II' => 'Nuosu, Sichuan Yi', 'OC' => 'Occitan (post 1500)', 'OJ' => 'Ojibwa', 'OR' => 'Oriya', 'OM' => 'Oromo', 'OS' => 'Ossetian, Ossetic', 'PI' => 'Pali', 'PA' => 'Panjabi, Punjabi', 'PS' => 'Pashto, Pushto', 'FA' => 'Persian', 'PL' => 'Polish', 'PT' => 'Portuguese', 'QU' => 'Quechua', 'RM' => 'Romansh', 'RN' => 'Rundi', 'RU' => 'Russian', 'SM' => 'Samoan', 'SG' => 'Sango', 'SA' => 'Sanskrit', 'SC' => 'Sardinian', 'SR' => 'Serbian', 'SN' => 'Shona', 'SD' => 'Sindhi', 'SI' => 'Sinhala, Sinhalese', 'SK' => 'Slovak', 'SL' => 'Slovenian', 'SO' => 'Somali', 'ST' => 'Sotho, Southern', 'NR' => 'South Ndebele', 'ES' => 'Spanish, Castilian', 'SU' => 'Sundanese', 'SW' => 'Swahili', 'SS' => 'Swati', 'SV' => 'Swedish', 'TL' => 'Tagalog', 'TY' => 'Tahitian', 'TG' => 'Tajik', 'TA' => 'Tamil', 'TT' => 'Tatar', 'TE' => 'Telugu', 'TH' => 'Thai', 'BO' => 'Tibetan', 'TI' => 'Tigrinya', 'TO' => 'Tonga (Tonga Islands)', 'TS' => 'Tsonga', 'TN' => 'Tswana', 'TR' => 'Turkish', 'TK' => 'Turkmen', 'TW' => 'Twi', 'UG' => 'Uighur, Uyghur', 'UK' => 'Ukrainian', 'UR' => 'Urdu', 'UZ' => 'Uzbek', 'VE' => 'Venda', 'VI' => 'Vietnamese', 'VO' => 'Volap_k', 'WA' => 'Walloon', 'CY' => 'Welsh', 'FY' => 'Western Frisian', 'WO' => 'Wolof', 'XH' => 'Xhosa', 'YI' => 'Yiddish', 'YO' => 'Yoruba', 'ZA' => 'Zhuang, Chuang', 'ZU' => 'Zulu', ]; } ================================================ FILE: src/Support/Iso6391Alpha3.php ================================================ 'Abkhazian', 'AAR' => 'Afar', 'AFR' => 'Afrikaans', 'ALB' => 'Albanian', 'SQI' => 'Albanian', 'AMH' => 'Amharic', 'ARA' => 'Arabic', 'ARG' => 'Aragonese', 'ARM' => 'Armenian', 'HYE' => 'Armenian', 'ASM' => 'Assamese', 'AVE' => 'Avestan', 'AYM' => 'Aymara', 'AZE' => 'Azerbaijani', 'BAK' => 'Bashkir', 'BAQ' => 'Basque', 'EUS' => 'Basque', 'BEL' => 'Belarusian', 'BEN' => 'Bengali', 'BIH' => 'Bihari', 'BIS' => 'Bislama', 'BOS' => 'Bosnian', 'BRE' => 'Breton', 'BUL' => 'Bulgarian', 'BUR' => 'Burmese', 'MYA' => 'Burmese', 'CAT' => 'Catalan', 'CHA' => 'Chamorro', 'CHE' => 'Chechen', 'CHI' => 'Chinese', 'ZHO' => 'Chinese', 'CHU' => 'Church Slavic, Slavonic, Old Bulgarian', 'CHV' => 'Chuvash', 'COR' => 'Cornish', 'COS' => 'Corsican', 'HRV' => 'Croatian', 'SCR' => 'Croatian', 'CZE' => 'Czech', 'CES' => 'Czech', 'DAN' => 'Danish', 'DIV' => 'Divehi, Dhivehi, Maldivian', 'DUT' => 'Dutch', 'NLD' => 'Dutch', 'DZO' => 'Dzongkha', 'ENG' => 'English', 'EPO' => 'Esperanto', 'EST' => 'Estonian', 'FAO' => 'Faroese', 'FIJ' => 'Fijian', 'FIN' => 'Finnish', 'FRE' => 'French', 'FRA' => 'French', 'GD' => 'Gaelic, Scottish Gaelic', 'GLA' => 'Gaelic, Scottish Gaelic', 'GLG' => 'Galician', 'GEO' => 'Georgian', 'KAT' => 'Georgian', 'GER' => 'German', 'DEU' => 'German', 'GRE' => 'Greek, Modern', 'ELL' => 'Greek, Modern', 'GRN' => 'Guarani', 'GUJ' => 'Gujarati', 'HAT' => 'Haitian, Haitian Creole', 'HAU' => 'Hausa', 'HEB' => 'Hebrew', 'HER' => 'Herero', 'HIN' => 'Hindi', 'HMO' => 'Hiri Motu', 'HUN' => 'Hungarian', 'ICE' => 'Icelandic', 'ISL' => 'Icelandic', 'IDO' => 'Ido', 'IND' => 'Indonesian', 'INA' => 'Interlingua', 'ILE' => 'Interlingue', 'IKU' => 'Inuktitut', 'IPK' => 'Inupiaq', 'GLE' => 'Irish', 'ITA' => 'Italian', 'JPN' => 'Japanese', 'JAV' => 'Javanese', 'KAL' => 'Kalaallisut', 'KAN' => 'Kannada', 'KAS' => 'Kashmiri', 'KAZ' => 'Kazakh', 'KHM' => 'Khmer', 'KIK' => 'Kikuyu, Gikuyu', 'KIN' => 'Kinyarwanda', 'KIR' => 'Kirghiz', 'KOM' => 'Komi', 'KOR' => 'Korean', 'KUA' => 'Kuanyama, Kwanyama', 'KUR' => 'Kurdish', 'LAO' => 'Lao', 'LAT' => 'Latin', 'LAV' => 'Latvian', 'LIM' => 'Limburgan, Limburger, Limburgish', 'LIN' => 'Lingala', 'LIT' => 'Lithuanian', 'LTZ' => 'Luxembourgish, Letzeburgesch', 'MAC' => 'Macedonian', 'MKD' => 'Macedonian', 'MLG' => 'Malagasy', 'MAY' => 'Malay', 'MSA' => 'Malay', 'MAL' => 'Malayalam', 'MLT' => 'Maltese', 'GLV' => 'Manx', 'MAO' => 'Maori', 'MRI' => 'Maori', 'MAR' => 'Marathi', 'MAH' => 'Marshallese', 'MOL' => 'Moldavian', 'MON' => 'Mongolian', 'NAU' => 'Nauru', 'NAV' => 'Navaho, Navajo', 'NDE' => 'Ndebele, North', 'NBL' => 'Ndebele, South', 'NDO' => 'Ndonga', 'NEP' => 'Nepali', 'SME' => 'Northern Sami', 'NOR' => 'Norwegian', 'NOB' => 'Norwegian Bokmal', 'NNO' => 'Norwegian Nynorsk', 'NYA' => 'Nyanja, Chichewa, Chewa', 'OCI' => 'Occitan, Provencal', 'ORI' => 'Oriya', 'ORM' => 'Oromo', 'OSS' => 'Ossetian, Ossetic', 'PLI' => 'Pali', 'PAN' => 'Panjabi', 'PER' => 'Persian', 'FAS' => 'Persian', 'POL' => 'Polish', 'POR' => 'Portuguese', 'PUS' => 'Pushto', 'QUE' => 'Quechua', 'ROH' => 'Raeto-Romance', 'RUM' => 'Romanian', 'RON' => 'Romanian', 'RUN' => 'Rundi', 'RUS' => 'Russian', 'SMO' => 'Samoan', 'SAG' => 'Sango', 'SAN' => 'Sanskrit', 'SRD' => 'Sardinian', 'SCC' => 'Serbian', 'SRP' => 'Serbian', 'SNA' => 'Shona', 'III' => 'Sichuan Yi', 'SND' => 'Sindhi', 'SIN' => 'Sinhala, Sinhalese', 'SLO' => 'Slovak', 'SLK' => 'Slovak', 'SLV' => 'Slovenian', 'SOM' => 'Somali', 'SOT' => 'Sotho, Southern', 'SPA' => 'Spanish, Castilian', 'SUN' => 'Sundanese', 'SWA' => 'Swahili', 'SSW' => 'Swati', 'SWE' => 'Swedish', 'TGL' => 'Tagalog', 'TAH' => 'Tahitian', 'TGK' => 'Tajik', 'TAM' => 'Tamil', 'TAT' => 'Tatar', 'TEL' => 'Telugu', 'THA' => 'Thai', 'TIB' => 'Tibetan', 'BOD' => 'Tibetan', 'TIR' => 'Tigrinya', 'TON' => 'Tonga', 'TSO' => 'Tsonga', 'TSN' => 'Tswana', 'TUR' => 'Turkish', 'TUK' => 'Turkmen', 'TWI' => 'Twi', 'UIG' => 'Uighur', 'UKR' => 'Ukrainian', 'URD' => 'Urdu', 'UZB' => 'Uzbek', 'VIE' => 'Vietnamese', 'VOL' => 'Volapuk', 'WLN' => 'Walloon', 'WEL' => 'Welsh', 'CYM' => 'Welsh', 'FRY' => 'Western Frisian', 'WOL' => 'Wolof', 'XHO' => 'Xhosa', 'YID' => 'Yiddish', 'YOR' => 'Yoruba', 'ZHA' => 'Zhuang, Chuang', 'ZUL' => 'Zulu', ]; } ================================================ FILE: src/Types/Rule.php ================================================ parameters = func_get_args(); } /** * Retrieve the appropriate, localized validation message * or fall back to the given default. * **/ public function getLocalizedErrorMessage(string $key, string $default) : string { return trans("validation.$key") === "validation.$key" ? $default : trans("validation.$key"); } } ================================================ FILE: support/migrations/2014_10_12_000000_create_users_table.php ================================================ bigIncrements('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * **/ public function down() : void { Schema::dropIfExists('users'); } } ================================================ FILE: support/migrations/2015_10_12_000001_create_posts_table.php ================================================ bigIncrements('id'); $table->unsignedBigInteger('user_id'); $table->string('title'); $table->timestamps(); }); } /** * Reverse the migrations. * **/ public function down() : void { Schema::dropIfExists('posts'); } } ================================================ FILE: tests/CitizenIdentificationTest.php ================================================ [new CitizenIdentification('usa')]]; $this->assertFalse(validator(['id' => 'XXX-XX-XXXX'], $rule)->passes()); $this->assertFalse(validator(['id' => '000-11-1111'], $rule)->passes()); $this->assertTrue(validator(['id' => '401-60-1048'], $rule)->passes()); $this->assertTrue(validator(['id' => '318-66-9044'], $rule)->passes()); $rule = ['id' => [new CitizenIdentification('us')]]; $this->assertFalse(validator(['id' => 'XXX-XX-XXXX'], $rule)->passes()); $this->assertFalse(validator(['id' => '000-11-1111'], $rule)->passes()); $this->assertTrue(validator(['id' => '401-60-1048'], $rule)->passes()); $this->assertTrue(validator(['id' => '318-66-9044'], $rule)->passes()); } /** @test */ public function the_citizen_identification_rule_can_be_validated_for_gbr() { $rule = ['id' => [new CitizenIdentification('gbr')]]; $this->assertFalse(validator(['id' => 'DC135798A'], $rule)->passes()); $this->assertFalse(validator(['id' => 'FQ987654C'], $rule)->passes()); $this->assertTrue(validator(['id' => 'JG103759A'], $rule)->passes()); $this->assertTrue(validator(['id' => 'AP019283D'], $rule)->passes()); $rule = ['id' => [new CitizenIdentification('gb')]]; $this->assertFalse(validator(['id' => 'DC135798A'], $rule)->passes()); $this->assertFalse(validator(['id' => 'FQ987654C'], $rule)->passes()); $this->assertTrue(validator(['id' => 'JG103759A'], $rule)->passes()); $this->assertTrue(validator(['id' => 'AP019283D'], $rule)->passes()); } /** @test */ public function the_citizen_identification_rule_can_be_validated_for_fra() { $rule = ['id' => [new CitizenIdentification('fra')]]; $this->assertFalse(validator(['id' => 'DC135798A'], $rule)->passes()); $this->assertFalse(validator(['id' => 'FQ987654C'], $rule)->passes()); $this->assertTrue(validator(['id' => '1 51 02 46102 043 25'], $rule)->passes()); $rule = ['id' => [new CitizenIdentification('fr')]]; $this->assertFalse(validator(['id' => 'DC135798A'], $rule)->passes()); $this->assertFalse(validator(['id' => 'FQ987654C'], $rule)->passes()); $this->assertTrue(validator(['id' => '1 51 02 46102 043 25'], $rule)->passes()); } /** @test */ public function the_citizen_identification_rule_can_be_validated_for_bra() { $rule = ['id' => [new CitizenIdentification('bra')]]; $this->assertFalse(validator(['id' => '9876543218'], $rule)->passes()); $this->assertFalse(validator(['id' => '03464227362'], $rule)->passes()); $this->assertTrue(validator(['id' => '166.525.300-23'], $rule)->passes()); $this->assertTrue(validator(['id' => '16652530023'], $rule)->passes()); $rule = ['id' => [new CitizenIdentification('br')]]; $this->assertFalse(validator(['id' => '9876543218'], $rule)->passes()); $this->assertFalse(validator(['id' => '03464227362'], $rule)->passes()); $this->assertTrue(validator(['id' => '166.525.300-23'], $rule)->passes()); $this->assertTrue(validator(['id' => '16652530023'], $rule)->passes()); } /** @test */ public function the_citizen_identification_rule_can_be_validated_for_vn() { $rule = ['id' => [new CitizenIdentification('vn')]]; $this->assertFalse(validator(['id' => '101597002120'], $rule)->passes()); $this->assertFalse(validator(['id' => '0501991234561'], $rule)->passes()); $this->assertTrue(validator(['id' => '001097002120'], $rule)->passes()); $this->assertTrue(validator(['id' => '050199123456'], $rule)->passes()); $rule = ['id' => [new CitizenIdentification('vi')]]; $this->assertFalse(validator(['id' => '101597002120'], $rule)->passes()); $this->assertFalse(validator(['id' => '0501991234561'], $rule)->passes()); $this->assertTrue(validator(['id' => '001097002120'], $rule)->passes()); $this->assertTrue(validator(['id' => '050199123456'], $rule)->passes()); } } ================================================ FILE: tests/CountryCodeTest.php ================================================ [new CountryCode(2)]]; $this->assertTrue(validator(['code' => 'US'], $rule)->passes()); $this->assertTrue(validator(['code' => 'GB'], $rule)->passes()); $this->assertTrue(validator(['code' => 'FR'], $rule)->passes()); $this->assertFalse(validator(['code' => 'xx'], $rule)->passes()); } /** @test */ public function the_three_letter_country_code_rule_can_be_validated() { $rule = ['code' => [new CountryCode(3)]]; $this->assertTrue(validator(['code' => 'USA'], $rule)->passes()); $this->assertTrue(validator(['code' => 'GBR'], $rule)->passes()); $this->assertTrue(validator(['code' => 'FRA'], $rule)->passes()); $this->assertFalse(validator(['code' => 'xxx'], $rule)->passes()); } } ================================================ FILE: tests/DecimalTest.php ================================================ [new Decimal(4, 2)]]; $this->assertFalse(validator(['figure' => '1'], $rule)->passes()); $this->assertFalse(validator(['figure' => '123'], $rule)->passes()); $this->assertFalse(validator(['figure' => '1234'], $rule)->passes()); $this->assertFalse(validator(['figure' => '1234.'], $rule)->passes()); $this->assertTrue(validator(['figure' => '1234.5'], $rule)->passes()); $this->assertTrue(validator(['figure' => '1234.56'], $rule)->passes()); $this->assertFalse(validator(['figure' => '1234.567'], $rule)->passes()); $this->assertTrue(validator(['figure' => '1234.0'], $rule)->passes()); $this->assertTrue(validator(['figure' => '1234.00'], $rule)->passes()); } /** @test */ public function the_decimal_rule_example_is_valid() { $rule = ['figure' => [$class = new Decimal(4, 2)]]; $this->assertTrue(validator(['figure' => $class->example()], $rule)->passes()); } } ================================================ FILE: tests/DisposableEmailTest.php ================================================ ['bail', 'email', new DisposableEmail()]]; $this->assertTrue(validator(['email' => 'john.doe@gmail.com'], $rule)->passes()); $this->assertFalse(validator(['email' => 'john.doe@mailinator.com'], $rule)->passes()); } } ================================================ FILE: tests/DomainTest.php ================================================ [new Domain]]; $this->assertFalse(validator(['domain' => 'http://'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'https://'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'http://google.com'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'https://google.com'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'http://google'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'https://google'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'https://google.com/test'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'google.com/test'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'www.google.com/test'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'www.google.com/test/test'], $rule)->passes()); $this->assertFalse(validator(['domain' => 'google'], $rule)->passes()); $this->assertFalse(validator(['domain' => '1'], $rule)->passes()); $this->assertTrue(validator(['domain' => 'google.com'], $rule)->passes()); $this->assertTrue(validator(['domain' => 'www.google.com'], $rule)->passes()); } } ================================================ FILE: tests/EncodedImageTest.php ================================================ [new EncodedImage('png')]]; $jpeg_rule = ['image' => [new EncodedImage('jpeg')]]; $multiple_rule = ['image' => [new EncodedImage('jpeg', 'png')]]; $this->assertFalse(validator(['image' => $this->getFile('image.jpeg')], $png_rule)->passes()); $this->assertTrue(validator(['image' => $this->getFile('image.png')], $png_rule)->passes()); $this->assertTrue(validator(['image' => $this->getFile('image.jpeg')], $jpeg_rule)->passes()); $this->assertFalse(validator(['image' => $this->getFile('image.png')], $jpeg_rule)->passes()); $this->assertTrue(validator(['image' => $this->getFile('image.png')], $multiple_rule)->passes()); $this->assertTrue(validator(['image' => $this->getFile('image.jpeg')], $multiple_rule)->passes()); $this->assertFalse(validator(['image' => $this->getFile('image.tiff')], $multiple_rule)->passes()); $this->assertFalse(validator(['image' => $this->invalidImage('image.jpeg')], $jpeg_rule)->passes()); $this->assertFalse(validator(['image' => $this->invalidImage('image.png')], $jpeg_rule)->passes()); $this->assertFalse(validator(['image' => $this->invalidImage()], $jpeg_rule)->passes()); } } ================================================ FILE: tests/EvenNumber.php ================================================ [new EvenNumber]]; $this->assertFalse(validator(['number' => '1'], $rule)->passes()); $this->assertTrue(validator(['number' => '2'], $rule)->passes()); $this->assertFalse(validator(['number' => '3'], $rule)->passes()); $this->assertTrue(validator(['number' => '4'], $rule)->passes()); } } ================================================ FILE: tests/FileExistsTest.php ================================================ set('filesystems.disks.local', [ 'driver' => 'local', 'root' => realpath(__DIR__ . '/..') . '/support/assets', ]); } /** @test */ public function the_file_exists_rule_can_be_validated() { $rule = ['file' => [new FileExists('local', '/')]]; $this->assertTrue(validator(['file' => 'image.png'], $rule)->passes()); $this->assertTrue(validator(['file' => '/image.png'], $rule)->passes()); $this->assertFalse(validator(['file' => '/fake.png'], $rule)->passes()); $this->assertFalse(validator(['file' => 'fake.png'], $rule)->passes()); } } ================================================ FILE: tests/HexColorTest.php ================================================ [new HexColor()]]; $this->assertTrue(validator(['hex_color' => '#f0f0f0'], $rule)->passes()); $this->assertTrue(validator(['hex_color' => '#fff'], $rule)->passes()); $this->assertTrue(validator(['hex_color' => '#00ff0080'], $rule)->passes()); $this->assertFalse(validator(['hex_color' => '#00ff00ff'], $rule)->passes()); $this->assertFalse(validator(['hex_color' => 'f0f0f0'], $rule)->passes()); $this->assertFalse(validator(['hex_color' => 'rgb(0,0,255)'], $rule)->passes()); $this->assertTrue(validator(['hex_color' => '#000000'], $rule)->passes()); $this->assertFalse(validator(['hex_color' => '#0f0f'], $rule)->passes()); } } ================================================ FILE: tests/ISBNTest.php ================================================ [new ISBN]]; $this->assertFalse(validator(['book' => '1'], $rule)->passes()); $this->assertFalse(validator(['book' => '1#'], $rule)->passes()); $this->assertFalse(validator(['book' => 'a1#'], $rule)->passes()); $this->assertTrue(validator(['book' => 'ISBN 978-0-596-52068-7'], $rule)->passes()); $this->assertTrue(validator(['book' => 'ISBN-13: 978-0-596-52068-7'], $rule)->passes()); $this->assertTrue(validator(['book' => '978 0 596 52068 7'], $rule)->passes()); $this->assertTrue(validator(['book' => '9780596520687'], $rule)->passes()); $this->assertTrue(validator(['book' => 'ISBN-10 0-596-52068-9'], $rule)->passes()); $this->assertTrue(validator(['book' => '0-596-52068-9'], $rule)->passes()); } } ================================================ FILE: tests/LanguageCodeTest.php ================================================ [new LanguageCode(2)]]; $this->assertTrue(validator(['code' => 'EL'], $rule)->passes()); $this->assertTrue(validator(['code' => 'KL'], $rule)->passes()); $this->assertFalse(validator(['code' => 'xx'], $rule)->passes()); } /** @test */ public function the_three_letter_language_code_rule_can_be_validated() { $rule = ['code' => [new LanguageCode(3)]]; $this->assertTrue(validator(['code' => 'RUN'], $rule)->passes()); $this->assertTrue(validator(['code' => 'RUS'], $rule)->passes()); $this->assertFalse(validator(['code' => 'xxx'], $rule)->passes()); } } ================================================ FILE: tests/LocationCoordinatesTest.php ================================================ [new LocationCoordinates]]; $this->assertFalse(validator(['location' => '1'], $rule)->passes()); $this->assertTrue(validator(['location' => '1, 1'], $rule)->passes()); $this->assertTrue(validator(['location' => '1.0,1.0'], $rule)->passes()); $this->assertTrue(validator(['location' => '90.0,180.0'], $rule)->passes()); $this->assertFalse(validator(['location' => '90.0,181.0'], $rule)->passes()); $this->assertFalse(validator(['location' => '91.0,180.0'], $rule)->passes()); $this->assertTrue(validator(['location' => '-77.0364335, 38.8951555'], $rule)->passes()); $this->assertTrue(validator(['location' => '-77.03643357, 38.8951555'], $rule)->passes()); $this->assertTrue(validator(['location' => '-77.0364335, 38.89515557'], $rule)->passes()); $this->assertFalse(validator(['location' => '-77.036433576, 38.8951555'], $rule)->passes()); $this->assertFalse(validator(['location' => '-77.0364335, 38.895155576'], $rule)->passes()); } } ================================================ FILE: tests/LowercaseTest.php ================================================ [new Lowercase]]; $this->assertTrue(validator(['text' => 'hello'], $rule)->passes()); $this->assertFalse(validator(['text' => 'HELLO'], $rule)->passes()); } } ================================================ FILE: tests/MacAddress.php ================================================ [new MacAddress]]; $this->assertTrue(validator(['address' => '3D:F2:C9:A6:B3:4F'], $rule)->passes()); $this->assertTrue(validator(['address' => '3D-F2-C9-A6-B3-4F'], $rule)->passes()); $this->assertFalse(validator(['address' => '00:00:00:00:00:00:00'], $rule)->passes()); } } ================================================ FILE: tests/MaxWordsTest.php ================================================ [new MaxWords($data['max_words'])]]; $this->assertEquals($data['passes'], validator(['text' => $data['text']], $rule)->passes()); } /** * Retrieve the seed data for the test. * */ public function provideSentences() : array { return [ [ ['text' => 'hello world', 'max_words' => 2, 'passes' => true], ], [ ['text' => 'مرحبا بالعالم', 'max_words' => 2, 'passes' => true], ], [ ['text' => 'This sentence contains more than 2 words', 'max_words' => 2, 'passes' => false], ], [ ['text' => 'Three words sentence', 'max_words' => 3, 'passes' => true], ],[ ['text' => 'مرحبا بالعالم من التحقق', 'max_words' => 3, 'passes' => false], ], ]; } } ================================================ FILE: tests/MissingTest.php ================================================ set('auth.providers.users.driver', 'database'); $app['config']->set('auth.providers.users.table', 'users'); $app['config']->set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'foreign_key_constraints' => true, ]); } /** * Insert database records for testing purposes. * **/ protected function seedDatabase() : void { $this->loadMigrationsFrom(realpath(__DIR__ . '/..') . '/support/migrations'); $this->user = DB::table('users')->insertGetId([ 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => bcrypt('password'), ]); } /** @test */ public function the_does_not_exist_rule_can_be_validated() { $this->seedDatabase(); $rule = ['user_id' => [new Missing('users', 'id')]]; $this->assertTrue(validator(['user_id' => 'non_existent_user'], $rule)->passes()); $this->assertFalse(validator(['user_id' => $this->user], $rule)->passes()); } } ================================================ FILE: tests/MonetaryFigureTest.php ================================================ [new MonetaryFigure('$', 4, 4)]]; $this->assertFalse(validator(['deposit' => '$'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$123'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1234'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '$12345'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '$1234.'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1234.1'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1234.12'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1234.123'], $rule)->passes()); $this->assertTrue(validator(['deposit' => '$1234.1234'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '$1234.12345'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '$12345.1234'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '$abcd.efgh'], $rule)->passes()); $this->assertFalse(validator(['deposit' => '£1234.1234'], $rule)->passes()); } /** @test */ public function the_monetary_figure_rule_example_is_valid() { $rule = ['deposit' => [$class = new MonetaryFigure('$', 4, 2)]]; $this->assertTrue(validator(['deposit' => $class->example()], $rule)->passes()); } } ================================================ FILE: tests/OddNumberTest.php ================================================ [new OddNumber]]; $this->assertFalse(validator(['number' => '0'], $rule)->passes()); $this->assertTrue(validator(['number' => '1'], $rule)->passes()); $this->assertFalse(validator(['number' => '2'], $rule)->passes()); $this->assertTrue(validator(['number' => '3'], $rule)->passes()); } } ================================================ FILE: tests/RecordOwnerTest.php ================================================ set('auth.providers.users.driver', 'database'); $app['config']->set('auth.providers.users.table', 'users'); $app['config']->set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'foreign_key_constraints' => true, ]); } /** * Insert database records for testing purposes. * **/ protected function seedDatabase() : void { $this->loadMigrationsFrom(realpath(__DIR__ . '/..') . '/support/migrations'); $this->owner = DB::table('users')->insertGetId([ 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => bcrypt('password'), ]); $this->other = DB::table('users')->insertGetId([ 'name' => 'Jane Doe', 'email' => 'jane@example.com', 'password' => bcrypt('password'), ]); $this->post = DB::table('posts')->insertGetId([ 'title' => 'Post #1', 'user_id' => $this->owner, ]); } /** @test */ public function the_record_owner_rule_can_be_validated() { $this->seedDatabase(); $rule = ['post_id' => [new RecordOwner('posts', 'id')]]; $this->assertFalse(validator(['post_id' => $this->post], $rule)->passes()); Auth::loginUsingId($this->other); $this->assertFalse(validator(['post_id' => $this->post], $rule)->passes()); Auth::loginUsingId($this->owner); $this->assertTrue(validator(['post_id' => $this->post], $rule)->passes()); } } ================================================ FILE: tests/StrongPasswordTest.php ================================================ [new StrongPassword]]; $this->assertFalse(validator(['password' => '1'], $rule)->passes()); $this->assertFalse(validator(['password' => '1#'], $rule)->passes()); $this->assertFalse(validator(['password' => 'a1#'], $rule)->passes()); $this->assertFalse(validator(['password' => 'aB1#'], $rule)->passes()); $this->assertFalse(validator(['password' => 'Ertbyrt123#'], $rule)->passes()); $this->assertTrue(validator(['password' => 'Ertbyrt1234#'], $rule)->passes()); } } ================================================ FILE: tests/TelephoneNumberTest.php ================================================ [new TelephoneNumber]]; $this->assertFalse(validator(['phone' => '1'], $rule)->passes()); $this->assertFalse(validator(['phone' => '1#'], $rule)->passes()); $this->assertFalse(validator(['phone' => 'a1#'], $rule)->passes()); $this->assertFalse(validator(['phone' => 'aB1#'], $rule)->passes()); $this->assertFalse(validator(['phone' => '123456'], $rule)->passes()); $this->assertFalse(validator(['phone' => '1234567890123456'], $rule)->passes()); $this->assertTrue(validator(['phone' => '123456789'], $rule)->passes()); } } ================================================ FILE: tests/TitlecaseTest.php ================================================ [new Titlecase]]; $this->assertFalse(validator(['text' => 'hello world'], $rule)->passes()); $this->assertFalse(validator(['text' => 'Hello world'], $rule)->passes()); $this->assertFalse(validator(['text' => 'hello World'], $rule)->passes()); $this->assertTrue(validator(['text' => 'Hello World'], $rule)->passes()); $this->assertTrue(validator(['text' => 'HELLO WORLD'], $rule)->passes()); } } ================================================ FILE: tests/UppercaseTest.php ================================================ [new Uppercase]]; $this->assertFalse(validator(['text' => 'hello'], $rule)->passes()); $this->assertTrue(validator(['text' => 'HELLO'], $rule)->passes()); } } ================================================ FILE: tests/WithoutWhitespaceTest.php ================================================ [new WithoutWhitespace]]; $this->assertFalse(validator(['text' => 'hello '], $rule)->passes()); $this->assertFalse(validator(['text' => ' hello'], $rule)->passes()); $this->assertFalse(validator(['text' => 'hello world'], $rule)->passes()); $this->assertTrue(validator(['text' => 'hello'], $rule)->passes()); } }