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
================================================
<?php declare(strict_types = 1);
$finder = Symfony\Component\Finder\Finder::create()
->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
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
================================================
FILE: src/Rules/CitizenIdentification.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Axiom\Support\Iso3166Alpha2;
use Axiom\Support\Iso3166Alpha3;
class CitizenIdentification extends Rule
{
/**
* Determine if the validation rule passes.
*
* The rule requires one parameter:
* 1. The identification type to use ('USA' or 'US, 'GBR' or 'GB', 'FRA' or 'FR', 'BRA' or 'BR').
*
**/
public function passes($attribute, $value) : bool
{
$array = ($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Axiom\Support\Iso3166Alpha2;
use Axiom\Support\Iso3166Alpha3;
class CountryCode extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
$array = ($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class Decimal extends Rule
{
/**
* Generate an example value that satisifies the validation rule.
*
**/
public function example() : string
{
return mt_rand(1, (int) str_repeat('9', $this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Exception;
use Axiom\Types\Rule;
use Illuminate\Support\Str;
class DisposableEmail extends Rule
{
/**
* Determine if the validation rule passes.
*
* By default, if the API fails to load, the email will
* be accepted. However, you can override this by adding
* a boolean parameter e.g. new DisposableEmail(true).
*
**/
public function passes($attribute, $value) : bool
{
$url = 'https://open.kickbox.com/v1/disposable/' . Str::after($value, '@');
try {
return ! json_decode(file_get_contents($url), true)['disposable'];
} catch (Exception $ex) {
return ($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class Domain extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match('/^([\w-]+\.)*[\w\-]+\.\w{2,10}$/', $value) > 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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
class EncodedImage extends Rule
{
/**
* Pointer to the temporary file.
*
**/
protected $file;
/**
* Write the given data to a temporary file.
*
**/
protected function createTemporaryFile(string $data) : UploadedFile
{
$this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class EvenNumber extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return intval($value) % 2 === 0;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'even_number',
'The :attribute must be an even number'
);
}
}
================================================
FILE: src/Rules/FileExists.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Illuminate\Support\Facades\Storage;
class FileExists extends Rule
{
/**
* Determine if the validation rule passes.
*
* The rule has two parameters:
* 1. The disk defined in your config file.
* 2. The directory to search within.
*
**/
public function passes($attribute, $value) : bool
{
$path = rtrim($this->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
================================================
<?php
namespace Axiom\Rules;
use Axiom\Types\Rule;
class HexColor extends Rule
{
/**
* Hex color regex formats.
*
*/
private array $formats = [
4 => '/^#([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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class ISBN extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match(
'/^(?:ISBN(-1(?:(0)|3))?:?\ )?(?(1)(?(2)(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]|(?=[0-9]{13}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9])|(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X])$/',
$value
) > 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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Axiom\Support\Iso6391Alpha2;
use Axiom\Support\Iso6391Alpha3;
class LanguageCode extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
$array = ($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class LocationCoordinates extends Rule
{
/**
* Determine if the validation rule passes.
*
* The latitude and longitude may have a maximum of
* eight digits after the decimal point. This provides
* an accuracy of up to ~1 millimeter.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match(
'/^[-]?((([0-8]?[0-9])(\.(\d{1,8}))?)|(90(\.0+)?)),\s?[-]?((((1[0-7][0-9])|([0-9]?[0-9]))(\.(\d{1,8}))?)|180(\.0+)?)$/',
$value
) > 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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class Lowercase extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return mb_strtolower($value) === $value;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'lowercase',
'The :attribute must be entirely lowercase text'
);
}
}
================================================
FILE: src/Rules/MacAddress.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class MacAddress extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match('/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/', $value) > 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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class MaxWords extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return count(preg_split('~[^\p{L}\p{N}\']+~u', $value)) <= $this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Illuminate\Support\Facades\DB;
class Missing extends Rule
{
/**
* Determine if the validation rule passes.
*
* The rule requires two parameters:
* 1. The database table to use.
* 2. The column on the table to compare the value against.
*
**/
public function passes($attribute, $value) : bool
{
return DB::table($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class MonetaryFigure extends Rule
{
/**
* Generate an example value that satisifies the validation rule.
*
**/
public function example() : string
{
return $this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class OddNumber extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return intval($value) % 2 !== 0;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'odd_number',
'The :attribute must be an odd number'
);
}
}
================================================
FILE: src/Rules/RecordOwner.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
class RecordOwner extends Rule
{
/**
* Determine if the validation rule passes.
*
* The rule requires two parameters:
* 1. The database table to use.
* 2. The column on the table to compare the value against.
*
**/
public function passes($attribute, $value) : bool
{
return DB::table($this->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class StrongPassword extends Rule
{
/**
* Determine if the validation rule passes.
*
* The password must be 12 - 30 characters in length,
* and include a number, a symbol, an upper case letter,
* and a lower case letter.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match(
'/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@()$%^&*=_{}[\]:;"\'|\\<>,.\/~`±§+-]).{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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class TelephoneNumber extends Rule
{
/**
* Determine if the validation rule passes.
*
* The telephone number must be 7 - 15 characters in length,
* and comprised entirely of integers.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match('/^[0-9]{7,15}$/', $value) > 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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class Titlecase extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return ucwords($value) === $value;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'titlecase',
'Each word in :attribute must begin with a capital letter'
);
}
}
================================================
FILE: src/Rules/Uppercase.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class Uppercase extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return mb_strtoupper($value) === $value;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'uppercase',
'The :attribute must be entirely uppercase text'
);
}
}
================================================
FILE: src/Rules/WithoutWhitespace.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules;
use Axiom\Types\Rule;
class WithoutWhitespace extends Rule
{
/**
* Determine if the validation rule passes.
*
**/
public function passes($attribute, $value) : bool
{
return preg_match('/\s/', $value) === 0;
}
/**
* Get the validation error message.
*
**/
public function message() : string
{
return $this->getLocalizedErrorMessage(
'without_whitespace',
'The :attribute must be an unbroken string of text, it cannot include spaces'
);
}
}
================================================
FILE: src/Support/Iso3166Alpha2.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Support;
class Iso3166Alpha2
{
/**
* Array of countries with their ISO 3166-1 alpha-2 codes.
*
**/
public static array $codes = [
'AD' => '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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Support;
class Iso3166Alpha3
{
/**
* Array of countries with their ISO 3166-1 alpha-3 codes.
*
**/
public static array $codes = [
'ABW' => '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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Support;
class Iso6391Alpha2
{
/**
* Array of countries with their ISO 639-1 alpha-2 codes.
*
**/
public static array $codes = [
'AB' => '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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Support;
class Iso6391Alpha3
{
/**
* Array of countries with their ISO 639-1 alpha-3 codes.
*
**/
public static array $codes = [
'ABK' => '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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Types;
use Illuminate\Contracts\Validation\Rule as BaseRule;
abstract class Rule implements BaseRule
{
/**
* Array of supporting parameters.
*
**/
protected array $parameters;
/**
* Constructor.
*
**/
public function __construct()
{
$this->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
================================================
<?php declare(strict_types = 1);
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
**/
public function up() : void
{
Schema::create('users', function(Blueprint $table) {
$table->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
================================================
<?php declare(strict_types = 1);
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
**/
public function up() : void
{
Schema::create('posts', function (Blueprint $table) {
$table->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Orchestra\Testbench\TestCase;
use Axiom\Rules\CitizenIdentification;
class CitizenIdentificationTest extends TestCase
{
/** @test */
public function the_citizen_identification_rule_can_be_validated_for_usa()
{
$rule = ['id' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\CountryCode;
use Orchestra\Testbench\TestCase;
class CountryCodeTest extends TestCase
{
/** @test */
public function the_two_letter_country_code_rule_can_be_validated()
{
$rule = ['code' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Decimal;
use Orchestra\Testbench\TestCase;
class DecimalTest extends TestCase
{
/** @test */
public function the_decimal_rule_can_be_validated()
{
$rule = ['figure' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\DisposableEmail;
use Orchestra\Testbench\TestCase;
class DisposableEmailTest extends TestCase
{
/** @test */
public function the_disposable_email_rule_can_be_validated()
{
$rule = ['email' => ['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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Domain;
use Orchestra\Testbench\TestCase;
class DomainTest extends TestCase
{
/** @test */
public function the_domain_rule_can_be_validated()
{
$rule = ['domain' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\EncodedImage;
use Orchestra\Testbench\TestCase;
class EncodedImageTest extends TestCase
{
/**
* Retrieve the contents of a given file.
*
**/
protected function getFile(string $file_name) : string
{
$path = realpath(__DIR__ . '/..') . "/support/assets/$file_name";
$extension = pathinfo($path, PATHINFO_EXTENSION);
return "data:image/{$extension};base64," . base64_encode(file_get_contents($path));
}
/**
* Generate an invalid image file with a given mime type.
*
**/
protected function invalidImage(string $mime = '') : string
{
return "data:image/{$mime};base64," . base64_encode('not an image file');
}
/** @test */
public function the_encoded_jpeg_image_rule_can_be_validated()
{
$png_rule = ['image' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\EvenNumber;
use Orchestra\Testbench\TestCase;
class EvenNumberTest extends TestCase
{
/** @test */
public function the_even_number_rule_can_be_validated()
{
$rule = ['number' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\FileExists;
use Orchestra\Testbench\TestCase;
class FileExistsTest extends TestCase
{
/**
* Define the application environment.
*
**/
protected function getEnvironmentSetUp($app) : void
{
$app['config']->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
================================================
<?php
namespace Axiom\Rules\Tests;
use Axiom\Rules\HexColor;
use Orchestra\Testbench\TestCase;
class HexColorTest extends TestCase
{
/** @test */
public function it_can_validate_hex_color()
{
$rule = ['hex_color' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\ISBN;
use Orchestra\Testbench\TestCase;
class ISBNTest extends TestCase
{
/** @test */
public function the_isbn_rule_can_be_validated()
{
$rule = ['book' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\LanguageCode;
use Orchestra\Testbench\TestCase;
class LanguageCodeTest extends TestCase
{
/** @test */
public function the_two_letter_language_code_rule_can_be_validated()
{
$rule = ['code' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Orchestra\Testbench\TestCase;
use Axiom\Rules\LocationCoordinates;
class LocationCoordinatesTest extends TestCase
{
/** @test */
public function the_location_coordinates_rule_can_be_validated()
{
$rule = ['location' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Lowercase;
use Orchestra\Testbench\TestCase;
class LowercaseTest extends TestCase
{
/** @test */
public function the_lowercase_rule_can_be_validated()
{
$rule = ['text' => [new Lowercase]];
$this->assertTrue(validator(['text' => 'hello'], $rule)->passes());
$this->assertFalse(validator(['text' => 'HELLO'], $rule)->passes());
}
}
================================================
FILE: tests/MacAddress.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\MacAddress;
use Orchestra\Testbench\TestCase;
class MacAddressTest extends TestCase
{
/** @test */
public function the_mac_address_rule_can_be_validated()
{
$rule = ['address' => [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
================================================
<?php declare(strict_types=1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\MaxWords;
use Orchestra\Testbench\TestCase;
class MaxWordsTest extends TestCase
{
/**
* @test
* @dataProvider provideSentences
*/
public function the_max_words_rule_can_be_validated($data)
{
$rule = ['text' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Missing;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\DB;
class MissingTest extends TestCase
{
/**
* The user id.
*
**/
protected int $user;
/**
* Define the application environment.
*
**/
protected function getEnvironmentSetUp($app) : void
{
$app['config']->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\MonetaryFigure;
use Orchestra\Testbench\TestCase;
class MonetaryFigureTest extends TestCase
{
/** @test */
public function the_monetary_figure_rule_can_be_validated()
{
$rule = ['deposit' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\OddNumber;
use Orchestra\Testbench\TestCase;
class OddNumberTest extends TestCase
{
/** @test */
public function the_odd_number_rule_can_be_validated()
{
$rule = ['number' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\RecordOwner;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
class RecordOwnerTest extends TestCase
{
/**
* The other user id.
*
**/
protected int $other;
/**
* The owner user id.
*
**/
protected int $owner;
/**
* The post id.
*
**/
protected int $post;
/**
* Define the application environment.
*
**/
protected function getEnvironmentSetUp($app) : void
{
$app['config']->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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\StrongPassword;
use Orchestra\Testbench\TestCase;
class StrongPasswordTest extends TestCase
{
/** @test */
public function the_strong_password_rule_can_be_validated()
{
$rule = ['password' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\TelephoneNumber;
use Orchestra\Testbench\TestCase;
class TelephoneNumberTest extends TestCase
{
/** @test */
public function the_telephone_number_rule_can_be_validated()
{
$rule = ['phone' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Titlecase;
use Orchestra\Testbench\TestCase;
class TitlecaseTest extends TestCase
{
/** @test */
public function the_titlecase_rule_can_be_validated()
{
$rule = ['text' => [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
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Axiom\Rules\Uppercase;
use Orchestra\Testbench\TestCase;
class UppercaseTest extends TestCase
{
/** @test */
public function the_uppercase_rule_can_be_validated()
{
$rule = ['text' => [new Uppercase]];
$this->assertFalse(validator(['text' => 'hello'], $rule)->passes());
$this->assertTrue(validator(['text' => 'HELLO'], $rule)->passes());
}
}
================================================
FILE: tests/WithoutWhitespaceTest.php
================================================
<?php declare(strict_types = 1);
namespace Axiom\Rules\Tests;
use Orchestra\Testbench\TestCase;
use Axiom\Rules\WithoutWhitespace;
class WithoutWhitespaceTest extends TestCase
{
/** @test */
public function the_without_whitespace_rule_can_be_validated()
{
$rule = ['text' => [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());
}
}
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
SYMBOL INDEX (157 symbols across 55 files)
FILE: src/Rules/CitizenIdentification.php
class CitizenIdentification (line 9) | class CitizenIdentification extends Rule
method passes (line 18) | public function passes($attribute, $value) : bool
method message (line 52) | public function message() : string
method verifyFrance (line 64) | protected function verifyFrance($value) : bool
method verifyUnitedKingdom (line 73) | protected function verifyUnitedKingdom($value) : bool
method verifyUnitedStates (line 82) | protected function verifyUnitedStates($value) : bool
method verifyBrazil (line 91) | protected function verifyBrazil($value) : bool
method verifyVietnam (line 118) | protected function verifyVietnam($value) : bool
FILE: src/Rules/CountryCode.php
class CountryCode (line 9) | class CountryCode extends Rule
method passes (line 15) | public function passes($attribute, $value) : bool
method message (line 26) | public function message() : string
FILE: src/Rules/Decimal.php
class Decimal (line 7) | class Decimal extends Rule
method example (line 13) | public function example() : string
method passes (line 27) | public function passes($attribute, $value) : bool
method message (line 39) | public function message() : string
FILE: src/Rules/DisposableEmail.php
class DisposableEmail (line 9) | class DisposableEmail extends Rule
method passes (line 19) | public function passes($attribute, $value) : bool
method message (line 34) | public function message() : string
FILE: src/Rules/Domain.php
class Domain (line 7) | class Domain extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/EncodedImage.php
class EncodedImage (line 9) | class EncodedImage extends Rule
method createTemporaryFile (line 21) | protected function createTemporaryFile(string $data) : UploadedFile
method passes (line 45) | public function passes($attribute, $value) : bool
method message (line 72) | public function message() : string
FILE: src/Rules/EvenNumber.php
class EvenNumber (line 7) | class EvenNumber extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/FileExists.php
class FileExists (line 8) | class FileExists extends Rule
method passes (line 18) | public function passes($attribute, $value) : bool
method message (line 30) | public function message() : string
FILE: src/Rules/HexColor.php
class HexColor (line 7) | class HexColor extends Rule
method passes (line 26) | public function passes($attribute, $value)
method message (line 42) | public function message()
FILE: src/Rules/ISBN.php
class ISBN (line 7) | class ISBN extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 25) | public function message() : string
FILE: src/Rules/LanguageCode.php
class LanguageCode (line 9) | class LanguageCode extends Rule
method passes (line 15) | public function passes($attribute, $value) : bool
method message (line 26) | public function message() : string
FILE: src/Rules/LocationCoordinates.php
class LocationCoordinates (line 7) | class LocationCoordinates extends Rule
method passes (line 17) | public function passes($attribute, $value) : bool
method message (line 29) | public function message() : string
FILE: src/Rules/Lowercase.php
class Lowercase (line 7) | class Lowercase extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/MacAddress.php
class MacAddress (line 7) | class MacAddress extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/MaxWords.php
class MaxWords (line 7) | class MaxWords extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/Missing.php
class Missing (line 8) | class Missing extends Rule
method passes (line 18) | public function passes($attribute, $value) : bool
method message (line 29) | public function message() : string
FILE: src/Rules/MonetaryFigure.php
class MonetaryFigure (line 7) | class MonetaryFigure extends Rule
method example (line 13) | public function example() : string
method passes (line 29) | public function passes($attribute, $value) : bool
method message (line 41) | public function message() : string
FILE: src/Rules/OddNumber.php
class OddNumber (line 7) | class OddNumber extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/RecordOwner.php
class RecordOwner (line 9) | class RecordOwner extends Rule
method passes (line 19) | public function passes($attribute, $value) : bool
method message (line 31) | public function message() : string
FILE: src/Rules/StrongPassword.php
class StrongPassword (line 7) | class StrongPassword extends Rule
method passes (line 17) | public function passes($attribute, $value) : bool
method message (line 29) | public function message() : string
FILE: src/Rules/TelephoneNumber.php
class TelephoneNumber (line 7) | class TelephoneNumber extends Rule
method passes (line 16) | public function passes($attribute, $value) : bool
method message (line 25) | public function message() : string
FILE: src/Rules/Titlecase.php
class Titlecase (line 7) | class Titlecase extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/Uppercase.php
class Uppercase (line 7) | class Uppercase extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Rules/WithoutWhitespace.php
class WithoutWhitespace (line 7) | class WithoutWhitespace extends Rule
method passes (line 13) | public function passes($attribute, $value) : bool
method message (line 22) | public function message() : string
FILE: src/Support/Iso3166Alpha2.php
class Iso3166Alpha2 (line 5) | class Iso3166Alpha2
FILE: src/Support/Iso3166Alpha3.php
class Iso3166Alpha3 (line 5) | class Iso3166Alpha3
FILE: src/Support/Iso6391Alpha2.php
class Iso6391Alpha2 (line 5) | class Iso6391Alpha2
FILE: src/Support/Iso6391Alpha3.php
class Iso6391Alpha3 (line 5) | class Iso6391Alpha3
FILE: src/Types/Rule.php
class Rule (line 7) | abstract class Rule implements BaseRule
method __construct (line 19) | public function __construct()
method getLocalizedErrorMessage (line 29) | public function getLocalizedErrorMessage(string $key, string $default)...
FILE: support/migrations/2014_10_12_000000_create_users_table.php
class CreateUsersTable (line 7) | class CreateUsersTable extends Migration
method up (line 14) | public function up() : void
method down (line 32) | public function down() : void
FILE: support/migrations/2015_10_12_000001_create_posts_table.php
class CreatePostsTable (line 7) | class CreatePostsTable extends Migration
method up (line 14) | public function up() : void
method down (line 30) | public function down() : void
FILE: tests/CitizenIdentificationTest.php
class CitizenIdentificationTest (line 8) | class CitizenIdentificationTest extends TestCase
method the_citizen_identification_rule_can_be_validated_for_usa (line 11) | public function the_citizen_identification_rule_can_be_validated_for_u...
method the_citizen_identification_rule_can_be_validated_for_gbr (line 29) | public function the_citizen_identification_rule_can_be_validated_for_g...
method the_citizen_identification_rule_can_be_validated_for_fra (line 47) | public function the_citizen_identification_rule_can_be_validated_for_f...
method the_citizen_identification_rule_can_be_validated_for_bra (line 63) | public function the_citizen_identification_rule_can_be_validated_for_b...
method the_citizen_identification_rule_can_be_validated_for_vn (line 81) | public function the_citizen_identification_rule_can_be_validated_for_vn()
FILE: tests/CountryCodeTest.php
class CountryCodeTest (line 8) | class CountryCodeTest extends TestCase
method the_two_letter_country_code_rule_can_be_validated (line 11) | public function the_two_letter_country_code_rule_can_be_validated()
method the_three_letter_country_code_rule_can_be_validated (line 22) | public function the_three_letter_country_code_rule_can_be_validated()
FILE: tests/DecimalTest.php
class DecimalTest (line 8) | class DecimalTest extends TestCase
method the_decimal_rule_can_be_validated (line 11) | public function the_decimal_rule_can_be_validated()
method the_decimal_rule_example_is_valid (line 27) | public function the_decimal_rule_example_is_valid()
FILE: tests/DisposableEmailTest.php
class DisposableEmailTest (line 8) | class DisposableEmailTest extends TestCase
method the_disposable_email_rule_can_be_validated (line 11) | public function the_disposable_email_rule_can_be_validated()
FILE: tests/DomainTest.php
class DomainTest (line 8) | class DomainTest extends TestCase
method the_domain_rule_can_be_validated (line 11) | public function the_domain_rule_can_be_validated()
FILE: tests/EncodedImageTest.php
class EncodedImageTest (line 8) | class EncodedImageTest extends TestCase
method getFile (line 14) | protected function getFile(string $file_name) : string
method invalidImage (line 27) | protected function invalidImage(string $mime = '') : string
method the_encoded_jpeg_image_rule_can_be_validated (line 33) | public function the_encoded_jpeg_image_rule_can_be_validated()
FILE: tests/EvenNumber.php
class EvenNumberTest (line 8) | class EvenNumberTest extends TestCase
method the_even_number_rule_can_be_validated (line 11) | public function the_even_number_rule_can_be_validated()
FILE: tests/FileExistsTest.php
class FileExistsTest (line 8) | class FileExistsTest extends TestCase
method getEnvironmentSetUp (line 14) | protected function getEnvironmentSetUp($app) : void
method the_file_exists_rule_can_be_validated (line 23) | public function the_file_exists_rule_can_be_validated()
FILE: tests/HexColorTest.php
class HexColorTest (line 8) | class HexColorTest extends TestCase
method it_can_validate_hex_color (line 11) | public function it_can_validate_hex_color()
FILE: tests/ISBNTest.php
class ISBNTest (line 8) | class ISBNTest extends TestCase
method the_isbn_rule_can_be_validated (line 11) | public function the_isbn_rule_can_be_validated()
FILE: tests/LanguageCodeTest.php
class LanguageCodeTest (line 8) | class LanguageCodeTest extends TestCase
method the_two_letter_language_code_rule_can_be_validated (line 11) | public function the_two_letter_language_code_rule_can_be_validated()
method the_three_letter_language_code_rule_can_be_validated (line 21) | public function the_three_letter_language_code_rule_can_be_validated()
FILE: tests/LocationCoordinatesTest.php
class LocationCoordinatesTest (line 8) | class LocationCoordinatesTest extends TestCase
method the_location_coordinates_rule_can_be_validated (line 11) | public function the_location_coordinates_rule_can_be_validated()
FILE: tests/LowercaseTest.php
class LowercaseTest (line 8) | class LowercaseTest extends TestCase
method the_lowercase_rule_can_be_validated (line 11) | public function the_lowercase_rule_can_be_validated()
FILE: tests/MacAddress.php
class MacAddressTest (line 8) | class MacAddressTest extends TestCase
method the_mac_address_rule_can_be_validated (line 11) | public function the_mac_address_rule_can_be_validated()
FILE: tests/MaxWordsTest.php
class MaxWordsTest (line 8) | class MaxWordsTest extends TestCase
method the_max_words_rule_can_be_validated (line 14) | public function the_max_words_rule_can_be_validated($data)
method provideSentences (line 24) | public function provideSentences() : array
FILE: tests/MissingTest.php
class MissingTest (line 9) | class MissingTest extends TestCase
method getEnvironmentSetUp (line 21) | protected function getEnvironmentSetUp($app) : void
method seedDatabase (line 39) | protected function seedDatabase() : void
method the_does_not_exist_rule_can_be_validated (line 51) | public function the_does_not_exist_rule_can_be_validated()
FILE: tests/MonetaryFigureTest.php
class MonetaryFigureTest (line 8) | class MonetaryFigureTest extends TestCase
method the_monetary_figure_rule_can_be_validated (line 11) | public function the_monetary_figure_rule_can_be_validated()
method the_monetary_figure_rule_example_is_valid (line 32) | public function the_monetary_figure_rule_example_is_valid()
FILE: tests/OddNumberTest.php
class OddNumberTest (line 8) | class OddNumberTest extends TestCase
method the_odd_number_rule_can_be_validated (line 11) | public function the_odd_number_rule_can_be_validated()
FILE: tests/RecordOwnerTest.php
class RecordOwnerTest (line 10) | class RecordOwnerTest extends TestCase
method getEnvironmentSetUp (line 34) | protected function getEnvironmentSetUp($app) : void
method seedDatabase (line 52) | protected function seedDatabase() : void
method the_record_owner_rule_can_be_validated (line 75) | public function the_record_owner_rule_can_be_validated()
FILE: tests/StrongPasswordTest.php
class StrongPasswordTest (line 8) | class StrongPasswordTest extends TestCase
method the_strong_password_rule_can_be_validated (line 11) | public function the_strong_password_rule_can_be_validated()
FILE: tests/TelephoneNumberTest.php
class TelephoneNumberTest (line 8) | class TelephoneNumberTest extends TestCase
method the_telephone_number_rule_can_be_validated (line 11) | public function the_telephone_number_rule_can_be_validated()
FILE: tests/TitlecaseTest.php
class TitlecaseTest (line 8) | class TitlecaseTest extends TestCase
method the_titlecase_rule_can_be_validated (line 11) | public function the_titlecase_rule_can_be_validated()
FILE: tests/UppercaseTest.php
class UppercaseTest (line 8) | class UppercaseTest extends TestCase
method the_uppercase_rule_can_be_validated (line 11) | public function the_uppercase_rule_can_be_validated()
FILE: tests/WithoutWhitespaceTest.php
class WithoutWhitespaceTest (line 8) | class WithoutWhitespaceTest extends TestCase
method the_without_whitespace_rule_can_be_validated (line 11) | public function the_without_whitespace_rule_can_be_validated()
Condensed preview — 65 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (108K chars).
[
{
"path": ".github/.php-cs-fixer.php",
"chars": 2054,
"preview": "<?php declare(strict_types = 1);\n\n$finder = Symfony\\Component\\Finder\\Finder::create()\n ->notPath(dirname(__DIR__, 1) "
},
{
"path": ".github/workflows/style.yml",
"chars": 737,
"preview": "name: styling\n\non: [push]\n\njobs:\n style:\n runs-on: ubuntu-latest\n\n steps:\n - name: Checkout code\n use"
},
{
"path": ".github/workflows/tests.yml",
"chars": 1379,
"preview": "name: tests\n\non: [push, pull_request]\n\njobs:\n phpunit:\n runs-on: ${{ matrix.os }}\n strategy:\n fail-fast: tru"
},
{
"path": ".gitignore",
"chars": 88,
"preview": "build\ncomposer.lock\nvendor\n.DS_Store\ncoverage\n.phpunit.result.cache\n.idea\n.php_cs.cache\n"
},
{
"path": ".php-cs-fixer.cache",
"chars": 5080,
"preview": "{\"php\":\"8.1.12\",\"version\":\"3.13.0\",\"indent\":\" \",\"lineEnding\":\"\\n\",\"rules\":{\"blank_line_after_namespace\":true,\"braces\""
},
{
"path": "LICENSE.md",
"chars": 1084,
"preview": "The MIT License (MIT)\n\nCopyright © Caneara and contributors\n\nPermission is hereby granted, free of charge, to any person"
},
{
"path": "README.md",
"chars": 6618,
"preview": "# Axiom\n\nThis package provides a library of reusable validation rules for your Laravel projects. Use them to augment the"
},
{
"path": "composer.json",
"chars": 764,
"preview": "{\n \"name\": \"caneara/axiom\",\n \"description\": \"A package that provides a library of reusable Laravel validation rule"
},
{
"path": "phpunit.xml",
"chars": 672,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" bootstrap=\"vendor/"
},
{
"path": "src/Rules/CitizenIdentification.php",
"chars": 3716,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Axiom\\Support\\Iso3166Alpha2;\nuse Axi"
},
{
"path": "src/Rules/CountryCode.php",
"chars": 797,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Axiom\\Support\\Iso3166Alpha2;\nuse Axi"
},
{
"path": "src/Rules/Decimal.php",
"chars": 1162,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass Decimal extends Rule\n{\n /**\n "
},
{
"path": "src/Rules/DisposableEmail.php",
"chars": 1053,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Exception;\nuse Axiom\\Types\\Rule;\nuse Illuminate\\Support\\St"
},
{
"path": "src/Rules/Domain.php",
"chars": 631,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass Domain extends Rule\n{\n /**\n "
},
{
"path": "src/Rules/EncodedImage.php",
"chars": 2141,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Illuminate\\Support\\Str;\nuse Illumina"
},
{
"path": "src/Rules/EvenNumber.php",
"chars": 549,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass EvenNumber extends Rule\n{\n /**"
},
{
"path": "src/Rules/FileExists.php",
"chars": 860,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Illuminate\\Support\\Facades\\Storage;\n"
},
{
"path": "src/Rules/HexColor.php",
"chars": 994,
"preview": "<?php\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass HexColor extends Rule\n{\n /**\n * Hex color regex forma"
},
{
"path": "src/Rules/ISBN.php",
"chars": 990,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass ISBN extends Rule\n{\n /**\n "
},
{
"path": "src/Rules/LanguageCode.php",
"chars": 799,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Axiom\\Support\\Iso6391Alpha2;\nuse Axi"
},
{
"path": "src/Rules/LocationCoordinates.php",
"chars": 968,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass LocationCoordinates extends Rule\n"
},
{
"path": "src/Rules/Lowercase.php",
"chars": 563,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass Lowercase extends Rule\n{\n /**\n"
},
{
"path": "src/Rules/MacAddress.php",
"chars": 599,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass MacAddress extends Rule\n{\n /**"
},
{
"path": "src/Rules/MaxWords.php",
"chars": 628,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass MaxWords extends Rule\n{\n /**\n "
},
{
"path": "src/Rules/Missing.php",
"chars": 803,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Illuminate\\Support\\Facades\\DB;\n\nclas"
},
{
"path": "src/Rules/MonetaryFigure.php",
"chars": 1300,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass MonetaryFigure extends Rule\n{\n "
},
{
"path": "src/Rules/OddNumber.php",
"chars": 546,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass OddNumber extends Rule\n{\n /**\n"
},
{
"path": "src/Rules/RecordOwner.php",
"chars": 915,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\nuse Illuminate\\Support\\Facades\\DB;\nuse I"
},
{
"path": "src/Rules/StrongPassword.php",
"chars": 913,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass StrongPassword extends Rule\n{\n "
},
{
"path": "src/Rules/TelephoneNumber.php",
"chars": 727,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass TelephoneNumber extends Rule\n{\n "
},
{
"path": "src/Rules/Titlecase.php",
"chars": 567,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass Titlecase extends Rule\n{\n /**\n"
},
{
"path": "src/Rules/Uppercase.php",
"chars": 563,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass Uppercase extends Rule\n{\n /**\n"
},
{
"path": "src/Rules/WithoutWhitespace.php",
"chars": 609,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules;\n\nuse Axiom\\Types\\Rule;\n\nclass WithoutWhitespace extends Rule\n{\n"
},
{
"path": "src/Support/Iso3166Alpha2.php",
"chars": 8081,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Support;\n\nclass Iso3166Alpha2\n{\n /**\n * Array of countries with"
},
{
"path": "src/Support/Iso3166Alpha3.php",
"chars": 8286,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Support;\n\nclass Iso3166Alpha3\n{\n /**\n * Array of countries with"
},
{
"path": "src/Support/Iso6391Alpha2.php",
"chars": 5612,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Support;\n\nclass Iso6391Alpha2\n{\n /**\n * Array of countries with"
},
{
"path": "src/Support/Iso6391Alpha3.php",
"chars": 5967,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Support;\n\nclass Iso6391Alpha3\n{\n /**\n * Array of countries with"
},
{
"path": "src/Types/Rule.php",
"chars": 715,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Types;\n\nuse Illuminate\\Contracts\\Validation\\Rule as BaseRule;\n\nabstrac"
},
{
"path": "support/migrations/2014_10_12_000000_create_users_table.php",
"chars": 754,
"preview": "<?php declare(strict_types = 1);\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse I"
},
{
"path": "support/migrations/2015_10_12_000001_create_posts_table.php",
"chars": 683,
"preview": "<?php declare(strict_types = 1);\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse I"
},
{
"path": "tests/CitizenIdentificationTest.php",
"chars": 4431,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Orchestra\\Testbench\\TestCase;\nuse Axiom\\Rules\\Citize"
},
{
"path": "tests/CountryCodeTest.php",
"chars": 1068,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\CountryCode;\nuse Orchestra\\Testbench\\Tes"
},
{
"path": "tests/DecimalTest.php",
"chars": 1244,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Decimal;\nuse Orchestra\\Testbench\\TestCas"
},
{
"path": "tests/DisposableEmailTest.php",
"chars": 531,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\DisposableEmail;\nuse Orchestra\\Testbench"
},
{
"path": "tests/DomainTest.php",
"chars": 1513,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Domain;\nuse Orchestra\\Testbench\\TestCase"
},
{
"path": "tests/EncodedImageTest.php",
"chars": 2134,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\EncodedImage;\nuse Orchestra\\Testbench\\Te"
},
{
"path": "tests/EvenNumber.php",
"chars": 605,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\EvenNumber;\nuse Orchestra\\Testbench\\Test"
},
{
"path": "tests/FileExistsTest.php",
"chars": 950,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\FileExists;\nuse Orchestra\\Testbench\\Test"
},
{
"path": "tests/HexColorTest.php",
"chars": 938,
"preview": "<?php\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\HexColor;\nuse Orchestra\\Testbench\\TestCase;\n\nclass HexColorTest ext"
},
{
"path": "tests/ISBNTest.php",
"chars": 1040,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\ISBN;\nuse Orchestra\\Testbench\\TestCase;\n"
},
{
"path": "tests/LanguageCodeTest.php",
"chars": 927,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\LanguageCode;\nuse Orchestra\\Testbench\\Te"
},
{
"path": "tests/LocationCoordinatesTest.php",
"chars": 1338,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Orchestra\\Testbench\\TestCase;\nuse Axiom\\Rules\\Locati"
},
{
"path": "tests/LowercaseTest.php",
"chars": 453,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Lowercase;\nuse Orchestra\\Testbench\\TestC"
},
{
"path": "tests/MacAddress.php",
"chars": 585,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\MacAddress;\nuse Orchestra\\Testbench\\Test"
},
{
"path": "tests/MaxWordsTest.php",
"chars": 1170,
"preview": "<?php declare(strict_types=1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\MaxWords;\nuse Orchestra\\Testbench\\TestCase"
},
{
"path": "tests/MissingTest.php",
"chars": 1654,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Missing;\nuse Orchestra\\Testbench\\TestCas"
},
{
"path": "tests/MonetaryFigureTest.php",
"chars": 1735,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\MonetaryFigure;\nuse Orchestra\\Testbench\\"
},
{
"path": "tests/OddNumberTest.php",
"chars": 601,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\OddNumber;\nuse Orchestra\\Testbench\\TestC"
},
{
"path": "tests/RecordOwnerTest.php",
"chars": 2362,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\RecordOwner;\nuse Orchestra\\Testbench\\Tes"
},
{
"path": "tests/StrongPasswordTest.php",
"chars": 813,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\StrongPassword;\nuse Orchestra\\Testbench\\"
},
{
"path": "tests/TelephoneNumberTest.php",
"chars": 877,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\TelephoneNumber;\nuse Orchestra\\Testbench"
},
{
"path": "tests/TitlecaseTest.php",
"chars": 713,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Titlecase;\nuse Orchestra\\Testbench\\TestC"
},
{
"path": "tests/UppercaseTest.php",
"chars": 453,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Axiom\\Rules\\Uppercase;\nuse Orchestra\\Testbench\\TestC"
},
{
"path": "tests/WithoutWhitespaceTest.php",
"chars": 650,
"preview": "<?php declare(strict_types = 1);\n\nnamespace Axiom\\Rules\\Tests;\n\nuse Orchestra\\Testbench\\TestCase;\nuse Axiom\\Rules\\Withou"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the mattkingshott/axiom GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 65 files (98.4 KB), approximately 29.8k tokens, and a symbol index with 157 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.