Server IP : 213.176.29.180  /  Your IP : 3.146.107.49
Web Server : Apache
System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
User : webtaragh ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /proc/29/../self/cwd/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //proc/29/../self/cwd/respect.tar
stringifier/src/stringify.php000064400000001113147361033760012415 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier;

use Respect\Stringifier\Stringifiers\ClusterStringifier;

function stringify($value): string
{
    static $stringifier;

    if (null === $stringifier) {
        $stringifier = ClusterStringifier::createDefault();
    }

    return $stringifier->stringify($value, 0) ?? '#ERROR#';
}
stringifier/src/Stringifier.php000064400000001230147361033760012664 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier;

interface Stringifier
{
    /**
     * Converts the value into string if possible.
     *
     * @param mixed $raw The raw value to be converted.
     * @param int $depth The current depth of the conversion.
     *
     * @return null|string Returns NULL when the conversion is not possible.
     */
    public function stringify($raw, int $depth): ?string;
}
stringifier/src/Stringifiers/ClusterStringifier.php000064400000005613147361033760016707 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use Respect\Stringifier\Quoters\CodeQuoter;
use Respect\Stringifier\Quoters\StringQuoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts a value into a string using the defined Stringifiers.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ClusterStringifier implements Stringifier
{
    /**
     * @var Stringifier[]
     */
    private $stringifiers;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier[] ...$stringifiers
     */
    public function __construct(Stringifier ...$stringifiers)
    {
        $this->setStringifiers($stringifiers);
    }

    /**
     * Create a default instance of the class.
     *
     * This instance includes all possible stringifiers.
     *
     * @return ClusterStringifier
     */
    public static function createDefault(): self
    {
        $quoter = new CodeQuoter();

        $stringifier = new self();
        $stringifier->setStringifiers([
            new TraversableStringifier($stringifier, $quoter),
            new DateTimeStringifier($stringifier, $quoter, 'c'),
            new ThrowableStringifier($stringifier, $quoter),
            new StringableObjectStringifier($stringifier),
            new JsonSerializableStringifier($stringifier, $quoter),
            new ObjectStringifier($stringifier, $quoter),
            new ArrayStringifier($stringifier, $quoter, 3, 5),
            new InfiniteStringifier($quoter),
            new NanStringifier($quoter),
            new ResourceStringifier($quoter),
            new BoolStringifier($quoter),
            new NullStringifier($quoter),
            new JsonParsableStringifier(),
        ]);

        return $stringifier;
    }

    /**
     * Set stringifiers.
     *
     * @param array $stringifiers
     *
     * @return void
     */
    public function setStringifiers(array $stringifiers): void
    {
        $this->stringifiers = [];

        foreach ($stringifiers as $stringifier) {
            $this->addStringifier($stringifier);
        }
    }

    /**
     * Add a stringifier to the chain
     *
     * @param Stringifier $stringifier
     *
     * @return void
     */
    public function addStringifier(Stringifier $stringifier): void
    {
        $this->stringifiers[] = $stringifier;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($value, int $depth): ?string
    {
        foreach ($this->stringifiers as $stringifier) {
            $string = $stringifier->stringify($value, $depth);
            if (null === $string) {
                continue;
            }

            return $string;
        }

        return null;
    }
}
stringifier/src/Stringifiers/StringableObjectStringifier.php000064400000002320147361033760020477 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function is_object;
use function method_exists;
use Respect\Stringifier\Stringifier;

/**
 * Converts a object that implements the __toString() magic method into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StringableObjectStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     */
    public function __construct(Stringifier $stringifier)
    {
        $this->stringifier = $stringifier;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_object($raw)) {
            return null;
        }

        if (!method_exists($raw, '__toString')) {
            return null;
        }

        return $this->stringifier->stringify($raw->__toString(), $depth);
    }
}
stringifier/src/Stringifiers/TraversableStringifier.php000064400000002734147361033760017541 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function get_class;
use function iterator_to_array;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;
use Traversable;

/**
 * Converts an instance of Traversable into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class TraversableStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!$raw instanceof Traversable) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[traversable] (%s: %s)',
                get_class($raw),
                $this->stringifier->stringify(iterator_to_array($raw), $depth + 1)
            ),
            $depth
        );
    }
}
stringifier/src/Stringifiers/ObjectStringifier.php000064400000002716147361033760016475 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function get_class;
use function get_object_vars;
use function is_object;
use function sprintf;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts an object into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ObjectStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_object($raw)) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[object] (%s: %s)',
                get_class($raw),
                $this->stringifier->stringify(get_object_vars($raw), $depth + 1)
            ),
            $depth
        );
    }
}
stringifier/src/Stringifiers/DateTimeStringifier.php000064400000003152147361033760016756 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use DateTimeInterface;
use function get_class;
use function sprintf;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts an instance of DateTimeInterface into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DateTimeStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * @var string
     */
    private $format;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     * @param string $format
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter, string $format)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
        $this->format = $format;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!$raw instanceof DateTimeInterface) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[date-time] (%s: %s)',
                get_class($raw),
                $this->stringifier->stringify($raw->format($this->format), $depth + 1)
            ),
            $depth
        );
    }
}
stringifier/src/Stringifiers/NullStringifier.php000064400000001760147361033760016177 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts a NULL value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NullStringifier implements Stringifier
{
    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Quoter $quoter
     */
    public function __construct(Quoter $quoter)
    {
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (null !== $raw) {
            return null;
        }

        return $this->quoter->quote('NULL', $depth);
    }
}
stringifier/src/Stringifiers/ArrayStringifier.php000064400000005134147361033760016342 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function array_keys;
use function implode;
use function is_array;
use function is_int;
use function sprintf;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts an array value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ArrayStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * @var int
     */
    private $maximumDepth;

    /**
     * @var int
     */
    private $itemsLimit;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     * @param int $maximumDepth
     * @param int $itemsLimit
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter, int $maximumDepth, int $itemsLimit)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
        $this->maximumDepth = $maximumDepth;
        $this->itemsLimit = $itemsLimit;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_array($raw)) {
            return null;
        }

        if (empty($raw)) {
            return $this->quoter->quote('{ }', $depth);
        }

        if ($depth >= $this->maximumDepth) {
            return '...';
        }

        $items = [];
        $itemsCount = 0;
        $isSequential = $this->isSequential($raw);
        foreach ($raw as $key => $value) {
            if (++$itemsCount > $this->itemsLimit) {
                $items[$itemsCount] = '...';
                break;
            }

            $items[$itemsCount] = '';
            if (false === $isSequential) {
                $items[$itemsCount] .= sprintf('%s: ', $this->stringifier->stringify($key, $depth + 1));
            }
            $items[$itemsCount] .= $this->stringifier->stringify($value, $depth + 1);
        }

        return $this->quoter->quote(sprintf('{ %s }', implode(', ', $items)), $depth);
    }

    /**
     * Returns whether the array is sequential or not.
     *
     * @param array $array
     *
     * @return bool
     */
    private function isSequential(array $array): bool
    {
        return array_keys($array) === range(0, count($array) - 1);
    }
}
stringifier/src/Stringifiers/JsonSerializableStringifier.php000064400000002674147361033760020532 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;
use JsonSerializable;

/**
 * Converts an instance of JsonSerializable into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class JsonSerializableStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!$raw instanceof JsonSerializable) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[json-serializable] (%s: %s)',
                get_class($raw),
                $this->stringifier->stringify($raw->jsonSerialize(), $depth + 1)
            ),
            $depth
        );
    }
}
stringifier/src/Stringifiers/NanStringifier.php000064400000002134147361033760015775 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function is_float;
use function is_nan;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts a NaN value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NanStringifier implements Stringifier
{
    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Quoter $quoter
     */
    public function __construct(Quoter $quoter)
    {
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_float($raw)) {
            return null;
        }

        if (!is_nan($raw)) {
            return null;
        }

        return $this->quoter->quote('NaN', $depth);
    }
}
stringifier/src/Stringifiers/BoolStringifier.php000064400000002033147361033760016152 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function is_bool;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts a boolean value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class BoolStringifier implements Stringifier
{
    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Quoter $quoter
     */
    public function __construct(Quoter $quoter)
    {
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_bool($raw)) {
            return null;
        }

        return $this->quoter->quote($raw ? 'TRUE' : 'FALSE', $depth);
    }
}
stringifier/src/Stringifiers/ResourceStringifier.php000064400000002312147361033760017046 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function get_resource_type;
use function is_resource;
use function sprintf;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts a resource value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ResourceStringifier implements Stringifier
{
    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Quoter $quoter
     */
    public function __construct(Quoter $quoter)
    {
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_resource($raw)) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[resource] (%s)',
                get_resource_type($raw)
            ),
            $depth
        );
    }
}
stringifier/src/Stringifiers/ThrowableStringifier.php000064400000003552147361033760017215 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function get_class;
use function getcwd;
use function sprintf;
use function str_replace;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;
use Throwable;

/**
 * Converts an instance of Throwable into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ThrowableStringifier implements Stringifier
{
    /**
     * @var Stringifier
     */
    private $stringifier;

    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Stringifier $stringifier
     * @param Quoter $quoter
     */
    public function __construct(Stringifier $stringifier, Quoter $quoter)
    {
        $this->stringifier = $stringifier;
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!$raw instanceof Throwable) {
            return null;
        }

        return $this->quoter->quote(
            sprintf(
                '[throwable] (%s: %s)',
                get_class($raw),
                $this->stringifier->stringify($this->getData($raw), $depth + 1)
            ),
            $depth
        );
    }

    private function getData(Throwable $throwable): array
    {
        return [
            'message' => $throwable->getMessage(),
            'code' => $throwable->getCode(),
            'file' => sprintf(
                '%s:%d',
                str_replace(getcwd().'/', '', $throwable->getFile()),
                $throwable->getLine()
            ),
        ];
    }
}
stringifier/src/Stringifiers/JsonParsableStringifier.php000064400000001674147361033760017654 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use const JSON_UNESCAPED_UNICODE;
use const JSON_UNESCAPED_SLASHES;
use function json_encode;
use Respect\Stringifier\Stringifier;

/**
 * Converts any value into JSON parsable string representation.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class JsonParsableStringifier implements Stringifier
{
    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        $string = json_encode($raw, (JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION));
        if (false === $string) {
            return null;
        }

        return $string;
    }
}
stringifier/src/Stringifiers/InfiniteStringifier.php000064400000002215147361033760017026 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Stringifiers;

use function is_float;
use function is_infinite;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Stringifier;

/**
 * Converts an infinite float value into a string.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class InfiniteStringifier implements Stringifier
{
    /**
     * @var Quoter
     */
    private $quoter;

    /**
     * Initializes the stringifier.
     *
     * @param Quoter $quoter
     */
    public function __construct(Quoter $quoter)
    {
        $this->quoter = $quoter;
    }

    /**
     * {@inheritdoc}
     */
    public function stringify($raw, int $depth): ?string
    {
        if (!is_float($raw)) {
            return null;
        }

        if (!is_infinite($raw)) {
            return null;
        }

        return $this->quoter->quote(($raw > 0 ? '' : '-').'INF', $depth);
    }
}
stringifier/src/Quoters/CodeQuoter.php000064400000001332147361033760014116 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier\Quoters;

use Respect\Stringifier\Quoter;

/**
 * Add "`" quotes around a string depending on its level.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class CodeQuoter implements Quoter
{
    /**
     * {@inheritdoc}
     */
    public function quote(string $string, int $depth): string
    {
        if (0 === $depth) {
            return sprintf('`%s`', $string);
        }

        return $string;
    }
}
stringifier/src/Quoter.php000064400000001112147361033760011655 0ustar00<?php

/*
 * This file is part of Respect/Stringifier.
 *
 * (c) Henrique Moody <henriquemoody@gmail.com>
 *
 * For the full copyright and license information, please view the "LICENSE.md"
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Stringifier;

interface Quoter
{
    /**
     * Should add quotes to the given string.
     *
     * @param string $string The string to add quotes to
     * @param int $depth The current depth
     *
     * @return string
     */
    public function quote(string $string, int $depth): string;
}
stringifier/README.md000064400000003432147361033760010364 0ustar00# Respect\Stringifier

[![Build Status](https://img.shields.io/travis/Respect/Stringifier/master.svg?style=flat-square)](http://travis-ci.org/Respect/Stringifier)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Respect/Stringifier/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Respect/Stringifier/?branch=master)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Respect/Stringifier/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Respect/Stringifier/?branch=master)
[![Latest Stable Version](https://img.shields.io/packagist/v/respect/stringifier.svg?style=flat-square)](https://packagist.org/packages/respect/stringifier)
[![Total Downloads](https://img.shields.io/packagist/dt/respect/stringifier.svg?style=flat-square)](https://packagist.org/packages/respect/stringifier)
[![License](https://img.shields.io/packagist/l/respect/stringifier.svg?style=flat-square)](https://packagist.org/packages/respect/stringifier)

Converts any PHP value into a string.

## Installation

Package is available on [Packagist](https://packagist.org/packages/respect/stringifier), you can install it
using [Composer](http://getcomposer.org).

```bash
composer require respect/stringifier
```

This library requires PHP >= 7.1.

## Feature Guide

Below a quick guide of how to use the library.

### Namespace import

Respect\Stringifier is namespaced, and you can make your life easier by importing
a single function into your context:

```php
use function Respect\Stringifier\stringify;
```

Stringifier was built using objects, the `stringify()` is a easy way to use it.

### Usage

Simply use the function to convert any value you want to:

```php
echo stringify($value);
```

To see more examples of how to use the library check the [integration tests](tests/integration).
stringifier/LICENSE.md000064400000002114147361033760010505 0ustar00# License

Copyright (c) [Henrique Moody](http://github.com/henriquemoody).

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.
validation/CONTRIBUTING.md000064400000016370147361033760011150 0ustar00# Contributing

Contributions to Respect\Validation are always welcome. You make our lives
easier by sending us your contributions through [pull requests][].

Pull requests for bug fixes must be based on the oldest stable version's branch
whereas pull requests for new features must be based on the `master` branch.

Due to time constraints, we are not always able to respond as quickly as we
would like. Please do not take delays personal and feel free to remind us here,
on IRC, or on Gitter if you feel that we forgot to respond.

Please see the [project documentation][] before proceeding. You should also know
about [PHP-FIG][]'s standards and basic unit testing, but we're sure you can
learn that just by looking at other rules. Pick the simple ones like `ArrayType`
to begin.

Before writing anything, feature or bug fix:
- Check if there is already an issue related to it (opened or closed) and if
  someone is already working on that;
    - If there is not, [open an issue][] and notify everybody that you're going
      to work on that;
    - If there is, create a comment to notify everybody that you're going to
      work on that.
- Make sure that what you need is not done yet

## Adding a new validator

A common validator (rule) on Respect\Validation is composed of three classes:

  * `library/Rules/YourRuleName.php`: the rule itself
  * `library/Exceptions/YourRuleNameException.php`: the exception thrown by the rule
  * `tests/unit/Rules/YourRuleNameTest.php`: tests for the rule

The classes are pretty straightforward. In the sample below, we're going to
create a validator that validates if a string is equal to "Hello World".

- Classes should be `final` unless they are used in a different scope;
- Properties should be `private` unless they are used in a different scope;
- Classes should use strict typing;
- Some docblocks are required.

### Creating the rule

The rule itself needs to implement the `Validatable` interface but, it is
convenient to just extend the `AbstractRule` class.
Doing that, you'll only need to declare one method: `validate($input)`.
This method must return `true` or `false`.

If your validator class is `HelloWorld`, it will be available as `v::helloWorld()`
and will natively have support for chaining and everything else.

```php
<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Explain in one sentence what this rule does.
 *
 * @author Your Name <youremail@yourdomain.tld>
 */
final class HelloWorld extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $input === 'Hello World';
    }
}
```

### Creating the rule exception

Just that and we're done with the rule code. The Exception requires you to
declare messages used by `assert()` and `check()`. Messages are declared in
affirmative and negative moods, so if anyone calls `v::not(v::helloWorld())` the
library will show the appropriate message.

```php
<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Your Name <youremail@yourdomain.tld>
 */
final class HelloWorldException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a Hello World',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a Hello World',
        ]
    ];
}
```

### Creating unit tests

Finally, we need to test if everything is running smooth. We have `RuleTestCase`
that allows us to make easier to test rules, but you fell free to use the
`PHPUnit\Framework\TestCase` if you want or you need it's necessary.

The `RuleTestCase` extends PHPUnit's `PHPUnit\Framework\TestCase` class, so you
are able to use any methods of it. By extending `RuleTestCase` you should
implement two methods that should return a [data provider][] with the rule as
first item of the arrays:

- `providerForValidInput`: Will test when `validate()` should return `true`
- `providerForInvalidInput`: Will test when `validate()` should return `false`

```php
<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Test\RuleTestCase;

/**
 * @group rule
 *
 * @covers \Respect\Validation\Rules\HelloWorld
 *
 * @author Your Name <youremail@yourdomain.tld>
 */
final class HelloWorldTest extends RuleTestCase
{
    /**
     * {@inheritDoc}
     */
    public function providerForValidInput(): array
    {
        $rule = new HelloWorld();

        return [
            [$rule, 'Hello World'],
        ];
    }

    /**
     * {@inheritDoc}
     */
    public function providerForInvalidInput(): array
    {
        $rule = new HelloWorld();

        return [
            [$rule, 'Not a hello'],
            [$rule, 'Hello darkness, my old friend'],
            [$rule, 'Hello is it me you\'re looking for?'],
        ];
    }
}
```

If the constructor of your rule accepts arguments you may create specific tests
for it other than what is covered by `RuleTestCase`.

### Helping us a little bit more

You rule will be accepted only with these 3 files (rule, exception and unit test),
but if you really want to help us, you can follow the example of [ArrayType][] by:

- Adding your new rule on the `Validator`'s class docblock;
- Writing a documentation for your new rule;
- Creating integration tests with PHPT.

As we already said, none of them are required but you will help us a lot.

## Documentation

Our docs at https://respect-validation.readthedocs.io are generated from our
Markdown files. Add your brand new rule and it should be soon available.

## Running Tests

After run `composer install` on the library's root directory you must run PHPUnit.

### Linux

You can test the project using the commands:
```sh
$ vendor/bin/phpunit
```

or

```sh
$ composer phpunit
```

### Windows

You can test the project using the commands:
```sh
> vendor\bin\phpunit
```

or

```sh
> composer phpunit
```

No test should fail.

You can tweak the PHPUnit's settings by copying `phpunit.xml.dist` to `phpunit.xml`
and changing it according to your needs.

[ArrayType]: https://github.com/Respect/Validation/commit/f08a1fa
[data provider]: https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers "PHPUnit Data Providers"
[open an issue]: http://github.com/Respect/Validation/issues
[PHP-FIG]: http://www.php-fig.org "PHP Framework Interop Group"
[project documentation]: https://respect-validation.readthedocs.io/ "Respect\Validation documentation"
[pull requests]: http://help.github.com/pull-requests "GitHub pull requests"
validation/README.md000064400000001772147361033760010176 0ustar00# Respect\Validation

[![Build Status](https://img.shields.io/github/workflow/status/Respect/Validation/Continuous%20Integration/master?style=flat-square)](https://github.com/Respect/Validation/actions?query=workflow%3A%22Continuous+Integration%22)
[![Code Coverage](https://img.shields.io/codecov/c/github/Respect/Validation?style=flat-square)](https://codecov.io/gh/Respect/Validation)
[![Latest Stable Version](https://img.shields.io/packagist/v/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)
[![Total Downloads](https://img.shields.io/packagist/dt/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)
[![License](https://img.shields.io/packagist/l/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)

[The most awesome validation engine ever created for PHP.](http://bit.ly/1a1oeQv)

* [Documentation](https://respect-validation.readthedocs.io)
* [How to contribute](CONTRIBUTING.md)
validation/data/iso_3166-2/AX.json000064400000000175147361033760012437 0ustar00{
  "source": "http://www.geonames.org/AX/administrative-division-aland.html",
  "country": "Åland",
  "subdivisions": []
}
validation/data/iso_3166-2/BA.json000064400000001172147361033760012407 0ustar00{
  "source": "http://www.geonames.org/BA/administrative-division-bosnia-and-herzegovina.html",
  "country": "Bosnia and Herzegovina",
  "subdivisions": {
    "01": "Unsko-sanski kanton",
    "02": "Posavski kanton",
    "03": "Tuzlanski kanton",
    "04": "Zeničko-dobojski kanton",
    "05": "Bosansko-podrinjski kanton",
    "06": "Srednjobosanski kantonn",
    "07": "Hercegovačko-neretvanski kanton",
    "08": "Zapadnohercegovački kanton",
    "09": "Kanton Sarajevo",
    "10": "Kanton br. 10 (Livanjski kanton)",
    "BIH": "Federacija Bosna i Hercegovina",
    "BRC": "Brcko District",
    "SRP": "Republika Srpska"
  }
}
validation/data/iso_3166-2/BH.json000064400000000331147361033760012412 0ustar00{
  "source": "http://www.geonames.org/BH/administrative-division-bahrain.html",
  "country": "Bahrain",
  "subdivisions": {
    "13": "Capital",
    "14": "Southern",
    "15": "Muharraq",
    "17": "Northern"
  }
}
validation/data/iso_3166-2/EH.json000064400000000216147361033760012417 0ustar00{
  "source": "http://www.geonames.org/EH/administrative-division-western-sahara.html",
  "country": "Western Sahara",
  "subdivisions": []
}
validation/data/iso_3166-2/RS.json000064400000002034147361033760012447 0ustar00{
  "source": "http://www.geonames.org/RS/administrative-division-serbia.html",
  "country": "Serbia",
  "subdivisions": {
    "00": "Beograd",
    "01": "Severnobački okrug",
    "02": "Srednjebanatski okrug",
    "03": "Severnobanatski okrug",
    "04": "Južnobanatski okrug",
    "05": "Zapadno-Bački Okrug",
    "06": "Južnobački okrug",
    "07": "Srem",
    "08": "Mačvanski okrug",
    "09": "Kolubarski okrug",
    "10": "Podunavski okrug",
    "11": "Braničevski okrug",
    "12": "Šumadija",
    "13": "Pomoravski okrug",
    "14": "Borski okrug",
    "15": "Zaječarski okrug",
    "16": "Zlatibor",
    "17": "Moravički okrug",
    "18": "Raški okrug",
    "19": "Rasinski okrug",
    "20": "Nišavski okrug",
    "21": "Toplica",
    "22": "Pirotski okrug",
    "23": "Jablanički okrug",
    "24": "Pčinjski okrug",
    "25": "Kosovski okrug",
    "26": "Pećki okrug",
    "27": "Prizrenski okrug",
    "28": "Kosovsko-Mitrovački okrug",
    "29": "Kosovsko-Pomoravski okrug",
    "KM": "Kosovo",
    "VO": "Vojvodina"
  }
}
validation/data/iso_3166-2/MT.json000064400000003033147361033760012443 0ustar00{
  "source": "http://www.geonames.org/MT/administrative-division-malta.html",
  "country": "Malta",
  "subdivisions": {
    "01": "Attard",
    "02": "Balzan",
    "03": "Birgu",
    "04": "Birkirkara",
    "05": "Birzebbuga",
    "06": "Bormla",
    "07": "Dingli",
    "08": "Fgura",
    "09": "Floriana",
    "10": "Fontana",
    "11": "Gudja",
    "12": "Gzira",
    "13": "Ghajnsielem",
    "14": "Gharb",
    "15": "Gargur",
    "16": "Ghasri",
    "17": "Gaxaq",
    "18": "Hamrun",
    "19": "Iklin",
    "20": "Isla",
    "21": "Kalkara",
    "22": "Kercem",
    "23": "Kirkop",
    "24": "Lija",
    "25": "Luqa",
    "26": "Marsa",
    "27": "Marsaskala",
    "28": "Marsaxlokk",
    "29": "Mdina",
    "30": "Melliea",
    "31": "Mgarr",
    "32": "Mosta",
    "33": "Mqabba",
    "34": "Msida",
    "35": "Mtarfa",
    "36": "Munxar",
    "37": "Nadur",
    "38": "Naxxar",
    "39": "Paola",
    "40": "Pembroke",
    "41": "Pieta",
    "42": "Qala",
    "43": "Qormi",
    "44": "Qrendi",
    "45": "Rabat Għawdex",
    "46": "Rabat Malta",
    "47": "Safi",
    "48": "San Giljan",
    "49": "San Gwann",
    "50": "San Lawrenz",
    "51": "San Pawl il-Bahar",
    "52": "Sannat",
    "53": "Santa Lucija",
    "54": "Santa Venera",
    "55": "Siggiewi",
    "56": "Sliema",
    "57": "Swieqi",
    "58": "Tarxien",
    "59": "Ta Xbiex",
    "60": "Valletta",
    "61": "Xagra",
    "62": "Xewkija",
    "63": "Xgajra",
    "64": "Zabbar",
    "65": "Żebbuġ Għawdex",
    "66": "Żebbuġ Malta",
    "67": "Zejtun",
    "68": "Zurrieq"
  }
}
validation/data/iso_3166-2/JM.json000064400000001072147361033760012432 0ustar00{
  "source": "http://www.geonames.org/JM/administrative-division-jamaica.html",
  "country": "Jamaica",
  "subdivisions": {
    "01": "Kingston Parish",
    "02": "Saint Andrew Parish",
    "03": "Saint Thomas Parish",
    "04": "Portland Parish",
    "05": "Saint Mary Parish",
    "06": "Saint Ann Parish",
    "07": "Trelawny Parish",
    "08": "Saint James Parish",
    "09": "Hanover Parish",
    "10": "Westmoreland Parish",
    "11": "Saint Elizabeth Parish",
    "12": "Manchester Parish",
    "13": "Clarendon Parish",
    "14": "Saint Catherine Parish"
  }
}
validation/data/iso_3166-2/PS.json000064400000002120147361033760012441 0ustar00{
  "source": "http://www.geonames.org/PS/administrative-division-palestine.html",
  "country": "Palestine",
  "subdivisions": {
    "BTH": "Bethlehem [conventional] / Bayt Laḩm [Arabic]",
    "DEB": "Deir El Balah [conventional] /Dayr al Balaḩ[Arabic]",
    "GZA": "Gaza [conventional] / Ghazzah[Arabic]",
    "HBN": "Hebron [conventional] / Al Khalīl [Arabic]",
    "JEM": "Jerusalem [conventional] / Al Quds [Arabic]",
    "JEN": "Jenin [conventional] / Janīn [Arabic]",
    "JRH": "Jericho [conventional] / Arīḩā wal Aghwār [Arabic]",
    "KYS": "Khan Yunis [conventional] / Khān Yūnis[Arabic]",
    "NBS": "Nablus [conventional] / Nāblus [Arabic]",
    "NGZ": "North Gaza [conventional] / Shamāl Ghazzah[Arabic]",
    "QQA": "Qalqiyah [conventional] / Qalqīlyah [Arabic]",
    "RBH": "Ramallah and Al Birah [conventional] / Rām Allāh wal Bīrah [Arabic]",
    "RFH": "Rafah [conventional] / Rafaḩ[Arabic]",
    "SLT": "Salfit [conventional] / Salfīt [Arabic]",
    "TBS": "Tubas [conventional] / Ţūbās [Arabic]",
    "TKM": "Tulkarm [conventional] /Ţūlkarm [Arabic]"
  }
}
validation/data/iso_3166-2/KH.json000064400000001363147361033760012431 0ustar00{
  "source": "http://www.geonames.org/KH/administrative-division-cambodia.html",
  "country": "Cambodia",
  "subdivisions": {
    "1": "Banteay Mean Choay",
    "10": "Kratie",
    "11": "Mondul Kiri",
    "12": "Phnom Penh",
    "13": "Preah Vihear",
    "14": "Prey Veng",
    "15": "Pursat",
    "16": "Rôtânôkiri",
    "17": "Siemreap",
    "18": "Preah Seihanu (Kompong Som or Sihanoukville)",
    "19": "Stung Treng",
    "2": "Battambang",
    "20": "Svay Rieng",
    "21": "Takeo",
    "22": "Otdar Mean Choay",
    "23": "Keb",
    "24": "Pailin",
    "25": "Tboung Khmum",
    "3": "Kampong Cham",
    "4": "Kampong Chhnang",
    "5": "Kampong Speu",
    "6": "Kampong Thom",
    "7": "Kampot",
    "8": "Kandal",
    "9": "Kaoh Kong"
  }
}
validation/data/iso_3166-2/SG.json000064400000000405147361033760012434 0ustar00{
  "source": "http://www.geonames.org/SG/administrative-division-singapore.html",
  "country": "Singapore",
  "subdivisions": {
    "01": "Central Singapore",
    "02": "North East",
    "03": "North West",
    "04": "South East",
    "05": "South West"
  }
}
validation/data/iso_3166-2/MZ.json000064400000000552147361033760012454 0ustar00{
  "source": "http://www.geonames.org/MZ/administrative-division-mozambique.html",
  "country": "Mozambique",
  "subdivisions": {
    "A": "Niassa",
    "B": "Manica",
    "G": "Gaza",
    "I": "Inhambane",
    "L": "Maputo",
    "MPM": "Maputo (city)",
    "N": "Nampula",
    "P": "Cabo Delgado",
    "Q": "Zambezia",
    "S": "Sofala",
    "T": "Tete"
  }
}
validation/data/iso_3166-2/ZW.json000064400000000635147361033760012470 0ustar00{
  "source": "http://www.geonames.org/ZW/administrative-division-zimbabwe.html",
  "country": "Zimbabwe",
  "subdivisions": {
    "BU": "Bulawayo (city)",
    "HA": "Harare (city)",
    "MA": "Manicaland",
    "MC": "Mashonaland Central",
    "ME": "Mashonaland East",
    "MI": "Midlands",
    "MN": "Matabeleland North",
    "MS": "Matabeleland South",
    "MV": "Masvingo",
    "MW": "Mashonaland West"
  }
}
validation/data/iso_3166-2/CG.json000064400000000642147361033760012417 0ustar00{
  "source": "http://www.geonames.org/CG/administrative-division-republic-of-the-congo.html",
  "country": "Republic of the Congo",
  "subdivisions": {
    "11": "Bouenza",
    "12": "Pool",
    "13": "Sangha",
    "14": "Plateaux",
    "15": "Cuvette-Ouest",
    "16": "Pointe-Noire",
    "2": "Lekoumou",
    "5": "Kouilou",
    "7": "Likouala",
    "8": "Cuvette",
    "9": "Niari",
    "BZV": "Brazzaville"
  }
}
validation/data/iso_3166-2/BR.json000064400000001370147361033760012430 0ustar00{
  "source": "http://www.geonames.org/BR/administrative-division-brazil.html",
  "country": "Brazil",
  "subdivisions": {
    "AC": "Acre",
    "AL": "Alagoas",
    "AM": "Amazonas",
    "AP": "Amapa",
    "BA": "Bahia",
    "CE": "Ceara",
    "DF": "Distrito Federal",
    "ES": "Espirito Santo",
    "GO": "Goias",
    "MA": "Maranhao",
    "MG": "Minas Gerais",
    "MS": "Mato Grosso do Sul",
    "MT": "Mato Grosso",
    "PA": "Para",
    "PB": "Paraiba",
    "PE": "Pernambuco",
    "PI": "Piaui",
    "PR": "Parana",
    "RJ": "Rio de Janeiro",
    "RN": "Rio Grande do Norte",
    "RO": "Rondonia",
    "RR": "Roraima",
    "RS": "Rio Grande do Sul",
    "SC": "Santa Catarina",
    "SE": "Sergipe",
    "SP": "Sao Paulo",
    "TO": "Tocantins"
  }
}
validation/data/iso_3166-2/RO.json000064400000001745147361033760012453 0ustar00{
  "source": "http://www.geonames.org/RO/administrative-division-romania.html",
  "country": "Romania",
  "subdivisions": {
    "AB": "Alba",
    "AG": "Arges",
    "AR": "Arad",
    "B": "Bucuresti",
    "BC": "Bacau",
    "BH": "Bihor",
    "BN": "Bistrita-Nasaud",
    "BR": "Braila",
    "BT": "Botosani",
    "BV": "Brasov",
    "BZ": "Buzau",
    "CJ": "Cluj",
    "CL": "Calarasi",
    "CS": "Caras-Severin",
    "CT": "Constanta",
    "CV": "Covasna",
    "DB": "Dimbovita",
    "DJ": "Dolj",
    "GJ": "Gorj",
    "GL": "Galati",
    "GR": "Giurgiu",
    "HD": "Hunedoara",
    "HR": "Harghita",
    "IF": "Ilfov",
    "IL": "Ialomita",
    "IS": "Iasi",
    "MH": "Mehedinti",
    "MM": "Maramures",
    "MS": "Mures",
    "NT": "Neamt",
    "OT": "Olt",
    "PH": "Prahova",
    "SB": "Sibiu",
    "SJ": "Salaj",
    "SM": "Satu Mare",
    "SV": "Suceava",
    "TL": "Tulcea",
    "TM": "Timis",
    "TR": "Teleorman",
    "VL": "Vilcea",
    "VN": "Vrancea",
    "VS": "Vaslui"
  }
}
validation/data/iso_3166-2/KY.json000064400000000216147361033760012446 0ustar00{
  "source": "http://www.geonames.org/KY/administrative-division-cayman-islands.html",
  "country": "Cayman Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/AI.json000064400000000202147361033760012407 0ustar00{
  "source": "http://www.geonames.org/AI/administrative-division-anguilla.html",
  "country": "Anguilla",
  "subdivisions": []
}
validation/data/iso_3166-2/BI.json000064400000001006147361033760012413 0ustar00{
  "source": "http://www.geonames.org/BI/administrative-division-burundi.html",
  "country": "Burundi",
  "subdivisions": {
    "BB": "Bubanza",
    "BL": "Bujumbura Rural",
    "BM": "Bujumbura Mairie",
    "BR": "Bururi",
    "CA": "Cankuzo",
    "CI": "Cibitoke",
    "GI": "Gitega",
    "KI": "Kirundo",
    "KR": "Karuzi",
    "KY": "Kayanza",
    "MA": "Makamba",
    "MU": "Muramvya",
    "MW": "Mwaro",
    "MY": "Muyinga",
    "NG": "Ngozi",
    "RM": "Rumonge",
    "RT": "Rutana",
    "RY": "Ruyigi"
  }
}
validation/data/iso_3166-2/SO.json000064400000001024147361033760012442 0ustar00{
  "source": "http://www.geonames.org/SO/administrative-division-somalia.html",
  "country": "Somalia",
  "subdivisions": {
    "AW": "Awdal",
    "BK": "Bakool",
    "BN": "Banaadir",
    "BR": "Bari",
    "BY": "Bay",
    "GA": "Galguduud",
    "GE": "Gedo",
    "HI": "Hiiraan",
    "JD": "Jubbada Dhexe",
    "JH": "Jubbada Hoose",
    "MU": "Mudug",
    "NU": "Nugaal",
    "SA": "Sanaag",
    "SD": "Shabeellaha Dhexe",
    "SH": "Shabeellaha Hoose",
    "SO": "Sool",
    "TO": "Togdheer",
    "WO": "Woqooyi Galbeed"
  }
}
validation/data/iso_3166-2/GI.json000064400000000204147361033760012417 0ustar00{
  "source": "http://www.geonames.org/GI/administrative-division-gibraltar.html",
  "country": "Gibraltar",
  "subdivisions": []
}
validation/data/iso_3166-2/NI.json000064400000001051147361033760012427 0ustar00{
  "source": "http://www.geonames.org/NI/administrative-division-nicaragua.html",
  "country": "Nicaragua",
  "subdivisions": {
    "AN": "Region Autonoma del Atlantico Norte",
    "AS": "Region Autonoma del Atlantico Sur",
    "BO": "Boaco",
    "CA": "Carazo",
    "CI": "Chinandega",
    "CO": "Chontales",
    "ES": "Esteli",
    "GR": "Granada",
    "JI": "Jinotega",
    "LE": "Leon",
    "MD": "Madriz",
    "MN": "Managua",
    "MS": "Masaya",
    "MT": "Matagalpa",
    "NS": "Nueva Segovia",
    "RI": "Rivas",
    "SJ": "Rio San Juan"
  }
}
validation/data/iso_3166-2/GE.json000064400000000704147361033760012420 0ustar00{
  "source": "http://www.geonames.org/GE/administrative-division-georgia.html",
  "country": "Georgia",
  "subdivisions": {
    "AB": "Abkhazia",
    "AJ": "Ajaria",
    "GU": "Guria",
    "IM": "Imereti",
    "KA": "Kakheti",
    "KK": "Kvemo Kartli",
    "MM": "Mtskheta-Mtianeti",
    "RL": "Racha Lechkhumi and Kvemo Svaneti",
    "SJ": "Samtskhe-Javakheti",
    "SK": "Shida Kartli",
    "SZ": "Samegrelo-Zemo Svaneti",
    "TB": "Tbilisi"
  }
}
validation/data/iso_3166-2/LS.json000064400000000534147361033760012444 0ustar00{
  "source": "http://www.geonames.org/LS/administrative-division-lesotho.html",
  "country": "Lesotho",
  "subdivisions": {
    "A": "Maseru",
    "B": "Butha-Buthe",
    "C": "Leribe",
    "D": "Berea",
    "E": "Mafeteng",
    "F": "Mohale's Hoek",
    "G": "Quthing",
    "H": "Qacha's Nek",
    "J": "Mokhotlong",
    "K": "Thaba-Tseka"
  }
}
validation/data/iso_3166-2/UZ.json000064400000000732147361033760012464 0ustar00{
  "source": "http://www.geonames.org/UZ/administrative-division-uzbekistan.html",
  "country": "Uzbekistan",
  "subdivisions": {
    "AN": "Andijon",
    "BU": "Buxoro",
    "FA": "Farg'ona",
    "JI": "Jizzax",
    "NG": "Namangan",
    "NW": "Navoiy",
    "QA": "Qashqadaryo",
    "QR": "Qoraqalpog'iston Republikasi",
    "SA": "Samarqand",
    "SI": "Sirdaryo",
    "SU": "Surxondaryo",
    "TK": "Toshkent city",
    "TO": "Toshkent region",
    "XO": "Xorazm"
  }
}
validation/data/iso_3166-2/FJ.json000064400000001244147361033760012424 0ustar00{
  "source": "http://www.geonames.org/FJ/administrative-division-fiji.html",
  "country": "Fiji",
  "subdivisions": {
    "01": "Ba Province",
    "02": "Bua Province",
    "03": "Cakaudrove Province",
    "04": "Kadavu Province",
    "05": "Lau Province",
    "06": "Lomaiviti Province",
    "07": "Mathuata Province",
    "08": "Nandronga and Navosa Province",
    "09": "Naitasiri Province",
    "10": "Namosi Province",
    "11": "Ra Province",
    "12": "Rewa Province",
    "13": "Serua Province",
    "14": "Tailevu Province",
    "C": "Central Division",
    "E": "Eastern Division",
    "N": "Northern Division",
    "R": "Rotuma",
    "W": "Western Division"
  }
}
validation/data/iso_3166-2/VC.json000064400000000513147361033760012433 0ustar00{
  "source": "http://www.geonames.org/VC/administrative-division-saint-vincent-and-the-grenadines.html",
  "country": "Saint Vincent and the Grenadines",
  "subdivisions": {
    "01": "Charlotte",
    "02": "Saint Andrew",
    "03": "Saint David",
    "04": "Saint George",
    "05": "Saint Patrick",
    "06": "Grenadines"
  }
}
validation/data/iso_3166-2/TD.json000064400000001242147361033760012432 0ustar00{
  "source": "http://www.geonames.org/TD/administrative-division-chad.html",
  "country": "Chad",
  "subdivisions": {
    "BA": "Batha",
    "BG": "Barh el Ghazel",
    "BO": "Borkou",
    "CB": "Chari-Baguirmi",
    "EE": "Ennedi Est",
    "EO": "Ennedi Quest",
    "GR": "Guéra",
    "HL": "Hadjer-Lamis",
    "KA": "Kanem",
    "LC": "Lac",
    "LO": "Logone Occidental",
    "LR": "Logone Oriental",
    "MA": "Mandoul",
    "MC": "Moyen-Chari",
    "ME": "Mayo-Kebbi Est",
    "MO": "Mayo-Kebbi Ouest",
    "ND": "Ville de N'Djamena",
    "OD": "Ouaddaï",
    "SA": "Salamat",
    "SI": "Sila",
    "TA": "Tandjile",
    "TI": "Tibesti",
    "WF": "Wadi Fira"
  }
}
validation/data/iso_3166-2/GL.json000064400000000370147361033760012426 0ustar00{
  "source": "http://www.geonames.org/GL/administrative-division-greenland.html",
  "country": "Greenland",
  "subdivisions": {
    "AV": "Avannaata",
    "KU": "Kujalleq",
    "QE": "Qeqqata",
    "QT": "Qeqertalik",
    "SM": "Sermersooq"
  }
}
validation/data/iso_3166-2/BL.json000064400000000223147361033760012416 0ustar00{
  "source": "http://www.geonames.org/BL/administrative-division-saint-barthelemy.html",
  "country": "Saint Barthélemy",
  "subdivisions": []
}
validation/data/iso_3166-2/KE.json000064400000002141147361033760012421 0ustar00{
  "source": "http://www.geonames.org/KE/administrative-division-kenya.html",
  "country": "Kenya",
  "subdivisions": {
    "01": "Baringo",
    "02": "Bomet",
    "03": "Bungoma",
    "04": "Busia",
    "05": "Elgeyo/Marakwet",
    "06": "Embu",
    "07": "Garissa",
    "08": "Homa Bay",
    "09": "Isiolo",
    "10": "Kajiado",
    "11": "Kakamega",
    "12": "Kericho",
    "13": "Kiambu",
    "14": "Kilifi",
    "15": "Kirinyaga",
    "16": "Kisii",
    "17": "Kisumu",
    "18": "Kitui",
    "19": "Kwale",
    "20": "Laikipia",
    "21": "Lamu",
    "22": "Machakos",
    "23": "Makueni",
    "24": "Mandera",
    "25": "Marsabit",
    "26": "Meru",
    "27": "Migori",
    "28": "Mombasa",
    "29": "Murang’a",
    "30": "Nairobi",
    "31": "Nakuru",
    "32": "Nandi",
    "33": "Narok",
    "34": "Nyamira",
    "35": "Nyandarua",
    "36": "Nyeri",
    "37": "Samburu",
    "38": "Siaya",
    "39": "Taita/Taveta",
    "40": "Tana River",
    "41": "Tharak-Nithi",
    "42": "Trans Nzoia",
    "43": "Turkana",
    "44": "Uasin Gishu",
    "45": "Vihiga",
    "46": "Wajir",
    "47": "West Pokot"
  }
}
validation/data/iso_3166-2/NC.json000064400000000310147361033760012416 0ustar00{
  "source": "http://www.geonames.org/NC/administrative-division-new-caledonia.html",
  "country": "New Caledonia",
  "subdivisions": {
    "L": "Iles Loyaute",
    "N": "Nord",
    "S": "Sud"
  }
}
validation/data/iso_3166-2/LR.json000064400000000716147361033760012445 0ustar00{
  "source": "http://www.geonames.org/LR/administrative-division-liberia.html",
  "country": "Liberia",
  "subdivisions": {
    "BG": "Bong",
    "BM": "Bomi",
    "CM": "Grand Cape Mount",
    "GB": "Grand Bassa",
    "GG": "Grand Gedeh",
    "GK": "Grand Kru",
    "GP": "Gbarpolu",
    "LO": "Lofa",
    "MG": "Margibi",
    "MO": "Montserrado",
    "MY": "Maryland",
    "NI": "Nimba",
    "RG": "River Gee",
    "RI": "River Cess",
    "SI": "Sinoe"
  }
}
validation/data/iso_3166-2/FK.json000064400000000222147361033760012420 0ustar00{
  "source": "http://www.geonames.org/FK/administrative-division-falkland-islands.html",
  "country": "Falkland Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/HU.json000064400000002404147361033760012440 0ustar00{
  "source": "http://www.geonames.org/HU/administrative-division-hungary.html",
  "country": "Hungary",
  "subdivisions": {
    "BA": "Baranya megye",
    "BC": "Békéscsaba",
    "BE": "Békés megye",
    "BK": "Bács-Kiskun megye",
    "BU": "Budapest főváros",
    "BZ": "Borsod-Abaúj-Zemplén megye",
    "CS": "Csongrád megye",
    "DE": "Debrecen",
    "DU": "Dunaújváros",
    "EG": "Eger",
    "ER": "Erd",
    "FE": "Fejér megye",
    "GS": "Győr-Moson-Sopron megye",
    "GY": "Győr",
    "HB": "Hajdú-Bihar megye",
    "HE": "Heves megye",
    "HV": "Hódmezővásárhely",
    "JN": "Jász-Nagykun-Szolnok megye",
    "KE": "Komárom-Esztergom megye",
    "KM": "Kecskemét",
    "KV": "Kaposvár",
    "MI": "Miskolc",
    "NK": "Nagykanizsa",
    "NO": "Nógrád megye",
    "NY": "Nyíregyháza",
    "PE": "Pest megye",
    "PS": "Pécs",
    "SD": "Szeged",
    "SF": "Székesfehérvár",
    "SH": "Szombathely",
    "SK": "Szolnok",
    "SN": "Sopron",
    "SO": "Somogy megye",
    "SS": "Szekszárd",
    "ST": "Salgótarján",
    "SZ": "Szabolcs-Szatmár-Bereg megye",
    "TB": "Tatabánya",
    "TO": "Tolna megye",
    "VA": "Vas megye",
    "VE": "Veszprém megye",
    "VM": "Veszprém",
    "ZA": "Zala megye",
    "ZE": "Zalaegerszeg"
  }
}
validation/data/iso_3166-2/DM.json000064400000000705147361033760012426 0ustar00{
  "source": "http://www.geonames.org/DM/administrative-division-dominica.html",
  "country": "Dominica",
  "subdivisions": {
    "02": "Saint Andrew Parish",
    "03": "Saint David Parish",
    "04": "Saint George Parish",
    "05": "Saint John Parish",
    "06": "Saint Joseph Parish",
    "07": "Saint Luke Parish",
    "08": "Saint Mark Parish",
    "09": "Saint Patrick Parish",
    "10": "Saint Paul Parish",
    "11": "Saint Peter Parish"
  }
}
validation/data/iso_3166-2/AM.json000064400000000562147361033760012424 0ustar00{
  "source": "http://www.geonames.org/AM/administrative-division-armenia.html",
  "country": "Armenia",
  "subdivisions": {
    "AG": "Aragatsotn",
    "AR": "Ararat",
    "AV": "Armavir",
    "ER": "Yerevan",
    "GR": "Geghark'unik'",
    "KT": "Kotayk'",
    "LO": "Lorri",
    "SH": "Shirak",
    "SU": "Syunik'",
    "TV": "Tavush",
    "VD": "Vayots' Dzor"
  }
}
validation/data/iso_3166-2/SZ.json000064400000000335147361033760012461 0ustar00{
  "source": "http://www.geonames.org/SZ/administrative-division-swaziland.html",
  "country": "Swaziland",
  "subdivisions": {
    "HH": "Hhohho",
    "LU": "Lubombo",
    "MA": "Manzini",
    "SH": "Shishelweni"
  }
}
validation/data/iso_3166-2/CW.json000064400000000200147361033760012425 0ustar00{
  "source": "http://www.geonames.org/CW/administrative-division-curacao.html",
  "country": "Curacao",
  "subdivisions": []
}
validation/data/iso_3166-2/MN.json000064400000001164147361033760012440 0ustar00{
  "source": "http://www.geonames.org/MN/administrative-division-mongolia.html",
  "country": "Mongolia",
  "subdivisions": {
    "035": "Orhon",
    "037": "Darhan uul",
    "039": "Hentiy",
    "041": "Hovsgol",
    "043": "Hovd",
    "046": "Uvs",
    "047": "Tov",
    "049": "Selenge",
    "051": "Suhbaatar",
    "053": "Omnogovi",
    "055": "Ovorhangay",
    "057": "Dzavhan",
    "059": "DundgovL",
    "061": "Dornod",
    "063": "Dornogov",
    "064": "Govi-Sumber",
    "065": "Govi-Altay",
    "067": "Bulgan",
    "069": "Bayanhongor",
    "071": "Bayan-Olgiy",
    "073": "Arhangay",
    "1": "Ulanbaatar"
  }
}
validation/data/iso_3166-2/LA.json000064400000001036147361033760012420 0ustar00{
  "source": "http://www.geonames.org/LA/administrative-division-laos.html",
  "country": "Laos",
  "subdivisions": {
    "AT": "Attapu",
    "BK": "Bokeo",
    "BL": "Bolikhamxai",
    "CH": "Champasak",
    "HO": "Houaphan",
    "KH": "Khammouan",
    "LM": "Louang Namtha",
    "LP": "Louangphabang",
    "OU": "Oudomxai",
    "PH": "Phongsali",
    "SL": "Salavan",
    "SV": "Savannakhet",
    "VI": "Vientiane",
    "VT": "Vientiane",
    "XA": "Xaignabouli",
    "XE": "Xekong",
    "XI": "Xiangkhoang",
    "XS": "Xaisômboun"
  }
}
validation/data/iso_3166-2/TR.json000064400000003406147361033760012454 0ustar00{
  "source": "http://www.geonames.org/TR/administrative-division-turkey.html",
  "country": "Turkey",
  "subdivisions": {
    "01": "Adana",
    "02": "Adiyaman",
    "03": "Afyonkarahisar",
    "04": "Agri",
    "05": "Amasya",
    "06": "Ankara",
    "07": "Antalya",
    "08": "Artvin",
    "09": "Aydin",
    "10": "Balikesir",
    "11": "Bilecik",
    "12": "Bingol",
    "13": "Bitlis",
    "14": "Bolu",
    "15": "Burdur",
    "16": "Bursa",
    "17": "Canakkale",
    "18": "Cankiri",
    "19": "Corum",
    "20": "Denizli",
    "21": "Diyarbakir",
    "22": "Edirne",
    "23": "Elazig",
    "24": "Erzincan",
    "25": "Erzurum",
    "26": "Eskisehir",
    "27": "Gaziantep",
    "28": "Giresun",
    "29": "Gumushane",
    "30": "Hakkari",
    "31": "Hatay",
    "32": "Isparta",
    "33": "Mersin",
    "34": "Istanbul",
    "35": "Izmir",
    "36": "Kars",
    "37": "Kastamonu",
    "38": "Kayseri",
    "39": "Kirklareli",
    "40": "Kirsehir",
    "41": "Kocaeli",
    "42": "Konya",
    "43": "Kutahya",
    "44": "Malatya",
    "45": "Manisa",
    "46": "Kahramanmaras",
    "47": "Mardin",
    "48": "Mugla",
    "49": "Mus",
    "50": "Nevsehir",
    "51": "Nigde",
    "52": "Ordu",
    "53": "Rize",
    "54": "Sakarya",
    "55": "Samsun",
    "56": "Siirt",
    "57": "Sinop",
    "58": "Sivas",
    "59": "Tekirdag",
    "60": "Tokat",
    "61": "Trabzon",
    "62": "Tunceli",
    "63": "Sanliurfa",
    "64": "Usak",
    "65": "Van",
    "66": "Yozgat",
    "67": "Zonguldak",
    "68": "Aksaray",
    "69": "Bayburt",
    "70": "Karaman",
    "71": "Kirikkale",
    "72": "Batman",
    "73": "Sirnak",
    "74": "Bartin",
    "75": "Ardahan",
    "76": "Igdir",
    "77": "Yalova",
    "78": "Karabuk",
    "79": "Kilis",
    "80": "Osmaniye",
    "81": "Duzce"
  }
}
validation/data/iso_3166-2/CM.json000064400000001000147361033760012412 0ustar00{
  "source": "http://www.geonames.org/CM/administrative-division-cameroon.html",
  "country": "Cameroon",
  "subdivisions": {
    "AD": "Adamawa Province (Adamaoua)",
    "CE": "Centre Province",
    "EN": "Extreme North Province (Extrême-Nord)",
    "ES": "East Province (Est)",
    "LT": "Littoral Province",
    "NO": "North Province (Nord)",
    "NW": "Northwest Province (Nord-Ouest)",
    "OU": "West Province (Ouest)",
    "SU": "South Province (Sud)",
    "SW": "Southwest Province (Sud-Ouest)."
  }
}
validation/data/iso_3166-2/ME.json000064400000001463147361033760012431 0ustar00{
  "source": "http://www.geonames.org/ME/administrative-division-montenegro.html",
  "country": "Montenegro",
  "subdivisions": {
    "01": "Opština Andrijevica",
    "02": "Opština Bar",
    "03": "Opština Berane",
    "04": "Opština Bijelo Polje",
    "05": "Opština Budva",
    "06": "Opština Cetinje",
    "07": "Opština Danilovgrad",
    "08": "Opština Herceg-Novi",
    "09": "Opština Kolašin",
    "10": "Opština Kotor",
    "11": "Opština Mojkovac",
    "12": "Opština Nikšić",
    "13": "Opština Plav",
    "14": "Opština Pljevlja",
    "15": "Opština Plužine",
    "16": "Opština Podgorica",
    "17": "Opština Rožaje",
    "18": "Opština Šavnik",
    "19": "Opština Tivat",
    "20": "Opština Ulcinj",
    "21": "Opština Žabljak",
    "22": "Gusinje",
    "23": "Petnjica"
  }
}
validation/data/iso_3166-2/CF.json000064400000001067147361033760012420 0ustar00{
  "source": "http://www.geonames.org/CF/administrative-division-central-african-republic.html",
  "country": "Central African Republic",
  "subdivisions": {
    "AC": "Ouham",
    "BB": "Bamingui-Bangoran",
    "BGF": "Bangui",
    "BK": "Basse-Kotto",
    "HK": "Haute-Kotto",
    "HM": "Haut-Mbomou",
    "HS": "Mambere-Kadeï",
    "KB": "Nana-Grebizi",
    "KG": "Kemo",
    "LB": "Lobaye",
    "MB": "Mbomou",
    "MP": "Ombella-M'Poko",
    "NM": "Nana-Mambere",
    "OP": "Ouham-Pende",
    "SE": "Sangha-Mbaere",
    "UK": "Ouaka",
    "VK": "Vakaga"
  }
}
validation/data/iso_3166-2/GP.json000064400000000206147361033760012430 0ustar00{
  "source": "http://www.geonames.org/GP/administrative-division-guadeloupe.html",
  "country": "Guadeloupe",
  "subdivisions": []
}
validation/data/iso_3166-2/JE.json000064400000000176147361033760012426 0ustar00{
  "source": "http://www.geonames.org/JE/administrative-division-jersey.html",
  "country": "Jersey",
  "subdivisions": []
}
validation/data/iso_3166-2/AR.json000064400000001256147361033760012432 0ustar00{
  "source": "http://www.geonames.org/AR/administrative-division-argentina.html",
  "country": "Argentina",
  "subdivisions": {
    "A": "Salta",
    "B": "Buenos Aires Province",
    "C": "Ciudad Autónoma de Buenos Aires",
    "D": "San Luis",
    "E": "Entre Rios",
    "F": "La Rioja",
    "G": "Santiago del Estero",
    "H": "Chaco",
    "J": "San Juan",
    "K": "Catamarca",
    "L": "La Pampa",
    "M": "Mendoza",
    "N": "Misiones",
    "P": "Formosa",
    "Q": "Neuquen",
    "R": "Rio Negro",
    "S": "Santa Fe",
    "T": "Tucuman",
    "U": "Chubut",
    "V": "Tierra del Fuego",
    "W": "Corrientes",
    "X": "Cordoba",
    "Y": "Jujuy",
    "Z": "Santa Cruz"
  }
}
validation/data/iso_3166-2/PY.json000064400000001030147361033760012446 0ustar00{
  "source": "http://www.geonames.org/PY/administrative-division-paraguay.html",
  "country": "Paraguay",
  "subdivisions": {
    "1": "Concepcion",
    "10": "Alto Parana",
    "11": "Central",
    "12": "Neembucu",
    "13": "Amambay",
    "14": "Canindeyu",
    "15": "Presidente Hayes",
    "16": "Alto Paraguay",
    "19": "Boqueron",
    "2": "San Pedro",
    "3": "Cordillera",
    "4": "Guaira",
    "5": "Caaguazu",
    "6": "Caazapa",
    "7": "Itapua",
    "8": "Misiones",
    "9": "Paraguari",
    "ASU": "Asuncion"
  }
}
validation/data/iso_3166-2/BN.json000064400000000335147361033760012424 0ustar00{
  "source": "http://www.geonames.org/BN/administrative-division-brunei.html",
  "country": "Brunei",
  "subdivisions": {
    "BE": "Belait",
    "BM": "Brunei and Muara",
    "TE": "Temburong",
    "TU": "Tutong"
  }
}
validation/data/iso_3166-2/PA.json000064400000000700147361033760012421 0ustar00{
  "source": "http://www.geonames.org/PA/administrative-division-panama.html",
  "country": "Panama",
  "subdivisions": {
    "1": "Bocas del Toro",
    "10": "Panamá Oeste Province",
    "2": "Cocle",
    "3": "Colon",
    "4": "Chiriqui",
    "5": "Darien",
    "6": "Herrera",
    "7": "Los Santos",
    "8": "Panama",
    "9": "Veraguas",
    "EM": "Comarca Emberá-Wounaan",
    "KY": "Comarca de Kuna Yala",
    "NB": "Ngöbe-Buglé"
  }
}
validation/data/iso_3166-2/VN.json000064400000003016147361033760012447 0ustar00{
  "source": "http://www.geonames.org/VN/administrative-division-vietnam.html",
  "country": "Vietnam",
  "subdivisions": {
    "01": "Lai Chau",
    "02": "Lao Cai",
    "03": "Ha Giang",
    "04": "Cao Bang",
    "05": "Son La",
    "06": "Yen Bai",
    "07": "Tuyen Quang",
    "09": "Lang Son",
    "13": "Quang Ninh",
    "14": "Hoa Binh",
    "18": "Ninh Binh",
    "20": "Thai Binh",
    "21": "Thanh Hoa",
    "22": "Nghe An",
    "23": "Ha Tinh",
    "24": "Quang Binh",
    "25": "Quang Tri",
    "26": "Thua Thien-Hue",
    "27": "Quang Nam",
    "28": "Kon Tum",
    "29": "Quang Ngai",
    "30": "Gia Lai",
    "31": "Binh Dinh",
    "32": "Phu Yen",
    "33": "Dak Lak",
    "34": "Khanh Hoa",
    "35": "Lam Dong",
    "36": "Ninh Thuan",
    "37": "Tay Ninh",
    "39": "Dong Nai",
    "40": "Binh Thuan",
    "41": "Long An",
    "43": "Ba Ria-Vung Tau",
    "44": "An Giang",
    "45": "Dong Thap",
    "46": "Tien Giang",
    "47": "Kien Giang",
    "49": "Vinh Long",
    "50": "Ben Tre",
    "51": "Tra Vinh",
    "52": "Soc Trang",
    "53": "Bac Can",
    "54": "Bac Giang",
    "55": "Bac Lieu",
    "56": "Bac Ninh",
    "57": "Binh Duong",
    "58": "Binh Phuoc",
    "59": "Ca Mau",
    "61": "Hai Duong",
    "63": "Ha Nam",
    "66": "Hung Yen",
    "67": "Nam Dinh",
    "68": "Phu Tho",
    "69": "Thai Nguyen",
    "70": "Vinh Phuc",
    "71": "Dien Bien",
    "72": "Dak Nong",
    "73": "Hau Giang",
    "CT": "Can Tho",
    "DN": "Da Nang",
    "HN": "Ha Noi",
    "HP": "Hai Phong",
    "SG": "Ho Chi Minh"
  }
}
validation/data/iso_3166-2/AZ.json000064400000003442147361033760012441 0ustar00{
  "source": "http://www.geonames.org/AZ/administrative-division-azerbaijan.html",
  "country": "Azerbaijan",
  "subdivisions": {
    "ABS": "Abseron",
    "AGA": "Agstafa",
    "AGC": "AgcabAdi",
    "AGM": "Agdam",
    "AGS": "Agdas",
    "AGU": "Agsu",
    "AST": "Astara",
    "BA": "Baki",
    "BAB": "Babek",
    "BAL": "BalakAn",
    "BAR": "Barda",
    "BEY": "Beylaqan",
    "BIL": "Bilasuvar",
    "CAB": "Cabrayil",
    "CAL": "Calilabab",
    "CUL": "Culfa",
    "DAS": "Daskasan",
    "FUZ": "Fuzuli",
    "GA": "Ganca",
    "GAD": "Gadabay",
    "GOR": "Goranboy",
    "GOY": "Goycay",
    "GYG": "Göygöl",
    "HAC": "Haciqabul",
    "IMI": "Imisli",
    "ISM": "Ismayilli",
    "KAL": "Kalbacar",
    "KAN": "Kangarli",
    "KUR": "Kurdamir",
    "LA": "Lankaran",
    "LAC": "Lacin",
    "LAN": "Lankaran Sahari",
    "LER": "Lerik",
    "MAS": "Masalli",
    "MI": "Mingəçevir",
    "NA": "Naftalan",
    "NEF": "Neftcala",
    "NV": "Naxçivan",
    "NX": "Naxcivan",
    "OGU": "Oguz",
    "ORD": "Ordubad",
    "QAB": "Qabala",
    "QAX": "Qax",
    "QAZ": "Qazax",
    "QBA": "Quba",
    "QBI": "Qubadli",
    "QOB": "Qobustan",
    "QUS": "Qusar",
    "SA": "Saki",
    "SAB": "Sabirabad",
    "SAD": "Sadarak",
    "SAH": "Sahbuz",
    "SAK": "Saki Sahari",
    "SAL": "Salyan",
    "SAR": "Sarur",
    "SAT": "Saatli",
    "SBN": "Şabran",
    "SIY": "Siyazan",
    "SKR": "Samkir",
    "SM": "Sumqayit",
    "SMI": "Samaxi",
    "SMX": "Samux",
    "SR": "Şirvan",
    "SUS": "Susa",
    "TAR": "Tartar",
    "TOV": "Tovuz",
    "UCA": "Ucar",
    "XA": "Xankandi",
    "XAC": "Xacmaz",
    "XCI": "Xocali",
    "XIZ": "Xizi",
    "XVD": "Xocavand",
    "YAR": "Yardimli",
    "YE": "Yevlax Sahari",
    "YEV": "Yevlax",
    "ZAN": "Zangilan",
    "ZAQ": "Zaqatala",
    "ZAR": "Zardab"
  }
}
validation/data/iso_3166-2/VA.json000064400000000212147361033760012425 0ustar00{
  "source": "http://www.geonames.org/VA/administrative-division-vatican-city.html",
  "country": "Vatican City",
  "subdivisions": []
}
validation/data/iso_3166-2/MU.json000064400000001132147361033760012442 0ustar00{
  "source": "http://www.geonames.org/MU/administrative-division-mauritius.html",
  "country": "Mauritius",
  "subdivisions": {
    "AG": "Agalega Islands",
    "BL": "Black River",
    "BR": "Beau Bassin-Rose Hill",
    "CC": "Cargados Carajos Shoals (Saint Brandon Islands)",
    "CU": "Curepipe",
    "FL": "Flacq",
    "GP": "Grand Port",
    "MO": "Moka",
    "PA": "Pamplemousses",
    "PL": "Port Louis",
    "PU": "Port Louis",
    "PW": "Plaines Wilhems",
    "QB": "Quatre Bornes",
    "RO": "Rodrigues",
    "RR": "Riviere du Rempart",
    "SA": "Savanne",
    "VP": "Vacoas-Phoenix"
  }
}
validation/data/iso_3166-2/IT.json000064400000005752147361033760012451 0ustar00{
  "source": "http://www.geonames.org/IT/administrative-division-italy.html",
  "country": "Italy",
  "subdivisions": {
    "21": "Piedmont",
    "23": "Regione Autonoma Valle d'Aosta",
    "25": "Lombardy",
    "32": "Regione Autonoma Trentino-Alto Adige",
    "34": "Regione del Veneto",
    "36": "Regione Autonoma Friuli-Venezia Giulia",
    "42": "Regione Liguria",
    "45": "Regione Emilia-Romagna",
    "52": "Tuscany",
    "55": "Regione Umbria",
    "57": "Regione Marche",
    "62": "Regione Lazio",
    "65": "Regione Abruzzo",
    "67": "Regione Molise",
    "72": "Regione Campania",
    "75": "Regione Puglia",
    "77": "Regione Basilicata",
    "78": "Regione Calabria",
    "82": "Regione Autonoma Siciliana",
    "88": "Regione Autonoma della Sardegna",
    "AG": "Agrigento",
    "AL": "Alessandria",
    "AN": "Ancona",
    "AO": "Aosta",
    "AP": "Ascoli Piceno",
    "AQ": "L'Aquila",
    "AR": "Arezzo",
    "AT": "Asti",
    "AV": "Avellino",
    "BA": "Bari",
    "BG": "Bergamo",
    "BI": "Biella",
    "BL": "Belluno",
    "BN": "Benevento",
    "BO": "Bologna",
    "BR": "Brindisi",
    "BS": "Brescia",
    "BT": "Barletta-Andria-Trani",
    "BZ": "Bolzano",
    "CA": "Cagliari",
    "CB": "Campobasso",
    "CE": "Caserta",
    "CH": "Chieti",
    "CL": "Caltanissetta",
    "CN": "Cuneo",
    "CO": "Como",
    "CR": "Cremona",
    "CS": "Cosenza",
    "CT": "Catania",
    "CZ": "Catanzaro",
    "EN": "Enna",
    "FC": "Forlì-Cesena",
    "FE": "Ferrara",
    "FG": "Foggia",
    "FI": "Firenze",
    "FM": "Fermo",
    "FR": "Frosinone",
    "GE": "Genova",
    "GO": "Gorizia",
    "GR": "Grosseto",
    "IM": "Imperia",
    "IS": "Isernia",
    "KR": "Crotone",
    "LC": "Lecco",
    "LE": "Lecce",
    "LI": "Livorno",
    "LO": "Lodi",
    "LT": "Latina",
    "LU": "Lucca",
    "MB": "Monza e Brianza",
    "MC": "Macerata",
    "ME": "Messina",
    "MI": "Milano",
    "MN": "Mantova",
    "MO": "Modena",
    "MS": "Massa-Carrara",
    "MT": "Matera",
    "NA": "Napoli",
    "NO": "Novara",
    "NU": "Nuoro",
    "OR": "Oristano",
    "PA": "Palermo",
    "PC": "Piacenza",
    "PD": "Padova",
    "PE": "Pescara",
    "PG": "Perugia",
    "PI": "Pisa",
    "PN": "Pordenone",
    "PO": "Prato",
    "PR": "Parma",
    "PT": "Pistoia",
    "PU": "Pesaro e Urbino",
    "PV": "Pavia",
    "PZ": "Potenza",
    "RA": "Ravenna",
    "RC": "Reggio Calabria",
    "RE": "Reggio Emilia",
    "RG": "Ragusa",
    "RI": "Rieti",
    "RM": "Roma",
    "RN": "Rimini",
    "RO": "Rovigo",
    "SA": "Salerno",
    "SI": "Siena",
    "SO": "Sondrio",
    "SP": "La Spezia",
    "SR": "Siracusa",
    "SS": "Sassari",
    "SV": "Savona",
    "TA": "Taranto",
    "TE": "Teramo",
    "TN": "Trento",
    "TO": "Torino",
    "TP": "Trapani",
    "TR": "Terni",
    "TS": "Trieste",
    "TV": "Treviso",
    "UD": "Udine",
    "VA": "Varese",
    "VB": "Verbano-Cusio-Ossola",
    "VC": "Vercelli",
    "VE": "Venezia",
    "VI": "Vicenza",
    "VR": "Verona",
    "VT": "Viterbo",
    "VV": "Vibo Valentia"
  }
}
validation/data/iso_3166-2/GQ.json000064400000000667147361033760012444 0ustar00{
  "source": "http://www.geonames.org/GQ/administrative-division-equatorial-guinea.html",
  "country": "Equatorial Guinea",
  "subdivisions": {
    "AN": "Provincia Annobon",
    "BN": "Provincia Bioko Norte",
    "BS": "Provincia Bioko Sur",
    "C": "Región Continental",
    "CS": "Provincia Centro Sur",
    "I": "Región Insular",
    "KN": "Provincia Kie-Ntem",
    "LI": "Provincia Litoral",
    "WN": "Provincia Wele-Nzas"
  }
}
validation/data/iso_3166-2/SB.json000064400000000574147361033760012436 0ustar00{
  "source": "http://www.geonames.org/SB/administrative-division-solomon-islands.html",
  "country": "Solomon Islands",
  "subdivisions": {
    "CE": "Central",
    "CH": "Choiseul",
    "CT": "Capital Territory",
    "GU": "Guadalcanal",
    "IS": "Isabel",
    "MK": "Makira",
    "ML": "Malaita",
    "RB": "Rennell and Bellona",
    "TE": "Temotu",
    "WE": "Western"
  }
}
validation/data/iso_3166-2/GM.json000064400000000410147361033760012422 0ustar00{
  "source": "http://www.geonames.org/GM/administrative-division-gambia.html",
  "country": "Gambia",
  "subdivisions": {
    "B": "Banjul",
    "L": "Lower River",
    "M": "Central River",
    "N": "North Bank",
    "U": "Upper River",
    "W": "Western"
  }
}
validation/data/iso_3166-2/YE.json000064400000001113147361033760012435 0ustar00{
  "source": "http://www.geonames.org/YE/administrative-division-yemen.html",
  "country": "Yemen",
  "subdivisions": {
    "AB": "Abyan",
    "AD": "Adan",
    "AM": "Amran",
    "BA": "Al Bayda",
    "DA": "Ad Dali",
    "DH": "Dhamar",
    "HD": "Hadramawt",
    "HJ": "Hajjah",
    "HU": "Al Hudaydah",
    "IB": "Ibb",
    "JA": "Al Jawf",
    "LA": "Lahij",
    "MA": "Ma'rib",
    "MR": "Al Mahrah",
    "MW": "Al Mahwit",
    "RA": "Raymah",
    "SA": "Amanat Al Asimah",
    "SD": "Sa'dah",
    "SH": "Shabwah",
    "SN": "San'a",
    "SU": "Socotra",
    "TA": "Ta'izz"
  }
}
validation/data/iso_3166-2/CH.json000064400000001321147361033760012413 0ustar00{
  "source": "http://www.geonames.org/CH/administrative-division-switzerland.html",
  "country": "Switzerland",
  "subdivisions": {
    "AG": "Aargau",
    "AI": "Appenzell Innerhoden",
    "AR": "Appenzell Ausserrhoden",
    "BE": "Bern",
    "BL": "Basel-Landschaft",
    "BS": "Basel-Stadt",
    "FR": "Fribourg",
    "GE": "Geneva",
    "GL": "Glarus",
    "GR": "Graubunden",
    "JU": "Jura",
    "LU": "Lucerne",
    "NE": "Neuchâtel",
    "NW": "Nidwalden",
    "OW": "Obwalden",
    "SG": "St. Gallen",
    "SH": "Schaffhausen",
    "SO": "Solothurn",
    "SZ": "Schwyz",
    "TG": "Thurgau",
    "TI": "Ticino",
    "UR": "Uri",
    "VD": "Vaud",
    "VS": "Valais",
    "ZG": "Zug",
    "ZH": "Zurich"
  }
}
validation/data/iso_3166-2/ST.json000064400000000313147361033760012447 0ustar00{
  "source": "http://www.geonames.org/ST/administrative-division-sao-tome-and-principe.html",
  "country": "São Tomé and Príncipe",
  "subdivisions": {
    "P": "Principe",
    "S": "Sao Tome"
  }
}
validation/data/iso_3166-2/EC.json000064400000001226147361033760012414 0ustar00{
  "source": "http://www.geonames.org/EC/administrative-division-ecuador.html",
  "country": "Ecuador",
  "subdivisions": {
    "A": "Azuay",
    "B": "Bolivar",
    "C": "Carchi",
    "D": "Orellana",
    "E": "Esmeraldas",
    "F": "Canar",
    "G": "Guayas",
    "H": "Chimborazo",
    "I": "Imbabura",
    "L": "Loja",
    "M": "Manabi",
    "N": "Napo",
    "O": "El Oro",
    "P": "Pichincha",
    "R": "Los Rios",
    "S": "Morona-Santiago",
    "SD": "Santo Domingo de los Tsáchilas",
    "SE": "Santa Elena",
    "T": "Tungurahua",
    "U": "Sucumbios",
    "W": "Galapagos",
    "X": "Cotopaxi",
    "Y": "Pastaza",
    "Z": "Zamora-Chinchipe"
  }
}
validation/data/iso_3166-2/KP.json000064400000000724147361033760012441 0ustar00{
  "source": "http://www.geonames.org/KP/administrative-division-north-korea.html",
  "country": "North Korea",
  "subdivisions": {
    "01": "P'yongyang Special City",
    "02": "P'yongan-namdo",
    "03": "P'yongan-bukto",
    "04": "Chagang-do",
    "05": "Hwanghae-namdo",
    "06": "Hwanghae-bukto",
    "07": "Kangwon-do",
    "08": "Hamgyong-namdo",
    "09": "Hamgyong-bukto",
    "10": "Ryanggang-do (Yanggang-do)",
    "13": "Nasŏn (Najin-Sŏnbong)"
  }
}
validation/data/iso_3166-2/MC.json000064400000001051147361033760012420 0ustar00{
  "source": "http://www.geonames.org/MC/administrative-division-monaco.html",
  "country": "Monaco",
  "subdivisions": {
    "CL": "La Colle",
    "CO": "La Condamine",
    "FO": "Fontvieille",
    "GA": "La Gare",
    "JE": "Jardin Exotique",
    "LA": "Larvotto",
    "MA": "Malbousquet",
    "MC": "Monte-Carlo",
    "MG": "Moneghetti",
    "MO": "Monaco-Ville",
    "MU": "Moulins",
    "PH": "Port-Hercule",
    "SD": "Sainte-Dévote",
    "SO": "La Source",
    "SP": "Spélugues",
    "SR": "Saint-Roman",
    "VR": "Vallon de la Rousse"
  }
}
validation/data/iso_3166-2/MP.json000064400000000370147361033760012440 0ustar00{
  "source": "http://www.geonames.org/MP/administrative-division-northern-mariana-islands.html",
  "country": "Northern Mariana Islands",
  "subdivisions": {
    "N": "Northern Islands",
    "R": "Rota",
    "S": "Saipan",
    "T": "Tinian"
  }
}
validation/data/iso_3166-2/NL.json000064400000000643147361033760012440 0ustar00{
  "source": "http://www.geonames.org/NL/administrative-division-netherlands.html",
  "country": "Netherlands",
  "subdivisions": {
    "DR": "Drenthe",
    "FL": "Flevoland",
    "FR": "Friesland",
    "GE": "Gelderland",
    "GR": "Groningen",
    "LI": "Limburg",
    "NB": "Noord Brabant",
    "NH": "Noord Holland",
    "OV": "Overijssel",
    "UT": "Utrecht",
    "ZE": "Zeeland",
    "ZH": "Zuid Holland"
  }
}
validation/data/iso_3166-2/ID.json000064400000002216147361033760012421 0ustar00{
  "source": "http://www.geonames.org/ID/administrative-division-indonesia.html",
  "country": "Indonesia",
  "subdivisions": {
    "AC": "Aceh",
    "BA": "Bali",
    "BB": "Bangka-Belitung",
    "BE": "Bengkulu",
    "BT": "Banten",
    "GO": "Gorontalo",
    "JA": "Jambi",
    "JB": "Jawa Barat",
    "JI": "Jawa Timur",
    "JK": "Jakarta Raya",
    "JT": "Jawa Tengah",
    "JW": "Java",
    "KA": "Kalimantan",
    "KB": "Kalimantan Barat",
    "KI": "Kalimantan Timur",
    "KR": "Kepulauan Riau",
    "KS": "Kalimantan Selatan",
    "KT": "Kalimantan Tengah",
    "KU": "Kalimantan Utara",
    "LA": "Lampung",
    "MA": "Maluku",
    "ML": "Maluku",
    "MU": "Maluku Utara",
    "NB": "Nusa Tenggara Barat",
    "NT": "Nusa Tenggara Timur",
    "NU": "Nusa Tenggara",
    "PA": "Papua",
    "PB": "Papua Barat",
    "PP": "Papua",
    "RI": "Riau",
    "SA": "Sulawesi Utara",
    "SB": "Sumatera Barat",
    "SG": "Sulawesi Tenggara",
    "SL": "Sulawesi",
    "SM": "Sumatera",
    "SN": "Sulawesi Selatan",
    "SR": "Sulawesi Barat",
    "SS": "Sumatera Selatan",
    "ST": "Sulawesi Tengah",
    "SU": "Sumatera Utara",
    "YO": "Yogyakarta"
  }
}
validation/data/iso_3166-2/AT.json000064400000000513147361033760012427 0ustar00{
  "source": "http://www.geonames.org/AT/administrative-division-austria.html",
  "country": "Austria",
  "subdivisions": {
    "1": "Burgenland",
    "2": "Karnten",
    "3": "Niederosterreich",
    "4": "Oberosterreich",
    "5": "Salzburg",
    "6": "Steiermark",
    "7": "Tirol",
    "8": "Vorarlberg",
    "9": "Wien"
  }
}
validation/data/iso_3166-2/DZ.json000064400000002214147361033760012440 0ustar00{
  "source": "http://www.geonames.org/DZ/administrative-division-algeria.html",
  "country": "Algeria",
  "subdivisions": {
    "01": "Adrar",
    "02": "Chlef",
    "03": "Laghouat",
    "04": "Oum el-Bouaghi",
    "05": "Batna",
    "06": "Bejaia",
    "07": "Biskra",
    "08": "Bechar",
    "09": "Blida",
    "10": "Bouira",
    "11": "Tamanghasset",
    "12": "Tebessa",
    "13": "Tlemcen",
    "14": "Tiaret",
    "15": "Tizi Ouzou",
    "16": "Alger",
    "17": "Djelfa",
    "18": "Jijel",
    "19": "Setif",
    "20": "Saida",
    "21": "Skikda",
    "22": "Sidi Bel Abbes",
    "23": "Annaba",
    "24": "Guelma",
    "25": "Constantine",
    "26": "Medea",
    "27": "Mostaganem",
    "28": "M'Sila",
    "29": "Muaskar",
    "30": "Ouargla",
    "31": "Oran",
    "32": "El Bayadh",
    "33": "Illizi",
    "34": "Bordj Bou Arreridj",
    "35": "Boumerdes",
    "36": "El Tarf",
    "37": "Tindouf",
    "38": "Tissemsilt",
    "39": "El Oued",
    "40": "Khenchela",
    "41": "Souk Ahras",
    "42": "Tipaza",
    "43": "Mila",
    "44": "Ain Defla",
    "45": "Naama",
    "46": "Ain Temouchent",
    "47": "Ghardaia",
    "48": "Relizane"
  }
}
validation/data/iso_3166-2/KZ.json000064400000001104147361033760012444 0ustar00{
  "source": "http://www.geonames.org/KZ/administrative-division-kazakhstan.html",
  "country": "Kazakhstan",
  "subdivisions": {
    "AKM": "Aqmola",
    "AKT": "Aqtobe",
    "ALA": "Almaty",
    "ALM": "Almaty",
    "AST": "Astana",
    "ATY": "Atyrau",
    "BAY": "Baykonyr",
    "KAR": "Qaraghandy",
    "KUS": "Qustanay",
    "KZY": "Qyzylorda",
    "MAN": "Mangghystau",
    "PAV": "Paylodar",
    "SEV": "Soltustik Qazaqstan",
    "SHY": "Shymkent",
    "VOS": "Shyghys Qazaqstan",
    "YUZ": "Ongtustik Qazaqstan",
    "ZAP": "Baty Qazaqstan",
    "ZHA": "Zhambyl"
  }
}
validation/data/iso_3166-2/PM.json000064400000000324147361033760012437 0ustar00{
  "source": "http://www.geonames.org/PM/administrative-division-saint-pierre-and-miquelon.html",
  "country": "Saint Pierre and Miquelon",
  "subdivisions": {
    "M": "Miquelon",
    "P": "Saint Pierre"
  }
}
validation/data/iso_3166-2/NF.json000064400000000216147361033760012426 0ustar00{
  "source": "http://www.geonames.org/NF/administrative-division-norfolk-island.html",
  "country": "Norfolk Island",
  "subdivisions": []
}
validation/data/iso_3166-2/TM.json000064400000000453147361033760012446 0ustar00{
  "source": "http://www.geonames.org/TM/administrative-division-turkmenistan.html",
  "country": "Turkmenistan",
  "subdivisions": {
    "A": "Ahal Welayaty",
    "B": "Balkan Welayaty",
    "D": "Dashhowuz Welayaty",
    "L": "Lebap Welayaty",
    "M": "Mary Welayaty",
    "S": "Aşgabat"
  }
}
validation/data/iso_3166-2/HT.json000064400000000517147361033760012442 0ustar00{
  "source": "http://www.geonames.org/HT/administrative-division-haiti.html",
  "country": "Haiti",
  "subdivisions": {
    "AR": "Artibonite",
    "CE": "Centre",
    "GA": "Grand'Anse",
    "ND": "Nord",
    "NE": "Nord-Est",
    "NI": "Nippes",
    "NO": "Nord-Ouest",
    "OU": "Ouest",
    "SD": "Sud",
    "SE": "Sud-Est"
  }
}
validation/data/iso_3166-2/CN.json000064400000001530147361033760012423 0ustar00{
  "source": "http://www.geonames.org/CN/administrative-division-china.html",
  "country": "China",
  "subdivisions": {
    "AH": "Anhui",
    "BJ": "Beijing",
    "CQ": "Chongqìng",
    "FJ": "Fujian",
    "GD": "Guangdong",
    "GS": "Gansu",
    "GX": "Guangxi",
    "GZ": "Guizhou",
    "HA": "Henan",
    "HB": "Hubei",
    "HE": "Hebei",
    "HI": "Hainan",
    "HK": "Xianggang",
    "HL": "Heilongjiang",
    "HN": "Hunan",
    "JL": "Jilin",
    "JS": "Jiangsu",
    "JX": "Jiangxi",
    "LN": "Liaoning",
    "MO": "Aomen",
    "NM": "Nei Mongol",
    "NX": "Ningxia",
    "QH": "Qinghai",
    "SC": "Sichuan",
    "SD": "Shandong",
    "SH": "Shanghai",
    "SN": "Shaanxi",
    "SX": "Shanxi",
    "TJ": "Tianjin",
    "TW": "Taiwan",
    "XJ": "Xinjiang",
    "XZ": "Xizang Zìzhìqu (Tibet)",
    "YN": "Yunnan",
    "ZJ": "Zhejiang"
  }
}
validation/data/iso_3166-2/SA.json000064400000000702147361033760012426 0ustar00{
  "source": "http://www.geonames.org/SA/administrative-division-saudi-arabia.html",
  "country": "Saudi Arabia",
  "subdivisions": {
    "01": "Ar Riyad",
    "02": "Makkah",
    "03": "Al Madinah",
    "04": "Ash Sharqiyah (Eastern Province)",
    "05": "Al Qasim",
    "06": "Ha'il",
    "07": "Tabuk",
    "08": "Al Hudud ash Shamaliyah",
    "09": "Jizan",
    "10": "Najran",
    "11": "Al Bahah",
    "12": "Al Jawf",
    "14": "'Asir"
  }
}
validation/data/iso_3166-2/RW.json000064400000000333147361033760012453 0ustar00{
  "source": "http://www.geonames.org/RW/administrative-division-rwanda.html",
  "country": "Rwanda",
  "subdivisions": {
    "01": "Kigali",
    "02": "Est",
    "03": "Nord",
    "04": "Ouest",
    "05": "Sud"
  }
}
validation/data/iso_3166-2/CC.json000064400000000433147361033760012411 0ustar00{
  "source": "http://www.geonames.org/CC/administrative-division-cocos-islands.html",
  "country": "Cocos [Keeling] Islands",
  "subdivisions": {
    "D": "Direction Island",
    "H": "Home Island",
    "O": "Horsburgh Island",
    "S": "South Island",
    "W": "West Island"
  }
}
validation/data/iso_3166-2/IL.json000064400000000376147361033760012436 0ustar00{
  "source": "http://www.geonames.org/IL/administrative-division-israel.html",
  "country": "Israel",
  "subdivisions": {
    "D": "Southern",
    "HA": "Haifa",
    "JM": "Jerusalem",
    "M": "Central",
    "TA": "Tel Aviv",
    "Z": "Northern"
  }
}
validation/data/iso_3166-2/BF.json000064400000002624147361033760012417 0ustar00{
  "source": "http://www.geonames.org/BF/administrative-division-burkina-faso.html",
  "country": "Burkina Faso",
  "subdivisions": {
    "01": "Boucle du Mouhoun",
    "02": "Cascades",
    "03": "Centre",
    "04": "Centre-Est",
    "05": "Centre-Nord",
    "06": "Centre-Ouest",
    "07": "Centre-Sud",
    "08": "Est",
    "09": "Hauts-Bassins",
    "10": "Nord",
    "11": "Plateau-Central",
    "12": "Sahel",
    "13": "Sud-Ouest",
    "BAL": "Bale",
    "BAM": "Bam",
    "BAN": "Banwa",
    "BAZ": "Bazega",
    "BGR": "Bougouriba",
    "BLG": "Boulgou",
    "BLK": "Boulkiemde",
    "COM": "Comoe",
    "GAN": "Ganzourgou",
    "GNA": "Gnagna",
    "GOU": "Gourma",
    "HOU": "Houet",
    "IOB": "Ioba",
    "KAD": "Kadiogo",
    "KEN": "Kenedougou",
    "KMD": "Komondjari",
    "KMP": "Kompienga",
    "KOP": "Koulpelogo",
    "KOS": "Kossi",
    "KOT": "Kouritenga",
    "KOW": "Kourweogo",
    "LER": "Leraba",
    "LOR": "Loroum",
    "MOU": "Mouhoun",
    "NAM": "Namentenga",
    "NAO": "Nahouri",
    "NAY": "Nayala",
    "NOU": "Noumbiel",
    "OUB": "Oubritenga",
    "OUD": "Oudalan",
    "PAS": "Passore",
    "PON": "Poni",
    "SEN": "Seno",
    "SIS": "Sissili",
    "SMT": "Sanmatenga",
    "SNG": "Sanguie",
    "SOM": "Soum",
    "SOR": "Sourou",
    "TAP": "Tapoa",
    "TUI": "Tuy",
    "YAG": "Yagha",
    "YAT": "Yatenga",
    "ZIR": "Ziro",
    "ZON": "Zondoma",
    "ZOU": "Zoundweogo"
  }
}
validation/data/iso_3166-2/MD.json000064400000002170147361033760012424 0ustar00{
  "source": "http://www.geonames.org/MD/administrative-division-moldova.html",
  "country": "Moldova",
  "subdivisions": {
    "AN": "Raionul Anenii Noi",
    "BA": "Municipiul Bălţi",
    "BD": "Tighina",
    "BR": "Raionul Briceni",
    "BS": "Raionul Basarabeasca",
    "CA": "Cahul",
    "CL": "Raionul Călăraşi",
    "CM": "Raionul Cimişlia",
    "CR": "Raionul Criuleni",
    "CS": "Raionul Căuşeni",
    "CT": "Raionul Cantemir",
    "CU": "Municipiul Chişinău",
    "DO": "Donduşeni",
    "DR": "Raionul Drochia",
    "DU": "Dubăsari",
    "ED": "Raionul Edineţ",
    "FA": "Făleşti",
    "FL": "Floreşti",
    "GA": "U.T.A. Găgăuzia",
    "GL": "Raionul Glodeni",
    "HI": "Hînceşti",
    "IA": "Ialoveni",
    "LE": "Leova",
    "NI": "Nisporeni",
    "OC": "Raionul Ocniţa",
    "OR": "Raionul Orhei",
    "RE": "Rezina",
    "RI": "Rîşcani",
    "SD": "Raionul Şoldăneşti",
    "SI": "Sîngerei",
    "SN": "Stînga Nistrului",
    "SO": "Soroca",
    "ST": "Raionul Străşeni",
    "SV": "Raionul Ştefan Vodă",
    "TA": "Raionul Taraclia",
    "TE": "Teleneşti",
    "UN": "Raionul Ungheni"
  }
}
validation/data/iso_3166-2/CZ.json000064400000006245147361033760012447 0ustar00{
  "source": "http://www.geonames.org/CZ/administrative-division-czech-republic.html",
  "country": "Czechia",
  "subdivisions": {
    "10": "Prague - the Capital (Praha - hlavni mesto)",
    "101": "Praha 1",
    "102": "Praha 2",
    "103": "Praha 3",
    "104": "Praha 4",
    "105": "Praha 5",
    "106": "Praha 6",
    "107": "Praha 7",
    "108": "Praha 8",
    "109": "Praha 9",
    "110": "Praha 10",
    "111": "Praha 11",
    "112": "Praha 12",
    "113": "Praha 13",
    "114": "Praha 14",
    "115": "Praha 15",
    "116": "Praha 16",
    "117": "Praha 17",
    "118": "Praha 18",
    "119": "Praha 19",
    "120": "Praha 20",
    "121": "Praha 21",
    "122": "Praha 22",
    "20": "Central Bohemian Region (Stredocesky kraj)",
    "201": "Benešov",
    "202": "Beroun",
    "203": "Kladno",
    "204": "Kolín",
    "205": "Kutná Hora",
    "206": "Mělník",
    "207": "Mladá Boleslav",
    "208": "Nymburk",
    "209": "Praha-východ",
    "20A": "Praha-západ",
    "20B": "Příbram",
    "20C": "Rakovník",
    "31": "South Bohemian Region (Jihocesky kraj)",
    "311": "České Budějovice",
    "312": "Český Krumlov",
    "313": "Jindřichův Hradec",
    "314": "Písek",
    "315": "Prachatice",
    "316": "Strakonice",
    "317": "Tábor",
    "32": "Plzen( Region Plzensky kraj)",
    "321": "Domažlice",
    "322": "Klatovy",
    "323": "Plzeň-město",
    "324": "Plzeň-jih",
    "325": "Plzeň-sever",
    "326": "Rokycany",
    "327": "Tachov",
    "41": "Carlsbad Region  (Karlovarsky kraj)",
    "411": "Cheb",
    "412": "Karlovy Vary",
    "413": "Sokolov",
    "42": "Usti nad Labem Region (Ustecky kraj)",
    "421": "Děčín",
    "422": "Chomutov",
    "423": "Litoměřice",
    "424": "Louny",
    "425": "Most",
    "426": "Teplice",
    "427": "Ústí nad Labem",
    "51": "Liberec Region (Liberecky kraj)",
    "511": "Česká Lípa",
    "512": "Jablonec nad Nisou",
    "513": "Liberec",
    "514": "Semily",
    "52": "Hradec Kralove Region (Kralovehradecky kraj)",
    "521": "Hradec Králové",
    "522": "Jičín",
    "523": "Náchod",
    "524": "Rychnov nad Kněžnou",
    "525": "Trutnov",
    "53": "Pardubice Region (Pardubicky kraj)",
    "531": "Chrudim",
    "532": "Pardubice",
    "533": "Svitavy",
    "534": "Ústí nad Orlicí",
    "63": "Vysocina Region (kraj Vysocina)",
    "631": "Havlíčkův Brod",
    "632": "Jihlava",
    "633": "Pelhřimov",
    "634": "Třebíč",
    "635": "Žd’ár nad Sázavou",
    "64": "South Moravian Region (Jihomoravsky kraj)",
    "641": "Blansko",
    "642": "Brno-město",
    "643": "Brno-venkov",
    "644": "Břeclav",
    "645": "Hodonín",
    "646": "Vyškov",
    "647": "Znojmo",
    "71": "Olomouc Region (Olomoucky kraj)",
    "711": "Jeseník",
    "712": "Olomouc",
    "713": "Prostĕjov",
    "714": "Přerov",
    "715": "Šumperk",
    "72": "Zlin Region (Zlinsky kraj)",
    "721": "Kromĕříž",
    "722": "Uherské Hradištĕ",
    "723": "Vsetín",
    "724": "Zlín",
    "80": "Moravian-Silesian Region (Moravskoslezsky kraj)",
    "801": "Bruntál",
    "802": "Frýdek - Místek",
    "803": "Karviná",
    "804": "Nový Jičín",
    "805": "Opava",
    "806": "Ostrava - město"
  }
}
validation/data/iso_3166-2/GG.json000064400000000202147361033760012413 0ustar00{
  "source": "http://www.geonames.org/GG/administrative-division-guernsey.html",
  "country": "Guernsey",
  "subdivisions": []
}
validation/data/iso_3166-2/LC.json000064400000000553147361033760012425 0ustar00{
  "source": "http://www.geonames.org/LC/administrative-division-saint-lucia.html",
  "country": "Saint Lucia",
  "subdivisions": {
    "01": "Anse-la-Raye",
    "02": "Castries",
    "03": "Choiseul",
    "05": "Dennery",
    "06": "Gros-Islet",
    "07": "Laborie",
    "08": "Micoud",
    "10": "Soufriere",
    "11": "Vieux-Fort",
    "12": "Canaries"
  }
}
validation/data/iso_3166-2/TL.json000064400000000626147361033760012447 0ustar00{
  "source": "http://www.geonames.org/TL/administrative-division-east-timor.html",
  "country": "East Timor",
  "subdivisions": {
    "AL": "Aileu",
    "AN": "Ainaro",
    "BA": "Baucau",
    "BO": "Bobonaro",
    "CO": "Cova Lima",
    "DI": "Dili",
    "ER": "Ermera",
    "LA": "Lautem",
    "LI": "Liquica",
    "MF": "Manufahi",
    "MT": "Manatuto",
    "OE": "Oecussi",
    "VI": "Viqueque"
  }
}
validation/data/iso_3166-2/MH.json000064400000001262147361033760012431 0ustar00{
  "source": "http://www.geonames.org/MH/administrative-division-marshall-islands.html",
  "country": "Marshall Islands",
  "subdivisions": {
    "ALK": "Ailuk",
    "ALL": "Ailinglaplap",
    "ARN": "Arno",
    "AUR": "Aur",
    "EBO": "Ebon",
    "ENI": "Enewetak",
    "JAB": "Jabat",
    "JAL": "Jaluit",
    "KIL": "Kili",
    "KWA": "Kwajalein",
    "L": "Ralik chain",
    "LAE": "Lae",
    "LIB": "Lib",
    "LIK": "Likiep",
    "MAJ": "Majuro",
    "MAL": "Maloelap",
    "MEJ": "Mejit",
    "MIL": "Mili",
    "NMK": "Namorik",
    "NMU": "Namu",
    "RON": "Rongelap",
    "T": "Ratak chain",
    "UJA": "Ujae",
    "UTI": "Utirik",
    "WTH": "Wotho",
    "WTJ": "Wotje"
  }
}
validation/data/iso_3166-2/VE.json000064400000001225147361033760012436 0ustar00{
  "source": "http://www.geonames.org/VE/administrative-division-venezuela.html",
  "country": "Venezuela",
  "subdivisions": {
    "A": "Federal Capital",
    "B": "Anzoategui",
    "C": "Apure",
    "D": "Aragua",
    "E": "Barinas",
    "F": "Bolivar",
    "G": "Carabobo",
    "H": "Cojedes",
    "I": "Falcon",
    "J": "Guarico",
    "K": "Lara",
    "L": "Merida",
    "M": "Miranda",
    "N": "Monagas",
    "O": "Nueva Esparta",
    "P": "Portuguesa",
    "R": "Sucre",
    "S": "Tachira",
    "T": "Trujillo",
    "U": "Yaracuy",
    "V": "Zulia",
    "W": "Federal Dependency",
    "X": "Vargas",
    "Y": "Delta Amacuro",
    "Z": "Amazonas"
  }
}
validation/data/iso_3166-2/KR.json000064400000001226147361033760012441 0ustar00{
  "source": "http://www.geonames.org/KR/administrative-division-south-korea.html",
  "country": "South Korea",
  "subdivisions": {
    "11": "Seoul Special City",
    "26": "Busan Metropolitan City",
    "27": "Daegu Metropolitan City",
    "28": "Incheon Metropolitan City",
    "29": "Gwangju Metropolitan City",
    "30": "Daejeon Metropolitan City",
    "31": "Ulsan Metropolitan City",
    "41": "Gyeonggi-do",
    "42": "Gangwon-do",
    "43": "Chungcheongbuk-do",
    "44": "Chungcheongnam-do",
    "45": "Jeollabuk-do",
    "46": "Jeollanam-do",
    "47": "Gyeongsangbuk-do",
    "48": "Gyeongsangnam-do",
    "49": "Jeju-do",
    "50": "Sejong"
  }
}
validation/data/iso_3166-2/AO.json000064400000001053147361033760012422 0ustar00{
  "source": "http://www.geonames.org/AO/administrative-division-angola.html",
  "country": "Angola",
  "subdivisions": {
    "BGO": "Bengo",
    "BGU": "Benguela province",
    "BIE": "Bie",
    "CAB": "Cabinda",
    "CCU": "Cuando-Cubango",
    "CNN": "Cunene",
    "CNO": "Cuanza Norte",
    "CUS": "Cuanza Sul",
    "HUA": "Huambo province",
    "HUI": "Huila province",
    "LNO": "Lunda Norte",
    "LSU": "Lunda Sul",
    "LUA": "Luanda",
    "MAL": "Malange",
    "MOX": "Moxico",
    "NAM": "Namibe",
    "UIG": "Uige",
    "ZAI": "Zaire"
  }
}
validation/data/iso_3166-2/SR.json000064400000000543147361033760012452 0ustar00{
  "source": "http://www.geonames.org/SR/administrative-division-suriname.html",
  "country": "Suriname",
  "subdivisions": {
    "BR": "Brokopondo",
    "CM": "Commewijne",
    "CR": "Coronie",
    "MA": "Marowijne",
    "NI": "Nickerie",
    "PM": "Paramaribo",
    "PR": "Para",
    "SA": "Saramacca",
    "SI": "Sipaliwini",
    "WA": "Wanica"
  }
}
validation/data/iso_3166-2/BQ.json000064400000000305147361033760012424 0ustar00{
  "source": "http://www.geonames.org/BQ/administrative-division-bonaire.html",
  "country": "Bonaire",
  "subdivisions": {
    "BO": "Bonaire",
    "SA": "Saba",
    "SE": "Sint Eustatius"
  }
}
validation/data/iso_3166-2/BJ.json000064400000000562147361033760012422 0ustar00{
  "source": "http://www.geonames.org/BJ/administrative-division-benin.html",
  "country": "Benin",
  "subdivisions": {
    "AK": "Atakora",
    "AL": "Alibori",
    "AQ": "Atlantique",
    "BO": "Borgou",
    "CO": "Collines",
    "DO": "Donga",
    "KO": "Kouffo",
    "LI": "Littoral",
    "MO": "Mono",
    "OU": "Oueme",
    "PL": "Plateau",
    "ZO": "Zou"
  }
}
validation/data/iso_3166-2/NR.json000064400000000614147361033760012444 0ustar00{
  "source": "http://www.geonames.org/NR/administrative-division-nauru.html",
  "country": "Nauru",
  "subdivisions": {
    "01": "Aiwo",
    "02": "Anabar",
    "03": "Anetan",
    "04": "Anibare",
    "05": "Baiti",
    "06": "Boe",
    "07": "Buada",
    "08": "Denigomodu",
    "09": "Ewa",
    "10": "Ijuw",
    "11": "Meneng",
    "12": "Nibok",
    "13": "Uaboe",
    "14": "Yaren"
  }
}
validation/data/iso_3166-2/JP.json000064400000002336147361033760012441 0ustar00{
  "source": "http://www.geonames.org/JP/administrative-division-japan.html",
  "country": "Japan",
  "subdivisions": {
    "01": "Hokkaidō",
    "02": "Aomori",
    "03": "Iwate",
    "04": "Miyagi",
    "05": "Akita",
    "06": "Yamagata",
    "07": "Hukusima (Fukushima)",
    "08": "Ibaraki",
    "09": "Totigi (Tochigi)",
    "10": "Gunma",
    "11": "Saitama",
    "12": "Tiba (Chiba)",
    "13": "Tokyo",
    "14": "Kanagawa",
    "15": "Niigata",
    "16": "Toyama",
    "17": "Isikawa (Ishikawa)",
    "18": "Hukui (Fukui)",
    "19": "Yamanasi (Yamanashi)",
    "20": "Nagano",
    "21": "Gihu  (Gifu)",
    "22": "Sizuoka (Shizuoka)",
    "23": "Aiti (Aichi)",
    "24": "Mie",
    "25": "Siga (Shiga)",
    "26": "Kyoto",
    "27": "Osaka",
    "28": "Hyogo",
    "29": "Nara",
    "30": "Wakayama",
    "31": "Tottori",
    "32": "Simane (Shimane)",
    "33": "Okayama",
    "34": "Hirosima (Hiroshima)",
    "35": "Yamaguti (Yamaguchi)",
    "36": "Tokusima (Tokushima)",
    "37": "Kagawa",
    "38": "Ehime",
    "39": "Koti (Kochi)",
    "40": "Hukuoka (Fukuoka)",
    "41": "Saga",
    "42": "Nagasaki",
    "43": "Kumamoto",
    "44": "Oita",
    "45": "Miyazaki",
    "46": "Kagosima (Kagoshima)",
    "47": "Okinawa"
  }
}
validation/data/iso_3166-2/UG.json000064400000005447147361033760012451 0ustar00{
  "source": "http://www.geonames.org/UG/administrative-division-uganda.html",
  "country": "Uganda",
  "subdivisions": {
    "101": "Kalangala",
    "102": "Kampala",
    "103": "Kiboga",
    "104": "Luwero",
    "105": "Masaka",
    "106": "Mpigi",
    "107": "Mubende",
    "108": "Mukono",
    "109": "Nakasongola",
    "110": "Rakai",
    "111": "Sembabule",
    "112": "Kayunga",
    "113": "Wakiso",
    "114": "Lyantonde",
    "115": "Mityana",
    "116": "Nakaseke",
    "117": "Buikwe",
    "118": "Bukomansimbi",
    "119": "Butambala",
    "120": "Buvuma",
    "121": "Gomba",
    "122": "Kalungu",
    "123": "Kyankwanzi",
    "124": "Lwengo",
    "125": "Kyotera",
    "201": "Bugiri",
    "202": "Busia",
    "203": "Iganga",
    "204": "Jinja",
    "205": "Kamuli",
    "206": "Kapchorwa",
    "207": "Katakwi",
    "208": "Kumi",
    "209": "Mbale",
    "210": "Pallisa",
    "211": "Soroti",
    "212": "Tororo",
    "213": "Kaberamaido",
    "214": "Mayuge",
    "215": "Sironko",
    "216": "Amuria",
    "217": "Budaka",
    "218": "Bududa",
    "219": "Bukedea",
    "220": "Bukwa",
    "221": "Butaleja",
    "222": "Kaliro",
    "223": "Manafwa",
    "224": "Namutumba",
    "225": "Bulambuli",
    "226": "Buyende",
    "227": "Kibuku",
    "228": "Kween",
    "229": "Luuka",
    "230": "Namayingo",
    "231": "Ngora",
    "232": "Serere",
    "233": "Butebo",
    "234": "Namisindwa",
    "301": "Adjumani",
    "302": "Apac",
    "303": "Arua",
    "304": "Gulu",
    "305": "Kitgum",
    "306": "Kotido",
    "307": "Lira",
    "308": "Moroto",
    "309": "Moyo",
    "310": "Nebbi",
    "311": "Nakapiripirit",
    "312": "Pader",
    "313": "Yumbe",
    "314": "Abim",
    "315": "Amolatar",
    "316": "Amuru",
    "317": "Dokolo",
    "318": "Kaabong",
    "319": "Koboko",
    "320": "Maracha",
    "321": "Oyam",
    "322": "Agago",
    "323": "Alebtong",
    "324": "Amudat",
    "325": "Kole",
    "326": "Lamwo",
    "327": "Napak",
    "328": "Nwoya",
    "329": "Otuke",
    "330": "Zombo",
    "331": "Omoro",
    "332": "Pakwach",
    "401": "Bundibugyo",
    "402": "Bushenyi",
    "403": "Hoima",
    "404": "Kabale",
    "405": "Kabarole",
    "406": "Kasese",
    "407": "Kibaale",
    "408": "Kisoro",
    "409": "Masindi",
    "410": "Mbarara",
    "411": "Ntungamo",
    "412": "Rukungiri",
    "413": "Kamwenge",
    "414": "Kanungu",
    "415": "Kyenjojo",
    "416": "Buliisa",
    "417": "Ibanda",
    "418": "Isingiro",
    "419": "Kiruhura",
    "420": "Buhweju",
    "421": "Kiryandongo",
    "422": "Kyegegwa",
    "423": "Mitoma",
    "424": "Ntoroko",
    "425": "Rubirizi",
    "426": "Sheema",
    "427": "Kagadi",
    "428": "Kakumiro",
    "429": "Rubanda",
    "430": "Bunyangabu",
    "431": "Rukiga",
    "C": "Central",
    "E": "Eastern",
    "N": "Northern",
    "W": "Western"
  }
}
validation/data/iso_3166-2/PN.json000064400000000222147361033760012435 0ustar00{
  "source": "http://www.geonames.org/PN/administrative-division-pitcairn-islands.html",
  "country": "Pitcairn Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/DE.json000064400000001034147361033760012412 0ustar00{
  "source": "http://www.geonames.org/DE/administrative-division-germany.html",
  "country": "Germany",
  "subdivisions": {
    "BB": "Brandenburg",
    "BE": "Berlin",
    "BW": "Baden-Württemberg",
    "BY": "Bayern",
    "HB": "Bremen",
    "HE": "Hessen",
    "HH": "Hamburg",
    "MV": "Mecklenburg-Vorpommern",
    "NI": "Niedersachsen",
    "NW": "Nordrhein-Westfalen",
    "RP": "Rheinland-Pfalz",
    "SH": "Schleswig-Holstein",
    "SL": "Saarland",
    "SN": "Sachsen",
    "ST": "Sachsen-Anhalt",
    "TH": "Thüringen"
  }
}
validation/data/iso_3166-2/AS.json000064400000000375147361033760012434 0ustar00{
  "source": "http://www.geonames.org/AS/administrative-division-american-samoa.html",
  "country": "American Samoa",
  "subdivisions": {
    "E": "Eastern",
    "M": "Manu'a",
    "R": "Rose Island",
    "S": "Swains Island",
    "W": "Western"
  }
}
validation/data/iso_3166-2/HM.json000064400000000433147361033760012430 0ustar00{
  "source": "http://www.geonames.org/HM/administrative-division-heard-island-and-mcdonald-islands.html",
  "country": "Heard Island and McDonald Islands",
  "subdivisions": {
    "F": "Flat Island",
    "H": "Heard Island",
    "M": "McDonald Island",
    "S": "Shag Island"
  }
}
validation/data/iso_3166-2/FI.json000064400000002424147361033760012424 0ustar00{
  "source": "http://www.geonames.org/FI/administrative-division-finland.html",
  "country": "Finland",
  "subdivisions": {
    "01": "Ahvenanmaa [Finnish] / Åland [Swedish]",
    "02": "Etelä-Karjala [Finnish] / Södra Karelen [Swedish]",
    "03": "Etelä-Pohjanmaa [Finnish] / Södra Österbotten [Swedish]",
    "04": "Etelä-Savo [Finnish] / Södra Savolax [Swedish]",
    "05": "Kainuu [Finnish] / Kajanaland [Swedish]",
    "06": "Kanta-Häme [Finnish] / Egentliga Tavastland [Swedish]",
    "07": "Keski-Pohjanmaa [Finnish] / Mellersta Österbotten [Swedish]",
    "08": "Keski-Suomi [Finnish] / Mellersta Finland [Swedish]",
    "09": "Kymenlaakso [Finnish] / Kymmenedalen [Swedish]",
    "10": "Lappi [Finnish] / Lappland [Swedish]",
    "11": "Pirkanmaa [Finnish] / Birkaland [Swedish]",
    "12": "Pohjanmaa [Finnish] / Österbotten [Swedish]",
    "13": "Pohjois-Karjala [Finnish] / Norra Karelen [Swedish]",
    "14": "Pohjois-Pohjanmaa [Finnish] / Norra Österbotten [Swedish]",
    "15": "Pohjois-Savo [Finnish] / Norra Savolax [Swedish]",
    "16": "Päijät-Häme [Finnish] / Päijänne-Tavastland [Swedish]",
    "17": "Satakunta [Finnish and Swedish]",
    "18": "Uusimaa [Finnish] / Nyland [Swedish]",
    "19": "Varsinais-Suomi [Finnish] / Egentliga Finland [Swedish]"
  }
}
validation/data/iso_3166-2/GH.json000064400000000645147361033760012427 0ustar00{
  "source": "http://www.geonames.org/GH/administrative-division-ghana.html",
  "country": "Ghana",
  "subdivisions": {
    "AA": "Greater Accra Region",
    "AH": "Ashanti Region",
    "BA": "Brong-Ahafo Region",
    "CP": "Central Region",
    "EP": "Eastern Region",
    "NP": "Northern Region",
    "TV": "Volta Region",
    "UE": "Upper East Region",
    "UW": "Upper West Region",
    "WP": "Western Region"
  }
}
validation/data/iso_3166-2/LT.json000064400000003344147361033760012447 0ustar00{
  "source": "http://www.geonames.org/LT/administrative-division-lithuania.html",
  "country": "Lithuania",
  "subdivisions": {
    "01": "Akmenė",
    "02": "Alytaus miestas",
    "03": "Alytus",
    "04": "Anykščiai",
    "05": "Birštono",
    "06": "Biržai",
    "07": "Druskininkai",
    "08": "Elektrėnai",
    "09": "Ignalina",
    "10": "Jonava",
    "11": "Joniškis",
    "12": "Jurbarkas",
    "13": "Kaišiadorys",
    "14": "Kalvarijos",
    "15": "Kauno miestas",
    "16": "Kaunas",
    "17": "Kazlų Rūdos",
    "18": "Kėdainiai",
    "19": "Kelmė",
    "20": "Klaipėdos miestas",
    "21": "Klaipėda",
    "22": "Kretinga",
    "23": "Kupiškis",
    "24": "Lazdijai",
    "25": "Marijampolė",
    "26": "Mažeikiai",
    "27": "Molėtai",
    "28": "Neringa",
    "29": "Pagėgiai",
    "30": "Pakruojis",
    "31": "Palangos miestas",
    "32": "Panevėžio miestas",
    "33": "Panevėžys",
    "34": "Pasvalys",
    "35": "Plungė",
    "36": "Prienai",
    "37": "Radviliškis",
    "38": "Raseiniai",
    "39": "Rietavo",
    "40": "Rokiškis",
    "41": "Šakiai",
    "42": "Šalčininkai",
    "43": "Šiaulių miestas",
    "44": "Šiauliai",
    "45": "Šilalė",
    "46": "Šilutė",
    "47": "Širvintos",
    "48": "Skuodas",
    "49": "Švenčionys",
    "50": "Tauragė",
    "51": "Telšiai",
    "52": "Trakai",
    "53": "Ukmergė",
    "54": "Utena",
    "55": "Varėna",
    "56": "Vilkaviškis",
    "57": "Vilniaus miestas",
    "58": "Vilnius",
    "59": "Visaginas",
    "60": "Zarasai",
    "AL": "Alytus",
    "KL": "Klaipeda",
    "KU": "Kaunas",
    "MR": "Marijampole",
    "PN": "Panevezys",
    "SA": "Siauliai",
    "TA": "Taurage",
    "TE": "Telsiai",
    "UT": "Utena",
    "VL": "Vilnius"
  }
}
validation/data/iso_3166-2/BE.json000064400000000710147361033760012410 0ustar00{
  "source": "http://www.geonames.org/BE/administrative-division-belgium.html",
  "country": "Belgium",
  "subdivisions": {
    "BRU": "Brussels",
    "VAN": "Antwerpen",
    "VBR": "Vlaams Brabant",
    "VLG": "Flemish Region",
    "VLI": "Limburg",
    "VOV": "Oost-Vlaanderen",
    "VWV": "West-Vlaanderen",
    "WAL": "Wallonia",
    "WBR": "Brabant Wallon",
    "WHT": "Hainaut",
    "WLG": "Liege",
    "WLX": "Luxembourg",
    "WNA": "Namur"
  }
}
validation/data/iso_3166-2/AN.json000064400000000232147361033760012417 0ustar00{
  "source": "http://www.geonames.org/AN/administrative-division-netherlands-antilles.html",
  "country": "Netherlands Antilles",
  "subdivisions": []
}
validation/data/iso_3166-2/ZA.json000064400000000550147361033760012436 0ustar00{
  "source": "http://www.geonames.org/ZA/administrative-division-south-africa.html",
  "country": "South Africa",
  "subdivisions": {
    "EC": "Eastern Cape",
    "FS": "Free State",
    "GT": "Gauteng",
    "LP": "Limpopo",
    "MP": "Mpumalanga",
    "NC": "Northern Cape",
    "NL": "KwaZulu-Natal",
    "NW": "North West",
    "WC": "Western Cape"
  }
}
validation/data/iso_3166-2/PG.json000064400000001262147361033760012433 0ustar00{
  "source": "http://www.geonames.org/PG/administrative-division-papua-new-guinea.html",
  "country": "Papua New Guinea",
  "subdivisions": {
    "CPK": "Chimbu",
    "CPM": "Central",
    "EBR": "East New Britain",
    "EHG": "Eastern Highlands",
    "EPW": "Enga",
    "ESW": "East Sepik",
    "GPK": "Gulf",
    "HLA": "Hela",
    "JWK": "Jiwaka",
    "MBA": "Milne Bay",
    "MPL": "Morobe",
    "MPM": "Madang",
    "MRL": "Manus",
    "NCD": "National Capital",
    "NIK": "New Ireland",
    "NPP": "Northern",
    "NSB": "Bougainville",
    "SAN": "Sandaun",
    "SHM": "Southern Highlands",
    "WBK": "West New Britain",
    "WHM": "Western Highlands",
    "WPD": "Western"
  }
}
validation/data/iso_3166-2/DO.json000064400000001673147361033760012435 0ustar00{
  "source": "http://www.geonames.org/DO/administrative-division-dominican-republic.html",
  "country": "Dominican Republic",
  "subdivisions": {
    "01": "Distrito Nacional",
    "02": "Azua",
    "03": "Baoruco",
    "04": "Barahona",
    "05": "Dajabon",
    "06": "Duarte",
    "07": "Elias Pina",
    "08": "El Seybo",
    "09": "Espaillat",
    "10": "Independencia",
    "11": "La Altagracia",
    "12": "La Romana",
    "13": "La Vega",
    "14": "Maria Trinidad Sanchez",
    "15": "Monte Cristi",
    "16": "Pedernales",
    "17": "Peravia (Bani)",
    "18": "Puerto Plata",
    "19": "Salcedo",
    "20": "Samana",
    "21": "San Cristobal",
    "22": "San Juan",
    "23": "San Pedro de Macoris",
    "24": "Sanchez Ramirez",
    "25": "Santiago",
    "26": "Santiago Rodriguez",
    "27": "Valverde",
    "28": "Monsenor Nouel",
    "29": "Monte Plata",
    "30": "Hato Mayor",
    "31": "San Jose de Ocoa",
    "32": "Santo Domingo"
  }
}
validation/data/iso_3166-2/CX.json000064400000000222147361033760012432 0ustar00{
  "source": "http://www.geonames.org/CX/administrative-division-christmas-island.html",
  "country": "Christmas Island",
  "subdivisions": []
}
validation/data/iso_3166-2/OM.json000064400000000640147361033760012437 0ustar00{
  "source": "http://www.geonames.org/OM/administrative-division-oman.html",
  "country": "Oman",
  "subdivisions": {
    "BJ": "Al Batinah South",
    "BS": "Shamāl al Bāţinah",
    "BU": "Al Buraymī",
    "DA": "Ad Dakhiliyah",
    "MA": "Masqat",
    "MU": "Musandam",
    "SJ": "Ash Sharqiyah South",
    "SS": "Shamāl ash Sharqīyah",
    "WU": "Al Wusta",
    "ZA": "Az Zahirah",
    "ZU": "Zufar"
  }
}
validation/data/iso_3166-2/GW.json000064400000000662147361033760012445 0ustar00{
  "source": "http://www.geonames.org/GW/administrative-division-guinea-bissau.html",
  "country": "Guinea-Bissau",
  "subdivisions": {
    "BA": "Bafata Region",
    "BL": "Bolama Region",
    "BM": "Biombo Region",
    "BS": "Bissau Region",
    "CA": "Cacheu Region",
    "GA": "Gabu Region",
    "L": "Leste",
    "N": "Norte",
    "OI": "Oio Region",
    "QU": "Quinara Region",
    "S": "Sul",
    "TO": "Tombali Region"
  }
}
validation/data/iso_3166-2/MX.json000064400000001602147361033760012447 0ustar00{
  "source": "http://www.geonames.org/MX/administrative-division-mexico.html",
  "country": "Mexico",
  "subdivisions": {
    "AGU": "Aguascalientes",
    "BCN": "Baja California",
    "BCS": "Baja California Sur",
    "CAM": "Campeche",
    "CHH": "Chihuahua",
    "CHP": "Chiapas",
    "CMX": "Ciudad de Mexico",
    "COA": "Coahuila",
    "COL": "Colima",
    "DUR": "Durango",
    "GRO": "Guerrero",
    "GUA": "Guanajuato",
    "HID": "Hidalgo",
    "JAL": "Jalisco",
    "MEX": "Mexico",
    "MIC": "Michoacan",
    "MOR": "Morelos",
    "NAY": "Nayarit",
    "NLE": "Nuevo Leon",
    "OAX": "Oaxaca",
    "PUE": "Puebla",
    "QUE": "Queretaro",
    "ROO": "Quintana Roo",
    "SIN": "Sinaloa",
    "SLP": "San Luis Potosi",
    "SON": "Sonora",
    "TAB": "Tabasco",
    "TAM": "Tamaulipas",
    "TLA": "Tlaxcala",
    "VER": "Veracruz",
    "YUC": "Yucatan",
    "ZAC": "Zacatecas"
  }
}
validation/data/iso_3166-2/GS.json000064400000000312147361033760012431 0ustar00{
  "source": "http://www.geonames.org/GS/administrative-division-south-georgia-and-the-south-sandwich-islands.html",
  "country": "South Georgia and the South Sandwich Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/MG.json000064400000000206147361033760012425 0ustar00{
  "source": "http://www.geonames.org/MG/administrative-division-madagascar.html",
  "country": "Madagascar",
  "subdivisions": []
}
validation/data/iso_3166-2/BW.json000064400000000753147361033760012441 0ustar00{
  "source": "http://www.geonames.org/BW/administrative-division-botswana.html",
  "country": "Botswana",
  "subdivisions": {
    "CE": "Central",
    "CH": "Chobe",
    "FR": "Francistown",
    "GA": "Gaborone",
    "GH": "Ghanzi",
    "JW": "Jwaneng",
    "KG": "Kgalagadi",
    "KL": "Kgatleng",
    "KW": "Kweneng",
    "LO": "Lobatse",
    "NE": "North East",
    "NW": "North West",
    "SE": "South East",
    "SO": "Southern",
    "SP": "Selibe Phikwe",
    "ST": "Sowa Town"
  }
}
validation/data/iso_3166-2/IE.json000064400000001367147361033760012430 0ustar00{
  "source": "http://www.geonames.org/IE/administrative-division-ireland.html",
  "country": "Ireland",
  "subdivisions": {
    "C": "Connaught",
    "CE": "Clare",
    "CN": "Cavan",
    "CO": "Cork",
    "CW": "Carlow",
    "DL": "Donegal",
    "G": "Galway",
    "KE": "Kildare",
    "KK": "Kilkenny",
    "KY": "Kerry",
    "L": "Leinster",
    "LD": "Longford",
    "LH": "Louth",
    "LK": "Limerick, City and County",
    "LM": "Leitrim",
    "LS": "Laois",
    "M": "Munster",
    "MH": "Meath",
    "MN": "Monaghan",
    "MO": "Mayo",
    "OY": "Offaly",
    "RN": "Roscommon",
    "SO": "Sligo",
    "TA": "Tipperary",
    "U": "Ulster",
    "WD": "Waterford, City and County",
    "WH": "Westmeath",
    "WW": "Wicklow",
    "WX": "Wexford"
  }
}
validation/data/iso_3166-2/CS.json000064400000000371147361033760012432 0ustar00{
  "source": "http://www.geonames.org/CS/administrative-division-serbia-and-montenegro.html",
  "country": "Serbia And Montenegro",
  "subdivisions": {
    "KOS": "Kosovo",
    "MON": "Montenegro",
    "SER": "Serbia",
    "VOJ": "Vojvodina"
  }
}
validation/data/iso_3166-2/SY.json000064400000000664147361033760012465 0ustar00{
  "source": "http://www.geonames.org/SY/administrative-division-syria.html",
  "country": "Syria",
  "subdivisions": {
    "DI": "Dimashq",
    "DR": "Dara",
    "DY": "Dayr az Zawr",
    "HA": "Al Hasakah",
    "HI": "Hims",
    "HL": "Halab",
    "HM": "Hamah",
    "ID": "Idlib",
    "LA": "Al Ladhiqiyah",
    "QU": "Al Qunaytirah",
    "RA": "Ar Raqqah",
    "RD": "Rif Dimashq",
    "SU": "As Suwayda",
    "TA": "Tartus"
  }
}
validation/data/iso_3166-2/SX.json000064400000000212147361033760012451 0ustar00{
  "source": "http://www.geonames.org/SX/administrative-division-sint-maarten.html",
  "country": "Sint Maarten",
  "subdivisions": []
}
validation/data/iso_3166-2/EE.json000064400000001033147361033760012412 0ustar00{
  "source": "http://www.geonames.org/EE/administrative-division-estonia.html",
  "country": "Estonia",
  "subdivisions": {
    "37": "Harju County",
    "39": "Hiiu County",
    "44": "Ida-Viru County",
    "49": "Jõgeva County",
    "51": "Järva County",
    "57": "Lääne County",
    "59": "Lääne-Viru County",
    "65": "Põlva County",
    "67": "Pärnu County",
    "70": "Rapla County",
    "74": "Saare County",
    "78": "Tartu County",
    "82": "Valga County",
    "84": "Viljandi County",
    "86": "Võru County"
  }
}
validation/data/iso_3166-2/CV.json000064400000001413147361033760012433 0ustar00{
  "source": "http://www.geonames.org/CV/administrative-division-cape-verde.html",
  "country": "Cape Verde",
  "subdivisions": {
    "B": "Ilhas de Barlavento",
    "BR": "Brava",
    "BV": "Boa Vista",
    "CA": "Santa Catarina",
    "CF": "Santa Catarina do Fogo",
    "CR": "Santa Cruz",
    "MA": "Maio",
    "MO": "Mosteiros",
    "PA": "Paul",
    "PN": "Porto Novo",
    "PR": "Praia",
    "RB": "Ribeira Brava",
    "RG": "Ribeira Grande",
    "RS": "Ribeira Grande de Santiago",
    "S": "Ilhas de Sotavento",
    "SD": "Sao Domingos",
    "SF": "Sao Filipe",
    "SL": "Sal",
    "SM": "São Miguel",
    "SO": "São Lourenço dos Orgãos",
    "SS": "São Salvador do Mundo",
    "SV": "Sao Vicente",
    "TA": "Tarrafal",
    "TS": "Tarrafal de São Nicolau"
  }
}
validation/data/iso_3166-2/ET.json000064400000000637147361033760012442 0ustar00{
  "source": "http://www.geonames.org/ET/administrative-division-ethiopia.html",
  "country": "Ethiopia",
  "subdivisions": {
    "AA": "Addis Ababa",
    "AF": "Afar",
    "AM": "Amhara",
    "BE": "Benishangul-Gumaz",
    "DD": "Dire Dawa",
    "GA": "Gambela",
    "HA": "Hariai",
    "OR": "Oromia",
    "SN": "Southern Nations - Nationalities and Peoples Region",
    "SO": "Somali",
    "TI": "Tigray"
  }
}
validation/data/iso_3166-2/MR.json000064400000000767147361033760012454 0ustar00{
  "source": "http://www.geonames.org/MR/administrative-division-mauritania.html",
  "country": "Mauritania",
  "subdivisions": {
    "01": "Hodh Ech Chargui",
    "02": "Hodh El Gharbi",
    "03": "Assaba",
    "04": "Gorgol",
    "05": "Brakna",
    "06": "Trarza",
    "07": "Adrar",
    "08": "Dakhlet Nouadhibou",
    "09": "Tagant",
    "10": "Guidimaka",
    "11": "Tiris Zemmour",
    "12": "Inchiri",
    "13": "Nouakchott-Ouest",
    "14": "Nouakchott-Nord",
    "15": "Nouakchott-Sud"
  }
}
validation/data/iso_3166-2/HK.json000064400000001471147361033760012431 0ustar00{
  "source": "http://www.geonames.org/HK/administrative-division-hong-kong.html",
  "country": "Hong Kong",
  "subdivisions": {
    "HCW": "Central and Western Hong Kong Island",
    "HEA": "Eastern Hong Kong Island",
    "HSO": "Southern Hong Kong Island",
    "HWC": "Wan Chai Hong Kong Island",
    "KKC": "Kowloon City Kowloon",
    "KKT": "Kwun Tong Kowloon",
    "KSS": "Sham Shui Po Kowloon",
    "KWT": "Wong Tai Sin Kowloon",
    "KYT": "Yau Tsim Mong Kowloon",
    "NIS": "Islands New Territories",
    "NKT": "Kwai Tsing New Territories",
    "NNO": "North New Territories",
    "NSK": "Sai Kung New Territories",
    "NST": "Sha Tin New Territories",
    "NTM": "Tuen Mun New Territories",
    "NTP": "Tai Po New Territories",
    "NTW": "Tsuen Wan New Territories",
    "NYL": "Yuen Long New Territories"
  }
}
validation/data/iso_3166-2/MK.json000064400000004054147361033760012436 0ustar00{
  "source": "http://www.geonames.org/MK/administrative-division-macedonia.html",
  "country": "Macedonia",
  "subdivisions": {
    "01": "Aerodrom †",
    "02": "Aračinovo",
    "03": "Berovo",
    "04": "Bitola",
    "05": "Bogdanci",
    "06": "Bogovinje",
    "07": "Bosilovo",
    "08": "Brvenica",
    "09": "Butel †",
    "10": "Valandovo",
    "11": "Vasilevo",
    "12": "Vevčani",
    "13": "Veles",
    "14": "Vinica",
    "15": "Vraneštica",
    "16": "Vrapčište",
    "17": "Gazi Baba †",
    "18": "Gevgelija",
    "19": "Gostivar",
    "20": "Gradsko",
    "21": "Debar",
    "22": "Debarca",
    "23": "Delčevo",
    "24": "Demir Kapija",
    "25": "Demir Hisar",
    "26": "Dojran",
    "27": "Dolneni",
    "28": "Drugovo",
    "29": "Gjorče Petrov †",
    "30": "Želino",
    "31": "Zajas",
    "32": "Zelenikovo",
    "33": "Zrnovci",
    "34": "Ilinden",
    "35": "Jegunovce",
    "36": "Kavadarci",
    "37": "Karbinci",
    "38": "Karpoš †",
    "39": "Kisela Voda †",
    "40": "Kičevo",
    "41": "Konče",
    "42": "Kočani",
    "43": "Kratovo",
    "44": "Kriva Palanka",
    "45": "Krivogaštani",
    "46": "Kruševo",
    "47": "Kumanovo",
    "48": "Lipkovo",
    "49": "Lozovo",
    "50": "Mavrovo-i-Rostuša",
    "51": "Makedonska Kamenica",
    "52": "Makedonski Brod",
    "53": "Mogila",
    "54": "Negotino",
    "55": "Novaci",
    "56": "Novo Selo",
    "57": "Oslomej",
    "58": "Ohrid",
    "59": "Petrovec",
    "60": "Pehčevo",
    "61": "Plasnica",
    "62": "Prilep",
    "63": "Probištip",
    "64": "Radoviš",
    "65": "Rankovce",
    "66": "Resen",
    "67": "Rosoman",
    "68": "Saraj †",
    "69": "Sveti Nikole",
    "70": "Štip",
    "71": "Struga",
    "72": "Strumica",
    "73": "Studeničani",
    "74": "Šuto Orizari †",
    "75": "Tearce",
    "76": "Tetovo",
    "77": "Centar †",
    "78": "Centar Župa",
    "79": "Čair †",
    "80": "Čaška",
    "81": "Češinovo-Obleševo",
    "82": "Čučer Sandevo",
    "83": "Sopište",
    "84": "Staro Nagoričane",
    "85": "Skopje"
  }
}
validation/data/iso_3166-2/TG.json000064400000000340147361033760012433 0ustar00{
  "source": "http://www.geonames.org/TG/administrative-division-togo.html",
  "country": "Togo",
  "subdivisions": {
    "C": "Centrale",
    "K": "Kara",
    "M": "Maritime",
    "P": "Plateaux",
    "S": "Savanes"
  }
}
validation/data/iso_3166-2/GT.json000064400000001223147361033760012434 0ustar00{
  "source": "http://www.geonames.org/GT/administrative-division-guatemala.html",
  "country": "Guatemala",
  "subdivisions": {
    "AV": "Alta Verapaz",
    "BV": "Baja Verapaz",
    "CM": "Chimaltenango",
    "CQ": "Chiquimula",
    "ES": "Escuintla",
    "GU": "Guatemala",
    "HU": "Huehuetenango",
    "IZ": "Izabal",
    "JA": "Jalapa",
    "JU": "Jutiapa",
    "PE": "El Peten",
    "PR": "El Progreso",
    "QC": "El Quiche",
    "QZ": "Quetzaltenango",
    "RE": "Retalhuleu",
    "SA": "Sacatepequez",
    "SM": "San Marcos",
    "SO": "Solola",
    "SR": "Santa Rosa",
    "SU": "Suchitepequez",
    "TO": "Totonicapan",
    "ZA": "Zacapa"
  }
}
validation/data/iso_3166-2/KN.json000064400000001272147361033760012436 0ustar00{
  "source": "http://www.geonames.org/KN/administrative-division-saint-kitts-and-nevis.html",
  "country": "Saint Kitts and Nevis",
  "subdivisions": {
    "01": "Christ Church Nichola Town",
    "02": "Saint Anne Sandy Point",
    "03": "Saint George Basseterre",
    "04": "Saint George Gingerland",
    "05": "Saint James Windward",
    "06": "Saint John Capesterre",
    "07": "Saint John Figtree",
    "08": "Saint Mary Cayon",
    "09": "Saint Paul Capesterre",
    "10": "Saint Paul Charlestown",
    "11": "Saint Peter Basseterre",
    "12": "Saint Thomas Lowland",
    "13": "Saint Thomas Middle Island",
    "15": "Trinity Palmetto Point",
    "K": "Saint Kitts",
    "N": "Nevis"
  }
}
validation/data/iso_3166-2/UM.json000064400000000644147361033760012451 0ustar00{
  "source": "http://www.geonames.org/UM/administrative-division-united-states-minor-outlying-islands.html",
  "country": "U.S. Minor Outlying Islands",
  "subdivisions": {
    "67": "Johnston Atoll",
    "71": "Midway Atoll",
    "76": "Navassa Island",
    "79": "Wake Island",
    "81": "Baker Island",
    "84": "Howland Island",
    "86": "Jarvis Island",
    "89": "Kingman Reef",
    "95": "Palmyra Atoll"
  }
}
validation/data/iso_3166-2/QA.json000064400000000521147361033760012423 0ustar00{
  "source": "http://www.geonames.org/QA/administrative-division-qatar.html",
  "country": "Qatar",
  "subdivisions": {
    "DA": "Ad Dawhah",
    "KH": "Al Khawr wa adh Dhakhīrah",
    "MS": "Ash Shamāl",
    "RA": "Ar Rayyan",
    "SH": "Al-Shahaniya",
    "US": "Umm Salal",
    "WA": "Al Wakrah",
    "ZA": "Az Z a‘āyin"
  }
}
validation/data/iso_3166-2/MV.json000064400000001774147361033760012457 0ustar00{
  "source": "http://www.geonames.org/MV/administrative-division-maldives.html",
  "country": "Maldives",
  "subdivisions": {
    "00": "Alifu Dhaalu / Ari Atholhu Dhekunuburi",
    "01": "Seenu / Addu Atholhu",
    "02": "Alifu Alifu / Ari Atholhu Uthuruburi",
    "03": "Lhaviyani / Faadhippolhu",
    "04": "Vaavu / Felidhu Atholhu",
    "05": "Laamu / Haddhdhunmathi",
    "07": "Haa Alifu / Thiladhunmathee Uthuruburi",
    "08": "Thaa / Kolhumadulu",
    "12": "Meemu / Mulakatholhu",
    "13": "Raa / Maalhosmadulu Uthuruburi",
    "14": "Faafu / Nilandhe Atholhu Uthuruburi",
    "17": "Dhaalu / Nilandhe Atholhu Dhekunuburi",
    "20": "Baa / Maalhosmadulu Dhekunuburi",
    "23": "Haa Dhaalu / Thiladhunmathee Dhekunuburi",
    "24": "Shaviyani / Miladhunmadulu Uthuruburi",
    "25": "Noonu / Miladhunmadulu Dhekunuburi",
    "26": "Kaafu / Maale Atholhu",
    "27": "Gaafu Alifu / Huvadhu Atholhu Uthuruburi",
    "28": "Gaafu Dhaalu / Huvadhu Atholhu Dhekunuburi",
    "29": "Gnaviyani / Fuvammulah"
  }
}
validation/data/iso_3166-2/KW.json000064400000000424147361033760012445 0ustar00{
  "source": "http://www.geonames.org/KW/administrative-division-kuwait.html",
  "country": "Kuwait",
  "subdivisions": {
    "AH": "Al Ahmadi",
    "FA": "Al Farwaniyah",
    "HA": "Hawalli",
    "JA": "Al Jahra",
    "KU": "Al Asimah",
    "MU": "Mubārak al Kabīr"
  }
}
validation/data/iso_3166-2/AW.json000064400000000174147361033760012435 0ustar00{
  "source": "http://www.geonames.org/AW/administrative-division-aruba.html",
  "country": "Aruba",
  "subdivisions": []
}
validation/data/iso_3166-2/MQ.json000064400000000206147361033760012437 0ustar00{
  "source": "http://www.geonames.org/MQ/administrative-division-martinique.html",
  "country": "Martinique",
  "subdivisions": []
}
validation/data/iso_3166-2/PK.json000064400000000566147361033760012445 0ustar00{
  "source": "http://www.geonames.org/PK/administrative-division-pakistan.html",
  "country": "Pakistan",
  "subdivisions": {
    "BA": "Balochistan",
    "GB": "Gilgit-Baltistan",
    "IS": "Islamabad Capital Territory",
    "JK": "Azad Kashmir",
    "KP": "Khyber Pakhtunkhwa",
    "PB": "Punjab",
    "SD": "Sindh",
    "TA": "Federally Administered Tribal Areas"
  }
}
validation/data/iso_3166-2/LY.json000064400000001231147361033760012445 0ustar00{
  "source": "http://www.geonames.org/LY/administrative-division-libya.html",
  "country": "Libya",
  "subdivisions": {
    "BA": "Banghazi",
    "BU": "Al Buţnān",
    "DR": "Darnah",
    "GT": "Ghāt",
    "JA": "Al Jabal al Akhdar",
    "JG": "Al Jabal al Gharbī",
    "JI": "Al Jifārah",
    "JU": "Al Jufrah",
    "KF": "Al Kufrah",
    "MB": "Al Marqab",
    "MI": "Misratah",
    "MJ": "Al Maraj",
    "MQ": "Murzuq",
    "NL": "Nālūt",
    "NQ": "An Nuqat al Khams",
    "SB": "Sabha",
    "SR": "Surt",
    "TB": "Ţarābulus",
    "WA": "Al Wāḩāt",
    "WD": "Wādī al Ḩayāt",
    "WS": "Wādī ash Shāţi´",
    "ZA": "Az Zawiyah"
  }
}
validation/data/iso_3166-2/CA.json000064400000000736147361033760012415 0ustar00{
  "source": "http://www.geonames.org/CA/administrative-division-canada.html",
  "country": "Canada",
  "subdivisions": {
    "AB": "Alberta",
    "BC": "British Columbia",
    "MB": "Manitoba",
    "NB": "New Brunswick",
    "NL": "Newfoundland and Labrador",
    "NS": "Nova Scotia",
    "NT": "Northwest Territories",
    "NU": "Nunavut",
    "ON": "Ontario",
    "PE": "Prince Edward Island",
    "QC": "Quebec",
    "SK": "Saskatchewan",
    "YT": "Yukon Territory"
  }
}
validation/data/iso_3166-2/SN.json000064400000000655147361033760012452 0ustar00{
  "source": "http://www.geonames.org/SN/administrative-division-senegal.html",
  "country": "Senegal",
  "subdivisions": {
    "DB": "Diourbel",
    "DK": "Dakar",
    "FK": "Fatick",
    "KA": "Kaffrine",
    "KD": "Kolda",
    "KE": "Kédougou",
    "KL": "Kaolack",
    "LG": "Louga",
    "MT": "Matam",
    "SE": "Sédhiou",
    "SL": "Saint-Louis",
    "TC": "Tambacounda",
    "TH": "Thies",
    "ZG": "Ziguinchor"
  }
}
validation/data/iso_3166-2/CL.json000064400000001170147361033760012421 0ustar00{
  "source": "http://www.geonames.org/CL/administrative-division-chile.html",
  "country": "Chile",
  "subdivisions": {
    "AI": "Aisen del General Carlos Ibanez del Campo (XI)",
    "AN": "Antofagasta (II)",
    "AP": "Arica y Parinacota",
    "AR": "Araucania (IX)",
    "AT": "Atacama (III)",
    "BI": "Bio-Bio (VIII)",
    "CO": "Coquimbo (IV)",
    "LI": "Libertador General Bernardo O'Higgins (VI)",
    "LL": "Los Lagos (X)",
    "LR": "Los Ríos",
    "MA": "Magallanes (XII)",
    "ML": "Maule (VII)",
    "NB": "Ñuble",
    "RM": "Region Metropolitana (RM)",
    "TA": "Tarapaca (I)",
    "VS": "Valparaiso (V)"
  }
}
validation/data/iso_3166-2/BM.json000064400000000601147361033760012417 0ustar00{
  "source": "http://www.geonames.org/BM/administrative-division-bermuda.html",
  "country": "Bermuda",
  "subdivisions": {
    "DS": "Devonshire",
    "GC": "Saint George",
    "HA": "Hamilton",
    "HC": "Hamilton City",
    "PB": "Pembroke",
    "PG": "Paget",
    "SA": "Sandys",
    "SG": "Saint George's",
    "SH": "Southampton",
    "SM": "Smith's",
    "WA": "Warwick"
  }
}
validation/data/iso_3166-2/IQ.json000064400000001013147361033760012430 0ustar00{
  "source": "http://www.geonames.org/IQ/administrative-division-iraq.html",
  "country": "Iraq",
  "subdivisions": {
    "AN": "Al Anbar",
    "AR": "Arbīl",
    "BA": "Al Basrah",
    "BB": "Babil",
    "BG": "Baghdad",
    "DA": "Dahūk",
    "DI": "Diyala",
    "DQ": "Dhi Qar",
    "KA": "Al Karbala",
    "KI": "Kirkūk",
    "MA": "Maysan",
    "MU": "Al Muthanna",
    "NA": "An Najaf",
    "NI": "Ninawa",
    "QA": "Al Qadisyah",
    "SD": "Salah ad Din",
    "SU": "As Sulaymānīyah",
    "WA": "Wasit"
  }
}
validation/data/iso_3166-2/VI.json000064400000000341147361033760012440 0ustar00{
  "source": "http://www.geonames.org/VI/administrative-division-u-s-virgin-islands.html",
  "country": "U.S. Virgin Islands",
  "subdivisions": {
    "C": "Saint Croix",
    "J": "Saint John",
    "T": "Saint Thomas"
  }
}
validation/data/iso_3166-2/RU.json000064400000004015147361033760012452 0ustar00{
  "source": "http://www.geonames.org/RU/administrative-division-russia.html",
  "country": "Russia",
  "subdivisions": {
    "AD": "Adygeya",
    "AL": "Altai Republic",
    "ALT": "Altai Krai",
    "AMU": "Amur",
    "ARK": "Arkhangelsk",
    "AST": "Astrakhan",
    "BA": "Bashkortostan",
    "BEL": "Belgorod",
    "BRY": "Bryansk",
    "BU": "Buryatia",
    "CE": "Chechnya",
    "CHE": "Chelyabinsk",
    "CHU": "Chukotka",
    "CU": "Chuvashia",
    "DA": "Dagestan",
    "IN": "Ingushetia",
    "IRK": "Irkutsk",
    "IVA": "Ivanovo",
    "KAM": "Kamchatka",
    "KB": "Kabardino-Balkaria",
    "KC": "Karachay-Cherkessia",
    "KDA": "Krasnodar",
    "KEM": "Kemerovo",
    "KGD": "Kaliningrad",
    "KGN": "Kurgan",
    "KHA": "Khabarovsk",
    "KHM": "Khantia-Mansia",
    "KIR": "Kirov",
    "KK": "Khakassia",
    "KL": "Kalmykia",
    "KLU": "Kaluga",
    "KO": "Komi",
    "KOS": "Kostroma",
    "KR": "Karelia",
    "KRS": "Kursk",
    "KYA": "Krasnoyarsk",
    "LEN": "Leningrad",
    "LIP": "Lipetsk",
    "MAG": "Magadan",
    "ME": "Mari El",
    "MO": "Mordovia",
    "MOS": "Moscow (Province)",
    "MOW": "Moscow (City)",
    "MUR": "Murmansk",
    "NEN": "Nenetsia",
    "NGR": "Novgorod",
    "NIZ": "Nizhny Novgorod",
    "NVS": "Novosibirsk",
    "OMS": "Omsk",
    "ORE": "Orenburg",
    "ORL": "Oryol",
    "PER": "Perm",
    "PNZ": "Penza",
    "PRI": "Primorsky",
    "PSK": "Pskov",
    "ROS": "Rostov",
    "RYA": "Ryazan",
    "SA": "Sakha",
    "SAK": "Sakhalin",
    "SAM": "Samara",
    "SAR": "Saratov",
    "SE": "North Ossetia",
    "SMO": "Smolensk",
    "SPE": "St. Petersburg",
    "STA": "Stavropol",
    "SVE": "Sverdlovsk",
    "TA": "Tatarstan",
    "TAM": "Tambov",
    "TOM": "Tomsk",
    "TUL": "Tula",
    "TVE": "Tver",
    "TY": "Tuva",
    "TYU": "Tyumen",
    "UD": "Udmurtia",
    "ULY": "Ulynovsk",
    "VGG": "Volgograd",
    "VLA": "Vladimir",
    "VLG": "Vologda",
    "VOR": "Voronezh",
    "YAN": "Yamalia",
    "YAR": "Yaroslavl",
    "YEV": "Jewish Oblast",
    "ZAB": "Zabaykal'skiy kray"
  }
}
validation/data/iso_3166-2/GD.json000064400000000502147361033760012413 0ustar00{
  "source": "http://www.geonames.org/GD/administrative-division-grenada.html",
  "country": "Grenada",
  "subdivisions": {
    "01": "Saint Andrew",
    "02": "Saint David",
    "03": "Saint George",
    "04": "Saint John",
    "05": "Saint Mark",
    "06": "Saint Patrick",
    "10": "Southern Grenadine Islands"
  }
}
validation/data/iso_3166-2/DK.json000064400000000436147361033760012425 0ustar00{
  "source": "http://www.geonames.org/DK/administrative-division-denmark.html",
  "country": "Denmark",
  "subdivisions": {
    "81": "Region Nordjylland",
    "82": "Region Midtjylland",
    "83": "Region Syddanmark",
    "84": "Region Hovedstaden",
    "85": "Region Sjæland"
  }
}
validation/data/iso_3166-2/ZM.json000064400000000656147361033760012461 0ustar00{
  "source": "http://www.geonames.org/ZM/administrative-division-zambia.html",
  "country": "Zambia",
  "subdivisions": {
    "01": "Western Province",
    "02": "Central Province",
    "03": "Eastern Province",
    "04": "Luapula Province",
    "05": "Northern Province",
    "06": "North-Western Province",
    "07": "Southern Province",
    "08": "Copperbelt Province",
    "09": "Lusaka Province",
    "10": "Muchinga"
  }
}
validation/data/iso_3166-2/VU.json000064400000000375147361033760012463 0ustar00{
  "source": "http://www.geonames.org/VU/administrative-division-vanuatu.html",
  "country": "Vanuatu",
  "subdivisions": {
    "MAP": "Malampa",
    "PAM": "Penama",
    "SAM": "Sanma",
    "SEE": "Shefa",
    "TAE": "Tafea",
    "TOB": "Torba"
  }
}
validation/data/iso_3166-2/GA.json000064400000000520147361033760012410 0ustar00{
  "source": "http://www.geonames.org/GA/administrative-division-gabon.html",
  "country": "Gabon",
  "subdivisions": {
    "1": "Estuaire",
    "2": "Haut-Ogooue",
    "3": "Moyen-Ogooue",
    "4": "Ngounie",
    "5": "Nyanga",
    "6": "Ogooue-Ivindo",
    "7": "Ogooue-Lolo",
    "8": "Ogooue-Maritime",
    "9": "Woleu-Ntem"
  }
}
validation/data/iso_3166-2/UA.json000064400000001337147361033760012435 0ustar00{
  "source": "http://www.geonames.org/UA/administrative-division-ukraine.html",
  "country": "Ukraine",
  "subdivisions": {
    "05": "Vinnytsya",
    "07": "Volyn'",
    "09": "Luhans'k",
    "12": "Dnipropetrovs'k",
    "14": "Donets'k",
    "18": "Zhytomyr",
    "21": "Zakarpattya",
    "23": "Zaporizhzhya",
    "26": "Ivano-Frankivs'k",
    "30": "Kyyiv",
    "32": "Kiev",
    "35": "Kirovohrad",
    "40": "Sevastopol",
    "43": "Crimea",
    "46": "L'viv",
    "48": "Mykolayiv",
    "51": "Odesa",
    "53": "Poltava",
    "56": "Rivne",
    "59": "Sumy",
    "61": "Ternopil'",
    "63": "Kharkiv",
    "65": "Kherson",
    "68": "Khmel'nyts'kyy",
    "71": "Cherkasy",
    "74": "Chernihiv",
    "77": "Chernivtsi"
  }
}
validation/data/iso_3166-2/KM.json000064400000000303147361033760012427 0ustar00{
  "source": "http://www.geonames.org/KM/administrative-division-comoros.html",
  "country": "Comoros",
  "subdivisions": {
    "A": "Anjouan",
    "G": "Grande Comore",
    "M": "Moheli"
  }
}
validation/data/iso_3166-2/CK.json000064400000000723147361033760012423 0ustar00{
  "source": "http://www.geonames.org/CK/administrative-division-cook-islands.html",
  "country": "Cook Islands",
  "subdivisions": {
    "AI": "Aitutaki",
    "AT": "Atiu",
    "MA": "Manuae",
    "MG": "Mangaia",
    "MK": "Manihiki",
    "MT": "Mitiaro",
    "MU": "Mauke",
    "NI": "Nassau Island",
    "PA": "Palmerston",
    "PE": "Penrhyn",
    "PU": "Pukapuka",
    "RK": "Rakahanga",
    "RR": "Rarotonga",
    "SU": "Surwarrow",
    "TA": "Takutea"
  }
}
validation/data/iso_3166-2/ES.json000064400000003730147361033760012436 0ustar00{
  "source": "http://www.geonames.org/ES/administrative-division-spain.html",
  "country": "Spain",
  "subdivisions": {
    "A": "Alicante",
    "AB": "Albacete",
    "AL": "Almería",
    "AN": "Comunidad Autónoma de Andalucía",
    "AR": "Comunidad Autónoma de Aragón",
    "AS": "Comunidad Autónoma del Principado de Asturias",
    "AV": "Ávila",
    "B": "Barcelona",
    "BA": "Badajoz",
    "BI": "Vizcaya",
    "BU": "Burgos",
    "C": "A Coruña",
    "CA": "Cádiz",
    "CB": "Comunidad Autónoma de Cantabria",
    "CC": "Cáceres",
    "CE": "Ceuta",
    "CL": "Comunidad Autónoma de Castilla y León",
    "CM": "Comunidad Autónoma de Castilla-La Mancha",
    "CN": "Comunidad Autónoma de Canarias",
    "CO": "Córdoba",
    "CR": "Ciudad Real",
    "CS": "Castellón",
    "CT": "Catalunya",
    "CU": "Cuenca",
    "EX": "Comunidad Autónoma de Extremadura",
    "GA": "Comunidad Autónoma de Galicia",
    "GC": "Las Palmas",
    "GI": "Girona",
    "GR": "Granada",
    "GU": "Guadalajara",
    "H": "Huelva",
    "HU": "Huesca",
    "IB": "Comunidad Autónoma de las Islas Baleares",
    "J": "Jaén",
    "L": "Lleida",
    "LE": "León",
    "LO": "La Rioja",
    "LU": "Lugo",
    "M": "Madrid",
    "MA": "Málaga",
    "MC": "Comunidad Autónoma de la Región de Murcia",
    "MD": "Comunidad de Madrid",
    "ML": "Melilla",
    "MU": "Murcia",
    "NA": "Navarra",
    "NC": "Comunidad Foral de Navarra",
    "O": "Asturias",
    "OR": "Ourense",
    "P": "Palencia",
    "PM": "Baleares",
    "PO": "Pontevedra",
    "PV": "Euskal Autonomia Erkidegoa",
    "RI": "Comunidad Autónoma de La Rioja",
    "S": "Cantabria",
    "SA": "Salamanca",
    "SE": "Sevilla",
    "SG": "Segovia",
    "SO": "Soria",
    "SS": "Guipúzcoa",
    "T": "Tarragona",
    "TE": "Teruel",
    "TF": "Santa Cruz de Tenerife",
    "TO": "Toledo",
    "V": "Valencia",
    "VA": "Valladolid",
    "VC": "Comunidad Valenciana",
    "VI": "Álava",
    "Z": "Zaragoza",
    "ZA": "Zamora"
  }
}
validation/data/iso_3166-2/WF.json000064400000000317147361033760012441 0ustar00{
  "source": "http://www.geonames.org/WF/administrative-division-wallis-and-futuna.html",
  "country": "Wallis and Futuna",
  "subdivisions": {
    "AL": "Alo",
    "SG": "Sigave",
    "UV": "ʻUvea"
  }
}
validation/data/iso_3166-2/IM.json000064400000000210147361033760012422 0ustar00{
  "source": "http://www.geonames.org/IM/administrative-division-isle-of-man.html",
  "country": "Isle of Man",
  "subdivisions": []
}
validation/data/iso_3166-2/MA.json000064400000004454147361033760012430 0ustar00{
  "source": "http://www.geonames.org/MA/administrative-division-morocco.html",
  "country": "Morocco",
  "subdivisions": {
    "01": "Tanger-Tetouan-Al Hoceima",
    "02": "Oriental",
    "03": "Fès-Meknès",
    "04": "Rabat-Salé-Kénitra",
    "05": "Béni Mellal-Khénifra",
    "06": "Casablanca-Settat",
    "07": "Marrakesh-Safi",
    "08": "Drâa-Tafilalet",
    "09": "Souss-Massa",
    "10": "Guelmim-Oued Noun",
    "11": "Laâyoune-Sakia El Hamra",
    "12": "Dakhla-Oued Ed-Dahab",
    "AGD": "Agadir-Ida-Outanane",
    "AOU": "Aousserd (EH)",
    "ASZ": "Assa-Zag",
    "AZI": "Azilal",
    "BEM": "Beni Mellal",
    "BER": "Berkane",
    "BES": "Ben Slimane",
    "BOD": "Boujdour (EH)",
    "BOM": "Boulemane",
    "BRR": "Berrechid",
    "CAS": "Casablanca [Dar el Beïda]",
    "CHE": "Chefchaouen",
    "CHI": "Chichaoua",
    "CHT": "Chtouka-Ait Baha",
    "DRI": "Driouch",
    "ERR": "Errachidia",
    "ESI": "Essaouira",
    "ESM": "Es Smara (EH)",
    "FAH": "Fahs-Anjra",
    "FES": "Fès-Dar-Dbibegh",
    "FIG": "Figuig",
    "FQH": "Fquih Ben Salah",
    "GUE": "Guelmim",
    "GUF": "Guercif",
    "HAJ": "El Hajeb",
    "HAO": "Al Haouz",
    "HOC": "Al Hoceïma",
    "IFR": "Ifrane",
    "INE": "Inezgane-Ait Melloul",
    "JDI": "El Jadida",
    "JRA": "Jrada",
    "KEN": "Kénitra",
    "KES": "Kelaat es Sraghna",
    "KHE": "Khémisset",
    "KHN": "Khénifra",
    "KHO": "Khouribga",
    "LAA": "Laâyoune",
    "LAR": "Larache",
    "MAR": "Marrakech",
    "MDF": "M'Diq-Fnideq",
    "MED": "Médiouna",
    "MEK": "Meknès",
    "MID": "Midelt",
    "MOH": "Mohammadia",
    "MOU": "Moulay Yacoub",
    "NAD": "Nador",
    "NOU": "Nouaceur",
    "OUA": "Ouarzazate",
    "OUD": "Oued ed Dahab (EH)",
    "OUJ": "Oujda-Angad",
    "OUZ": "Ouezzane",
    "RAB": "Rabat",
    "REH": "Rehamna",
    "SAF": "Safi",
    "SAL": "Salé",
    "SEF": "Sefrou",
    "SET": "Settat",
    "SIB": "Sidi Bennour",
    "SIF": "Sidi Ifni",
    "SIK": "Sidi Kacem",
    "SIL": "Sidi Slimane",
    "SKH": "Skhirate-Témara",
    "TAF": "Tarfaya",
    "TAI": "Taourirt",
    "TAO": "Taounate",
    "TAR": "Taroudant",
    "TAT": "Tata",
    "TAZ": "Taza",
    "TET": "Tétouan",
    "TIN": "Tinghir",
    "TIZ": "Tiznit",
    "TNG": "Tanger-Assilah",
    "TNT": "Tan-Tan",
    "YUS": "Youssoufia",
    "ZAG": "Zagora"
  }
}
validation/data/iso_3166-2/UY.json000064400000001047147361033760012463 0ustar00{
  "source": "http://www.geonames.org/UY/administrative-division-uruguay.html",
  "country": "Uruguay",
  "subdivisions": {
    "AR": "Artigas",
    "CA": "Canelones",
    "CL": "Cerro Largo",
    "CO": "Colonia",
    "DU": "Durazno",
    "FD": "Florida",
    "FS": "Flores",
    "LA": "Lavalleja",
    "MA": "Maldonado",
    "MO": "Montevideo",
    "PA": "Paysandu",
    "RN": "Rio Negro",
    "RO": "Rocha",
    "RV": "Rivera",
    "SA": "Salto",
    "SJ": "San Jose",
    "SO": "Soriano",
    "TA": "Tacuarembó",
    "TT": "Treinta y Tres"
  }
}
validation/data/iso_3166-2/CI.json000064400000000752147361033760012423 0ustar00{
  "source": "http://www.geonames.org/CI/administrative-division-ivory-coast.html",
  "country": "Ivory Coast",
  "subdivisions": {
    "AB": "Abidjan",
    "BS": "Bas-Sassandra",
    "CM": "Comoé",
    "DN": "Denguélé",
    "GD": "Gôh-Djiboua",
    "LC": "Lacs",
    "LG": "Lagunes",
    "MG": "Montagnes",
    "SM": "Sassandra-Marahoué",
    "SV": "Savanes",
    "VB": "Vallée du Bandama",
    "WR": "Woroba",
    "YM": "Yamoussoukro Autonomous District",
    "ZZ": "Zanzan"
  }
}
validation/data/iso_3166-2/CU.json000064400000001010147361033760012423 0ustar00{
  "source": "http://www.geonames.org/CU/administrative-division-cuba.html",
  "country": "Cuba",
  "subdivisions": {
    "01": "Pinar del Rio",
    "03": "La Habana",
    "04": "Matanzas",
    "05": "Villa Clara",
    "06": "Cienfuegos",
    "07": "Sancti Spiritus",
    "08": "Ciego de Avila",
    "09": "Camaguey",
    "10": "Las Tunas",
    "11": "Holguin",
    "12": "Granma",
    "13": "Santiago de Cuba",
    "14": "Guantanamo",
    "15": "Artemisa",
    "16": "Mayabeque",
    "99": "Isla de la Juventud"
  }
}
validation/data/iso_3166-2/AF.json000064400000002212147361033760012407 0ustar00{
  "source": "http://www.geonames.org/AF/administrative-division-afghanistan.html",
  "country": "Afghanistan",
  "subdivisions": {
    "BAL": "Balkh province",
    "BAM": "Bamian province",
    "BDG": "Badghis province",
    "BDS": "Badakhshan province",
    "BGL": "Baghlan province",
    "DAY": "Dāykundī",
    "FRA": "Farah province",
    "FYB": "Faryab province",
    "GHA": "Ghazni province",
    "GHO": "Ghowr province",
    "HEL": "Helmand province",
    "HER": "Herat province",
    "JOW": "Jowzjan province",
    "KAB": "Kabul province",
    "KAN": "Kandahar province",
    "KAP": "Kapisa province",
    "KDZ": "Kondoz province",
    "KHO": "Khost province",
    "KNR": "Konar province",
    "LAG": "Laghman province",
    "LOG": "Lowgar province",
    "NAN": "Nangrahar province",
    "NIM": "Nimruz province",
    "NUR": "Nurestan province",
    "PAN": "Panjshir",
    "PAR": "Parwan province",
    "PIA": "Paktia province",
    "PKA": "Paktika province",
    "SAM": "Samangan province",
    "SAR": "Sar-e Pol province",
    "TAK": "Takhar province",
    "URU": "Uruzgān province",
    "WAR": "Wardak province",
    "ZAB": "Zabol province"
  }
}
validation/data/iso_3166-2/SV.json000064400000000717147361033760012461 0ustar00{
  "source": "http://www.geonames.org/SV/administrative-division-el-salvador.html",
  "country": "El Salvador",
  "subdivisions": {
    "AH": "Ahuachapan",
    "CA": "Cabanas",
    "CH": "Chalatenango",
    "CU": "Cuscatlan",
    "LI": "La Libertad",
    "MO": "Morazan",
    "PA": "La Paz",
    "SA": "Santa Ana",
    "SM": "San Miguel",
    "SO": "Sonsonate",
    "SS": "San Salvador",
    "SV": "San Vicente",
    "UN": "La Union",
    "US": "Usulutan"
  }
}
validation/data/iso_3166-2/MO.json000064400000000174147361033760012441 0ustar00{
  "source": "http://www.geonames.org/MO/administrative-division-macao.html",
  "country": "Macao",
  "subdivisions": []
}
validation/data/iso_3166-2/GU.json000064400000000172147361033760012437 0ustar00{
  "source": "http://www.geonames.org/GU/administrative-division-guam.html",
  "country": "Guam",
  "subdivisions": []
}
validation/data/iso_3166-2/TN.json000064400000001175147361033760012451 0ustar00{
  "source": "http://www.geonames.org/TN/administrative-division-tunisia.html",
  "country": "Tunisia",
  "subdivisions": {
    "11": "Tunis",
    "12": "L'Ariana",
    "13": "Ben Arous",
    "14": "La Manouba",
    "21": "Nabeul",
    "22": "Zaghouan",
    "23": "Bizerte",
    "31": "Béja",
    "32": "Jendouba",
    "33": "Le Kef",
    "34": "Siliana",
    "41": "Kairouan",
    "42": "Kasserine",
    "43": "Sidi Bouzid",
    "51": "Sousse",
    "52": "Monastir",
    "53": "Mahdia",
    "61": "Sfax",
    "71": "Gafsa",
    "72": "Tozeur",
    "73": "Kebili",
    "81": "Gabès",
    "82": "Medenine",
    "83": "Tataouine"
  }
}
validation/data/iso_3166-2/BG.json000064400000001342147361033760012414 0ustar00{
  "source": "http://www.geonames.org/BG/administrative-division-bulgaria.html",
  "country": "Bulgaria",
  "subdivisions": {
    "01": "Blagoevgrad",
    "02": "Burgas",
    "03": "Varna",
    "04": "Veliko Turnovo",
    "05": "Vidin",
    "06": "Vratsa",
    "07": "Gabrovo",
    "08": "Dobrich",
    "09": "Kurdzhali",
    "10": "Kyustendil",
    "11": "Lovech",
    "12": "Montana",
    "13": "Pazardzhik",
    "14": "Pernik",
    "15": "Pleven",
    "16": "Plovdiv",
    "17": "Razgrad",
    "18": "Ruse",
    "19": "Silistra",
    "20": "Sliven",
    "21": "Smolyan",
    "22": "Sofia Region",
    "23": "Sofia",
    "24": "Stara Zagora",
    "25": "Turgovishte",
    "26": "Khaskovo",
    "27": "Shumen",
    "28": "Yambol"
  }
}
validation/data/iso_3166-2/PE.json000064400000001330147361033760012425 0ustar00{
  "source": "http://www.geonames.org/PE/administrative-division-peru.html",
  "country": "Peru",
  "subdivisions": {
    "AMA": "Amazonas",
    "ANC": "Ancash",
    "APU": "Apurimac",
    "ARE": "Arequipa",
    "AYA": "Ayacucho",
    "CAJ": "Cajamarca",
    "CAL": "Callao",
    "CUS": "Cusco",
    "HUC": "Huanuco",
    "HUV": "Huancavelica",
    "ICA": "Ica",
    "JUN": "Junin",
    "LAL": "La Libertad",
    "LAM": "Lambayeque",
    "LIM": "Lima",
    "LMA": "Municipalidad Metropolitana de Lima",
    "LOR": "Loreto",
    "MDD": "Madre de Dios",
    "MOQ": "Moquegua",
    "PAS": "Pasco",
    "PIU": "Piura",
    "PUN": "Puno",
    "SAM": "San Martin",
    "TAC": "Tacna",
    "TUM": "Tumbes",
    "UCA": "Ucayali"
  }
}
validation/data/iso_3166-2/BO.json000064400000000641147361033760012425 0ustar00{
  "source": "http://www.geonames.org/BO/administrative-division-bolivia.html",
  "country": "Bolivia",
  "subdivisions": {
    "B": "Departmento Beni",
    "C": "Departmento Cochabamba",
    "H": "Departmento Chuquisaca",
    "L": "Departmento La Paz",
    "N": "Departmento Pando",
    "O": "Departmento Oruro",
    "P": "Departmento Potosi",
    "S": "Departmento Santa Cruz",
    "T": "Departmento Tarija"
  }
}
validation/data/iso_3166-2/YT.json000064400000000200147361033760012450 0ustar00{
  "source": "http://www.geonames.org/YT/administrative-division-mayotte.html",
  "country": "Mayotte",
  "subdivisions": []
}
validation/data/iso_3166-2/LU.json000064400000001015147361033760012441 0ustar00{
  "source": "http://www.geonames.org/LU/administrative-division-luxembourg.html",
  "country": "Luxembourg",
  "subdivisions": {
    "CA": "Canton de Capellen",
    "CL": "Canton de Clervaux",
    "DI": "Canton de Diekirch",
    "EC": "Canton d'Echternach",
    "ES": "Canton d'Esch-sur-Alzette",
    "GR": "Canton de Grevenmacher",
    "LU": "Canton de Luxembourg",
    "ME": "Canton de Mersch",
    "RD": "Canton de Redange",
    "RM": "Canton de Remich",
    "VD": "Canton de Vianden",
    "WI": "Canton de Wiltz"
  }
}
validation/data/iso_3166-2/TZ.json000064400000001426147361033760012464 0ustar00{
  "source": "http://www.geonames.org/TZ/administrative-division-tanzania.html",
  "country": "Tanzania",
  "subdivisions": {
    "01": "Arusha",
    "02": "Dar es Salaam",
    "03": "Dodoma",
    "04": "Iringa",
    "05": "Kagera",
    "06": "Pemba North",
    "07": "Zanzibar North",
    "08": "Kigoma",
    "09": "Kilimanjaro",
    "10": "Pemba South",
    "11": "Zanzibar Central/South",
    "12": "Lindi",
    "13": "Mara",
    "14": "Mbeya",
    "15": "Zanzibar Urban/West",
    "16": "Morogoro",
    "17": "Mtwara",
    "18": "Mwanza",
    "19": "Pwani",
    "20": "Rukwa",
    "21": "Ruvuma",
    "22": "Shinyanga",
    "23": "Singida",
    "24": "Tabora",
    "25": "Tanga",
    "26": "Manyara",
    "27": "Geita",
    "28": "Katavi",
    "29": "Njombe",
    "30": "Simiyu"
  }
}
validation/data/iso_3166-2/IS.json000064400000000524147361033760012440 0ustar00{
  "source": "http://www.geonames.org/IS/administrative-division-iceland.html",
  "country": "Iceland",
  "subdivisions": {
    "1": "Höfuðborgarsvæði",
    "2": "Suðurnes",
    "3": "Vesturland",
    "4": "Vestfirðir",
    "5": "Norðurland Vestra",
    "6": "Norðurland Eystra",
    "7": "Austurland",
    "8": "Suðurland"
  }
}
validation/data/iso_3166-2/GY.json000064400000000715147361033760012446 0ustar00{
  "source": "http://www.geonames.org/GY/administrative-division-guyana.html",
  "country": "Guyana",
  "subdivisions": {
    "BA": "Barima-Waini",
    "CU": "Cuyuni-Mazaruni",
    "DE": "Demerara-Mahaica",
    "EB": "East Berbice-Corentyne",
    "ES": "Essequibo Islands-West Demerara",
    "MA": "Mahaica-Berbice",
    "PM": "Pomeroon-Supenaam",
    "PT": "Potaro-Siparuni",
    "UD": "Upper Demerara-Berbice",
    "UT": "Upper Takutu-Upper Essequibo"
  }
}
validation/data/iso_3166-2/SC.json000064400000001414147361033760012431 0ustar00{
  "source": "http://www.geonames.org/SC/administrative-division-seychelles.html",
  "country": "Seychelles",
  "subdivisions": {
    "01": "Anse aux Pins",
    "02": "Anse Boileau",
    "03": "Anse Etoile",
    "04": "Anse Louis",
    "05": "Anse Royale",
    "06": "Baie Lazare",
    "07": "Baie Sainte Anne",
    "08": "Beau Vallon",
    "09": "Bel Air",
    "10": "Bel Ombre",
    "11": "Cascade",
    "12": "Glacis",
    "13": "Grand' Anse (on Mahe)",
    "14": "Grand' Anse (on Praslin)",
    "15": "La Digue",
    "16": "La Riviere Anglaise",
    "17": "Mont Buxton",
    "18": "Mont Fleuri",
    "19": "Plaisance",
    "20": "Pointe La Rue",
    "21": "Port Glaud",
    "22": "Saint Louis",
    "23": "Takamaka",
    "24": "Les Mamelles",
    "25": "Roche Caïman"
  }
}
validation/data/iso_3166-2/BV.json000064400000000214147361033760012430 0ustar00{
  "source": "http://www.geonames.org/BV/administrative-division-bouvet-island.html",
  "country": "Bouvet Island",
  "subdivisions": []
}
validation/data/iso_3166-2/TW.json000064400000001143147361033760012455 0ustar00{
  "source": "http://www.geonames.org/TW/administrative-division-taiwan.html",
  "country": "Taiwan",
  "subdivisions": {
    "CHA": "Changhua",
    "CYI": "Chiayi",
    "CYQ": "Chiayi",
    "HSQ": "Hsinchu",
    "HSZ": "Hsinchu",
    "HUA": "Hualien",
    "ILA": "Ilan",
    "KEE": "Keelung",
    "KHH": "Kaohsiung",
    "KIN": "Kinmen",
    "LIE": "Lienchiang",
    "MIA": "Miaoli",
    "NAN": "Nantou",
    "NWT": "New Taipei",
    "PEN": "Penghu",
    "PIF": "Pingtung",
    "TAO": "Taoyuan",
    "TNN": "Tainan",
    "TPE": "Taipei",
    "TTT": "Taitung",
    "TXG": "Taichung",
    "YUN": "Yunlin"
  }
}
validation/data/iso_3166-2/LB.json000064400000000474147361033760012426 0ustar00{
  "source": "http://www.geonames.org/LB/administrative-division-lebanon.html",
  "country": "Lebanon",
  "subdivisions": {
    "AK": "Aakkâr",
    "AS": "Liban-Nord",
    "BA": "Beyrouth",
    "BH": "Baalbek-Hermel",
    "BI": "Béqaa",
    "JA": "Liban-Sud",
    "JL": "Mont-Liban",
    "NA": "Nabatîyé"
  }
}
validation/data/iso_3166-2/TF.json000064400000000250147361033760012432 0ustar00{
  "source": "http://www.geonames.org/TF/administrative-division-french-southern-territories.html",
  "country": "French Southern Territories",
  "subdivisions": []
}
validation/data/iso_3166-2/NA.json000064400000000663147361033760012427 0ustar00{
  "source": "http://www.geonames.org/NA/administrative-division-namibia.html",
  "country": "Namibia",
  "subdivisions": {
    "CA": "Caprivi",
    "ER": "Erongo",
    "HA": "Hardap",
    "KA": "Karas",
    "KE": "Kavango East",
    "KH": "Khomas",
    "KU": "Kunene",
    "KW": "Kavango West",
    "OD": "Otjozondjupa",
    "OH": "Omaheke",
    "ON": "Oshana",
    "OS": "Omusati",
    "OT": "Oshikoto",
    "OW": "Ohangwena"
  }
}
validation/data/iso_3166-2/KG.json000064400000000466147361033760012433 0ustar00{
  "source": "http://www.geonames.org/KG/administrative-division-kyrgyzstan.html",
  "country": "Kyrgyzstan",
  "subdivisions": {
    "B": "Batken",
    "C": "Chu",
    "GB": "Bishkek",
    "GO": "Osh City",
    "J": "Jalal-Abad",
    "N": "Naryn",
    "O": "Osh",
    "T": "Talas",
    "Y": "Ysyk-Kol"
  }
}
validation/data/iso_3166-2/CD.json000064400000001406147361033760012413 0ustar00{
  "source": "http://www.geonames.org/CD/administrative-division-democratic-republic-of-the-congo.html",
  "country": "Democratic Republic of the Congo",
  "subdivisions": {
    "BC": "Kongo Central",
    "BU": "Bas-Uélé",
    "EQ": "Équateur ",
    "HK": "Haut-Katanga",
    "HL": "Haut-Lomami",
    "HU": "Haut-Uélé",
    "IT": "Ituri",
    "KC": "Kasaï Central",
    "KE": "Kasai-Oriental",
    "KG": "Kwango",
    "KL": "Kwilu",
    "KN": "Kinshasa",
    "KS": "Kasaï",
    "LO": "Lomami",
    "LU": "Lualaba",
    "MA": "Maniema",
    "MN": "Mai-Ndombe",
    "MO": "Mongala",
    "NK": "Nord-Kivu",
    "NU": "Nord-Ubangi",
    "SA": "Sankuru",
    "SK": "Sud-Kivu",
    "SU": "Sud-Ubangi",
    "TA": "Tanganyika",
    "TO": "Tshopo",
    "TU": "Tshuapa"
  }
}
validation/data/iso_3166-2/BB.json000064400000000636147361033760012414 0ustar00{
  "source": "http://www.geonames.org/BB/administrative-division-barbados.html",
  "country": "Barbados",
  "subdivisions": {
    "01": "Christ Church",
    "02": "Saint Andrew",
    "03": "Saint George",
    "04": "Saint James",
    "05": "Saint John",
    "06": "Saint Joseph",
    "07": "Saint Lucy",
    "08": "Saint Michael",
    "09": "Saint Peter",
    "10": "Saint Philip",
    "11": "Saint Thomas"
  }
}
validation/data/iso_3166-2/NE.json000064400000000430147361033760012423 0ustar00{
  "source": "http://www.geonames.org/NE/administrative-division-niger.html",
  "country": "Niger",
  "subdivisions": {
    "1": "Agadez",
    "2": "Diffa",
    "3": "Dosso",
    "4": "Maradi",
    "5": "Tahoua",
    "6": "Tillabéri",
    "7": "Zinder",
    "8": "Niamey"
  }
}
validation/data/iso_3166-2/AE.json000064400000000506147361033760012412 0ustar00{
  "source": "http://www.geonames.org/AE/administrative-division-united-arab-emirates.html",
  "country": "United Arab Emirates",
  "subdivisions": {
    "AJ": "'Ajman",
    "AZ": "Abu Zaby",
    "DU": "Dubayy",
    "FU": "Al Fujayrah",
    "RK": "R'as al Khaymah",
    "SH": "Ash Shariqah",
    "UQ": "Umm al Qaywayn"
  }
}
validation/data/iso_3166-2/PW.json000064400000000753147361033760012457 0ustar00{
  "source": "http://www.geonames.org/PW/administrative-division-palau.html",
  "country": "Palau",
  "subdivisions": {
    "002": "Aimeliik",
    "004": "Airai",
    "010": "Angaur",
    "050": "Hatohobei",
    "100": "Kayangel",
    "150": "Koror",
    "212": "Melekeok",
    "214": "Ngaraard",
    "218": "Ngarchelong",
    "222": "Ngardmau",
    "224": "Ngatpang",
    "226": "Ngchesar",
    "227": "Ngeremlengui",
    "228": "Ngiwal",
    "350": "Peleliu",
    "370": "Sonsorol"
  }
}
validation/data/iso_3166-2/IN.json000064400000001750147361033760012435 0ustar00{
  "source": "http://www.geonames.org/IN/administrative-division-india.html",
  "country": "India",
  "subdivisions": {
    "AN": "Andaman and Nicobar Islands",
    "AP": "Andhra Pradesh",
    "AR": "Arunachal Pradesh",
    "AS": "Assam",
    "BR": "Bihar",
    "CH": "Chandigarh",
    "CT": "Chhattisgarh",
    "DD": "Daman and Diu",
    "DL": "Delhi",
    "DN": "Dadra and Nagar Haveli",
    "GA": "Goa",
    "GJ": "Gujarat",
    "HP": "Himachal Pradesh",
    "HR": "Haryana",
    "JH": "Jharkhand",
    "JK": "Jammu and Kashmir",
    "KA": "Karnataka",
    "KL": "Kerala",
    "LD": "Lakshadweep",
    "MH": "Maharashtra",
    "ML": "Meghalaya",
    "MN": "Manipur",
    "MP": "Madhya Pradesh",
    "MZ": "Mizoram",
    "NL": "Nagaland",
    "OR": "Orissa",
    "PB": "Punjab",
    "PY": "Pondicherry",
    "RJ": "Rajasthan",
    "SK": "Sikkim",
    "TG": "Telangana",
    "TN": "Tamil Nadu",
    "TR": "Tripura",
    "UP": "Uttar Pradesh",
    "UT": "Uttarakhand",
    "WB": "West Bengal"
  }
}
validation/data/iso_3166-2/NO.json000064400000001104147361033760012434 0ustar00{
  "source": "http://www.geonames.org/NO/administrative-division-norway.html",
  "country": "Norway",
  "subdivisions": {
    "01": "Ostfold",
    "02": "Akershus",
    "03": "Oslo",
    "04": "Hedmark",
    "05": "Oppland",
    "06": "Buskerud",
    "07": "Vestfold",
    "08": "Telemark",
    "09": "Aust-Agder",
    "10": "Vest-Agder",
    "11": "Rogaland",
    "12": "Hordaland",
    "14": "Sogn og Fjordane",
    "15": "More og Romdal",
    "18": "Nordland",
    "19": "Troms",
    "20": "Finnmark",
    "21": "Svalbard",
    "22": "Jan Mayen",
    "23": "Trøndelag"
  }
}
validation/data/iso_3166-2/DJ.json000064400000000401147361033760012414 0ustar00{
  "source": "http://www.geonames.org/DJ/administrative-division-djibouti.html",
  "country": "Djibouti",
  "subdivisions": {
    "AR": "Arta",
    "AS": "'Ali Sabih",
    "DI": "Dikhil",
    "DJ": "Djibouti",
    "OB": "Obock",
    "TA": "Tadjoura"
  }
}
validation/data/iso_3166-2/AL.json000064400000002121147361033760012414 0ustar00{
  "source": "http://www.geonames.org/AL/administrative-division-albania.html",
  "country": "Albania",
  "subdivisions": {
    "01": "Berat",
    "02": "Durres",
    "03": "Elbasan",
    "04": "Fier",
    "05": "Gjirokaster",
    "06": "Korce",
    "07": "Kukes",
    "08": "Lezhe",
    "09": "Diber",
    "10": "Shkoder",
    "11": "Tirane",
    "12": "Vlore",
    "BR": "Berat",
    "BU": "Bulqize",
    "DI": "Diber",
    "DL": "Delvine",
    "DR": "Durres",
    "DV": "Devoll",
    "EL": "Elbasan",
    "ER": "Kolonje",
    "FR": "Fier",
    "GJ": "Gjirokaster",
    "GR": "Gramsh",
    "HA": "Has",
    "KA": "Kavaje",
    "KB": "Kurbin",
    "KC": "Kucove",
    "KO": "Korce",
    "KR": "Kruje",
    "KU": "Kukes",
    "LB": "Librazhd",
    "LE": "Lezhe",
    "LU": "Lushnje",
    "MK": "Mallakaster",
    "MM": "Malesi e Madhe",
    "MR": "Mirdite",
    "MT": "Mat",
    "PG": "Pogradec",
    "PQ": "Peqin",
    "PR": "Permet",
    "PU": "Puke",
    "SH": "Shkoder",
    "SK": "Skrapar",
    "SR": "Sarande",
    "TE": "Tepelene",
    "TP": "Tropoje",
    "TR": "Tirane",
    "VL": "Vlore"
  }
}
validation/data/iso_3166-2/SM.json000064400000000554147361033760012447 0ustar00{
  "source": "http://www.geonames.org/SM/administrative-division-san-marino.html",
  "country": "San Marino",
  "subdivisions": {
    "01": "Acquaviva",
    "02": "Chiesanuova",
    "03": "Domagnano",
    "04": "Faetano",
    "05": "Fiorentino",
    "06": "Borgo Maggiore",
    "07": "Citta di San Marino",
    "08": "Montegiardino",
    "09": "Serravalle"
  }
}
validation/data/iso_3166-2/NU.json000064400000000172147361033760012446 0ustar00{
  "source": "http://www.geonames.org/NU/administrative-division-niue.html",
  "country": "Niue",
  "subdivisions": []
}
validation/data/iso_3166-2/US.json000064400000002720147361033760012454 0ustar00{
  "source": "http://www.geonames.org/US/administrative-division-united-states.html",
  "country": "United States",
  "subdivisions": {
    "AK": "Alaska",
    "AL": "Alabama",
    "AR": "Arkansas",
    "AS": "American Samoa",
    "AZ": "Arizona",
    "CA": "California",
    "CO": "Colorado",
    "CT": "Connecticut",
    "DC": "District of Columbia",
    "DE": "Delaware",
    "FL": "Florida",
    "GA": "Georgia",
    "GU": "Guam",
    "HI": "Hawaii",
    "IA": "Iowa",
    "ID": "Idaho",
    "IL": "Illinois",
    "IN": "Indiana",
    "KS": "Kansas",
    "KY": "Kentucky",
    "LA": "Louisiana",
    "MA": "Massachusetts",
    "MD": "Maryland",
    "ME": "Maine",
    "MI": "Michigan",
    "MN": "Minnesota",
    "MO": "Missouri",
    "MP": "Northern Mariana Islands",
    "MS": "Mississippi",
    "MT": "Montana",
    "NC": "North Carolina",
    "ND": "North Dakota",
    "NE": "Nebraska",
    "NH": "New Hampshire",
    "NJ": "New Jersey",
    "NM": "New Mexico",
    "NV": "Nevada",
    "NY": "New York",
    "OH": "Ohio",
    "OK": "Oklahoma",
    "OR": "Oregon",
    "PA": "Pennsylvania",
    "PR": "Puerto Rico",
    "RI": "Rhode Island",
    "SC": "South Carolina",
    "SD": "South Dakota",
    "TN": "Tennessee",
    "TX": "Texas",
    "UM": "U.S. Minor Outlying Islands",
    "UT": "Utah",
    "VA": "Virginia",
    "VI": "Virgin Islands of the U.S.",
    "VT": "Vermont",
    "WA": "Washington",
    "WI": "Wisconsin",
    "WV": "West Virginia",
    "WY": "Wyoming"
  }
}
validation/data/iso_3166-2/MF.json000064400000000212147361033760012421 0ustar00{
  "source": "http://www.geonames.org/MF/administrative-division-saint-martin.html",
  "country": "Saint Martin",
  "subdivisions": []
}
validation/data/iso_3166-2/TH.json000064400000003664147361033760012450 0ustar00{
  "source": "http://www.geonames.org/TH/administrative-division-thailand.html",
  "country": "Thailand",
  "subdivisions": {
    "10": "Bangkok",
    "11": "Samut Prakan",
    "12": "Nonthaburi",
    "13": "Pathum Thani",
    "14": "Phra Nakhon Si Ayutthaya",
    "15": "Ang Thong",
    "16": "Lop Buri",
    "17": "Sing Buri",
    "18": "Chai Nat",
    "19": "Saraburi",
    "20": "Chon Buri",
    "21": "Rayong",
    "22": "Chanthaburi",
    "23": "Trat",
    "24": "Chachoengsao",
    "25": "Prachin Buri",
    "26": "Nakhon Nayok",
    "27": "Sa Kaeo",
    "30": "Nakhon Ratchasima",
    "31": "Buri Ram",
    "32": "Surin",
    "33": "Si Sa Ket",
    "34": "Ubon Ratchathani",
    "35": "Yasothon",
    "36": "Chaiyaphum",
    "37": "Amnat Charoen",
    "38": "Bueng Kan",
    "39": "Nong Bua Lam Phu",
    "40": "Khon Kaen",
    "41": "Udon Thani",
    "42": "Loei",
    "43": "Nong Khai",
    "44": "Maha Sarakham",
    "45": "Roi Et",
    "46": "Kalasin",
    "47": "Sakon Nakhon",
    "48": "Nakhon Phanom",
    "49": "Mukdahan",
    "50": "Chiang Mai",
    "51": "Lamphun",
    "52": "Lampang",
    "53": "Uttaradit",
    "54": "Phrae",
    "55": "Nan",
    "56": "Phayao",
    "57": "Chiang Rai",
    "58": "Mae Hong Son",
    "60": "Nakhon Sawan",
    "61": "Uthai Thani",
    "62": "Kamphaeng Phet",
    "63": "Tak",
    "64": "Sukhothai",
    "65": "Phitsanulok",
    "66": "Phichit",
    "67": "Phetchabun",
    "70": "Ratchaburi",
    "71": "Kanchanaburi",
    "72": "Suphanburi",
    "73": "Nakhon Pathom",
    "74": "Samut Sakhon",
    "75": "Samut Songkhram",
    "76": "Phetchaburi",
    "77": "Prachuap Khiri Khan",
    "80": "Nakhon Si Thammarat",
    "81": "Krabi",
    "82": "Phang Nga",
    "83": "Phuket",
    "84": "Surat Thani",
    "85": "Ranong",
    "86": "Chumpon",
    "90": "Songkhla",
    "91": "Satun",
    "92": "Trang",
    "93": "Phattalung",
    "94": "Pattani",
    "95": "Yala",
    "96": "Narathiwat",
    "S": "Pattaya"
  }
}
validation/data/iso_3166-2/SS.json000064400000000210147361033760012442 0ustar00{
  "source": "http://www.geonames.org/SS/administrative-division-south-sudan.html",
  "country": "South Sudan",
  "subdivisions": []
}
validation/data/iso_3166-2/SK.json000064400000000504147361033760012440 0ustar00{
  "source": "http://www.geonames.org/SK/administrative-division-slovakia.html",
  "country": "Slovakia",
  "subdivisions": {
    "BC": "Banskobystricky",
    "BL": "Bratislavsky",
    "KI": "Kosicky",
    "NI": "Nitriansky",
    "PV": "Presovsky",
    "TA": "Trnavsky",
    "TC": "Trenciansky",
    "ZI": "Zilinsky"
  }
}
validation/data/iso_3166-2/MY.json000064400000000733147361033760012454 0ustar00{
  "source": "http://www.geonames.org/MY/administrative-division-malaysia.html",
  "country": "Malaysia",
  "subdivisions": {
    "01": "Johor",
    "02": "Kedah",
    "03": "Kelantan",
    "04": "Melaka",
    "05": "Negeri Sembilan",
    "06": "Pahang",
    "07": "Pinang",
    "08": "Perak",
    "09": "Perlis",
    "10": "Selangor",
    "11": "Terengganu",
    "12": "Sabah",
    "13": "Sarawak",
    "14": "Kuala Lumpur",
    "15": "Labuan",
    "16": "Putrajaya"
  }
}
validation/data/iso_3166-2/CO.json000064400000001604147361033760012426 0ustar00{
  "source": "http://www.geonames.org/CO/administrative-division-colombia.html",
  "country": "Colombia",
  "subdivisions": {
    "AMA": "Amazonas",
    "ANT": "Antioquia",
    "ARA": "Arauca",
    "ATL": "Atlantico",
    "BOL": "Bolivar",
    "BOY": "Boyaca",
    "CAL": "Caldas",
    "CAQ": "Caqueta",
    "CAS": "Casanare",
    "CAU": "Cauca",
    "CES": "Cesar",
    "CHO": "Choco",
    "COR": "Cordoba",
    "CUN": "Cundinamarca",
    "DC": "Bogota D.C.",
    "GUA": "Guainia",
    "GUV": "Guaviare",
    "HUI": "Huila",
    "LAG": "La Guajira",
    "MAG": "Magdalena",
    "MET": "Meta",
    "NAR": "Narino",
    "NSA": "Norte de Santander",
    "PUT": "Putumayo",
    "QUI": "Quindio",
    "RIS": "Risaralda",
    "SAN": "Santander",
    "SAP": "San Andres y Providencia",
    "SUC": "Sucre",
    "TOL": "Tolima",
    "VAC": "Valle del Cauca",
    "VAU": "Vaupes",
    "VID": "Vichada"
  }
}
validation/data/iso_3166-2/PF.json000064400000000441147361033760012430 0ustar00{
  "source": "http://www.geonames.org/PF/administrative-division-french-polynesia.html",
  "country": "French Polynesia",
  "subdivisions": {
    "I": "Austral Islands",
    "M": "Marquesas Islands",
    "S": "Iles Sous-le-Vent",
    "T": "Tuamotu-Gambier",
    "V": "Iles du Vent"
  }
}
validation/data/iso_3166-2/FO.json000064400000000214147361033760012425 0ustar00{
  "source": "http://www.geonames.org/FO/administrative-division-faroe-islands.html",
  "country": "Faroe Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/FR.json000064400000006510147361033760012435 0ustar00{
  "source": "http://www.geonames.org/FR/administrative-division-france.html",
  "country": "France",
  "subdivisions": {
    "01": "Ain",
    "02": "Aisne",
    "03": "Allier",
    "04": "Alpes-de-Haute-Provence",
    "05": "Hautes-Alpes",
    "06": "Alpes-Maritimes",
    "07": "Ardèche",
    "08": "Ardennes",
    "09": "Ariège",
    "10": "Aube",
    "11": "Aude",
    "12": "Aveyron",
    "13": "Bouches-du-Rhône",
    "14": "Calvados",
    "15": "Cantal",
    "16": "Charente",
    "17": "Charente-Maritime",
    "18": "Cher",
    "19": "Corrèze",
    "21": "Côte-d'Or",
    "22": "Côtes-d'Armor",
    "23": "Creuse",
    "24": "Dordogne",
    "25": "Doubs",
    "26": "Drôme",
    "27": "Eure",
    "28": "Eure-et-Loir",
    "29": "Finistère",
    "2A": "Corse-du-Sud",
    "2B": "Haute-Corse",
    "30": "Gard",
    "31": "Haute-Garonne",
    "32": "Gers",
    "33": "Gironde",
    "34": "Hérault",
    "35": "Ille-et-Vilaine",
    "36": "Indre",
    "37": "Indre-et-Loire",
    "38": "Isère",
    "39": "Jura",
    "40": "Landes",
    "41": "Loir-et-Cher",
    "42": "Loire",
    "43": "Haute-Loire",
    "44": "Loire-Atlantique",
    "45": "Loiret",
    "46": "Lot",
    "47": "Lot-et-Garonne",
    "48": "Lozère",
    "49": "Maine-et-Loire",
    "50": "Manche",
    "51": "Marne",
    "52": "Haute-Marne",
    "53": "Mayenne",
    "54": "Meurthe-et-Moselle",
    "55": "Meuse",
    "56": "Morbihan",
    "57": "Moselle",
    "58": "Nièvre",
    "59": "Nord",
    "60": "Oise",
    "61": "Orne",
    "62": "Pas-de-Calais",
    "63": "Puy-de-Dôme",
    "64": "Pyrénées-Atlantiques",
    "65": "Hautes-Pyrénées",
    "66": "Pyrénées-Orientales",
    "67": "Bas-Rhin",
    "68": "Haut-Rhin",
    "69": "Rhône",
    "70": "Haute-Saône",
    "71": "Saône-et-Loire",
    "72": "Sarthe",
    "73": "Savoie",
    "74": "Haute-Savoie",
    "75": "Paris",
    "76": "Seine-Maritime",
    "77": "Seine-et-Marne",
    "78": "Yvelines",
    "79": "Deux-Sèvres",
    "80": "Somme",
    "81": "Tarn",
    "82": "Tarn-et-Garonne",
    "83": "Var",
    "84": "Vaucluse",
    "85": "Vendée",
    "86": "Vienne",
    "87": "Haute-Vienne",
    "88": "Vosges",
    "89": "Yonne",
    "90": "Territoire de Belfort",
    "91": "Essonne",
    "92": "Hauts-de-Seine",
    "93": "Seine-Saint-Denis",
    "94": "Val-de-Marne",
    "95": "Val-d'Oise",
    "ARA": "Auvergne-Rhône-Alpes",
    "BFC": "Bourgogne-Franche-Comté",
    "BL": "Saint Barthélemy (see also separate ISO 3166-1 entry under BL)",
    "BRE": "Bretagne",
    "COR": "Corse",
    "CP": "Clipperton",
    "CVL": "Centre-Val de Loire",
    "GES": "Grand Est",
    "HDF": "Hauts-de-France",
    "IDF": "Île-de-France",
    "MF": "Saint Martin (see also separate ISO 3166-1 entry under MF)",
    "NAQ": "Nouvelle-Aquitaine",
    "NC": "Nouvelle-Calédonie (see also separate ISO 3166-1 entry under NC)",
    "NOR": "Normandy",
    "OCC": "Occitanie",
    "PAC": "Provence-Alpes-Côte d'Azur",
    "PDL": "Pays de la Loire",
    "PF": "Polynésie française (see also separate ISO 3166-1 entry under PF)",
    "PM": "Saint-Pierre-et-Miquelon (see also separate ISO 3166-1 entry under PM)",
    "TF": "Terres Australes Françaises (see also separate ISO 3166-1 entry under TF)",
    "WF": "Wallis et Futuna (see also separate ISO 3166-1 entry under WF)",
    "YT": "Mayotte (see also separate ISO 3166-1 entry under YT)"
  }
}
validation/data/iso_3166-2/FM.json000064400000000331147361033760012423 0ustar00{
  "source": "http://www.geonames.org/FM/administrative-division-micronesia.html",
  "country": "Micronesia",
  "subdivisions": {
    "KSA": "Kosrae",
    "PNI": "Pohnpei",
    "TRK": "Chuuk",
    "YAP": "Yap"
  }
}
validation/data/iso_3166-2/BZ.json000064400000000471147361033760012441 0ustar00{
  "source": "http://www.geonames.org/BZ/administrative-division-belize.html",
  "country": "Belize",
  "subdivisions": {
    "BZ": "Belize District",
    "CY": "Cayo District",
    "CZL": "Corozal District",
    "OW": "Orange Walk District",
    "SC": "Stann Creek District",
    "TOL": "Toledo District"
  }
}
validation/data/iso_3166-2/NZ.json000064400000001054147361033760012453 0ustar00{
  "source": "http://www.geonames.org/NZ/administrative-division-new-zealand.html",
  "country": "New Zealand",
  "subdivisions": {
    "AUK": "Auckland",
    "BOP": "Bay of Plenty",
    "CAN": "Canterbury",
    "CIT": "Chatham Islands",
    "GIS": "Gisborne",
    "HKB": "Hawke's Bay",
    "MBH": "Marlborough",
    "MWT": "Manawatu-Wanganui",
    "NSN": "Nelson",
    "NTL": "Northland",
    "OTA": "Otago",
    "STL": "Southland",
    "TAS": "Tasman",
    "TKI": "Taranaki",
    "WGN": "Wellington",
    "WKO": "Waikato",
    "WTC": "West Coast"
  }
}
validation/data/iso_3166-2/AU.json000064400000000562147361033760012434 0ustar00{
  "source": "http://www.geonames.org/AU/administrative-division-australia.html",
  "country": "Australia",
  "subdivisions": {
    "ACT": "Australian Capital Territory",
    "NSW": "New South Wales",
    "NT": "Northern Territory",
    "QLD": "Queensland",
    "SA": "South Australia",
    "TAS": "Tasmania",
    "VIC": "Victoria",
    "WA": "Western Australia"
  }
}
validation/data/iso_3166-2/AQ.json000064400000000206147361033760012423 0ustar00{
  "source": "http://www.geonames.org/AQ/administrative-division-antarctica.html",
  "country": "Antarctica",
  "subdivisions": []
}
validation/data/iso_3166-2/LK.json000064400000001650147361033760012434 0ustar00{
  "source": "http://www.geonames.org/LK/administrative-division-sri-lanka.html",
  "country": "Sri Lanka",
  "subdivisions": {
    "1": "Western",
    "11": "Kŏḷamba",
    "12": "Gampaha",
    "13": "Kaḷutara",
    "2": "Central",
    "21": "Mahanuvara",
    "22": "Mātale",
    "23": "Nuvara Ĕliya",
    "3": "Southern",
    "31": "Gālla",
    "32": "Mātara",
    "33": "Hambantŏṭa",
    "4": "Northern",
    "41": "Yāpanaya",
    "42": "Kilinŏchchi",
    "43": "Mannārama",
    "44": "Vavuniyāva",
    "45": "Mulativ",
    "5": "Eastern",
    "51": "Maḍakalapuva",
    "52": "Ampāra",
    "53": "Trikuṇāmalaya",
    "6": "North Western",
    "61": "Kuruṇægala",
    "62": "Puttalama",
    "7": "North Central",
    "71": "Anurādhapura",
    "72": "Pŏḷŏnnaruva",
    "8": "Uva",
    "81": "Badulla",
    "82": "Mŏṇarāgala",
    "9": "Sabaragamuwa",
    "91": "Ratnapura",
    "92": "Kægalla"
  }
}
validation/data/iso_3166-2/CR.json000064400000000433147361033760012430 0ustar00{
  "source": "http://www.geonames.org/CR/administrative-division-costa-rica.html",
  "country": "Costa Rica",
  "subdivisions": {
    "A": "Alajuela",
    "C": "Cartago",
    "G": "Guanacaste",
    "H": "Heredia",
    "L": "Limon",
    "P": "Puntarenas",
    "SJ": "San Jose"
  }
}
validation/data/iso_3166-2/SL.json000064400000000377147361033760012451 0ustar00{
  "source": "http://www.geonames.org/SL/administrative-division-sierra-leone.html",
  "country": "Sierra Leone",
  "subdivisions": {
    "E": "Eastern",
    "N": "Northern",
    "NW": "North West Province",
    "S": "Southern",
    "W": "Western"
  }
}
validation/data/iso_3166-2/AD.json000064400000000467147361033760012417 0ustar00{
  "source": "http://www.geonames.org/AD/administrative-division-andorra.html",
  "country": "Andorra",
  "subdivisions": {
    "02": "Canillo",
    "03": "Encamp",
    "04": "La Massana",
    "05": "Ordino",
    "06": "Sant Julia de Lòria",
    "07": "Andorra la Vella",
    "08": "Escaldes-Engordany"
  }
}
validation/data/iso_3166-2/CY.json000064400000000410147361033760012432 0ustar00{
  "source": "http://www.geonames.org/CY/administrative-division-cyprus.html",
  "country": "Cyprus",
  "subdivisions": {
    "01": "Lefkosía",
    "02": "Lemesós",
    "03": "Lárnaka",
    "04": "Ammóchostos",
    "05": "Páfos",
    "06": "Kerýneia"
  }
}
validation/data/iso_3166-2/AG.json000064400000000531147361033760012412 0ustar00{
  "source": "http://www.geonames.org/AG/administrative-division-antigua-and-barbuda.html",
  "country": "Antigua and Barbuda",
  "subdivisions": {
    "03": "Saint George",
    "04": "Saint John",
    "05": "Saint Mary",
    "06": "Saint Paul",
    "07": "Saint Peter",
    "08": "Saint Philip",
    "10": "Barbuda",
    "11": "Redonda"
  }
}
validation/data/iso_3166-2/SD.json000064400000001162147361033760012432 0ustar00{
  "source": "http://www.geonames.org/SD/administrative-division-sudan.html",
  "country": "Sudan",
  "subdivisions": {
    "DC": "Wasaţ Dārfūr",
    "DE": "Sharq Dārfūr",
    "DN": "Shamāl Dārfūr",
    "DS": "Janūb Dārfūr",
    "DW": "Gharb Dārfūr",
    "GD": "Al Qaḑārif",
    "GK": "West Kurdufan",
    "GZ": "Al Jazīrah",
    "KA": "Kassalā",
    "KH": "Al Kharţūm",
    "KN": "Shamāl Kurdufān",
    "KS": "Janūb Kurdufān",
    "NB": "An Nīl al Azraq",
    "NO": "Ash Shamālīyah",
    "NR": "An Nīl",
    "NW": "An Nīl al Abyaḑ",
    "RS": "Al Baḩr al Aḩmar",
    "SI": "Sinnār"
  }
}
validation/data/iso_3166-2/RE.json000064400000000201147361033760012423 0ustar00{
  "source": "http://www.geonames.org/RE/administrative-division-reunion.html",
  "country": "Réunion",
  "subdivisions": []
}
validation/data/iso_3166-2/IR.json000064400000001534147361033760012441 0ustar00{
  "source": "http://www.geonames.org/IR/administrative-division-iran.html",
  "country": "Iran",
  "subdivisions": {
    "01": "East Azarbaijan",
    "02": "West Azarbaijan",
    "03": "Ardabil",
    "04": "Esfahan",
    "05": "Ilam",
    "06": "Bushehr",
    "07": "Tehran",
    "08": "Chahar Mahaal and Bakhtiari",
    "10": "Khuzestan",
    "11": "Zanjan",
    "12": "Semnan",
    "13": "Sistan and Baluchistan",
    "14": "Fars",
    "15": "Kerman",
    "16": "Kurdistan",
    "17": "Kermanshah",
    "18": "Kohkiluyeh and Buyer Ahmad",
    "19": "Gilan",
    "20": "Lorestan",
    "21": "Mazandaran",
    "22": "Markazi",
    "23": "Hormozgan",
    "24": "Hamadan",
    "25": "Yazd",
    "26": "Qom",
    "27": "Golestan",
    "28": "Qazvin",
    "29": "South Khorasan",
    "30": "Razavi Khorasan",
    "31": "North Khorasan",
    "32": "Alborz"
  }
}
validation/data/iso_3166-2/LI.json000064400000000571147361033760012433 0ustar00{
  "source": "http://www.geonames.org/LI/administrative-division-liechtenstein.html",
  "country": "Liechtenstein",
  "subdivisions": {
    "01": "Balzers",
    "02": "Eschen",
    "03": "Gamprin",
    "04": "Mauren",
    "05": "Planken",
    "06": "Ruggell",
    "07": "Schaan",
    "08": "Schellenberg",
    "09": "Triesen",
    "10": "Triesenberg",
    "11": "Vaduz"
  }
}
validation/data/iso_3166-2/KI.json000064400000000325147361033760012427 0ustar00{
  "source": "http://www.geonames.org/KI/administrative-division-kiribati.html",
  "country": "Kiribati",
  "subdivisions": {
    "G": "Gilbert Islands",
    "L": "Line Islands",
    "P": "Phoenix Islands"
  }
}
validation/data/iso_3166-2/IO.json000064400000000613147361033760012433 0ustar00{
  "source": "http://www.geonames.org/IO/administrative-division-british-indian-ocean-territory.html",
  "country": "British Indian Ocean Territory",
  "subdivisions": {
    "DG": "Diego Garcia",
    "DI": "Danger Island",
    "EA": "Eagle Islands",
    "EG": "Egmont Islands",
    "NI": "Nelsons Island",
    "PB": "Peros Banhos",
    "SI": "Salomon Islands",
    "TB": "Three Brothers"
  }
}
validation/data/iso_3166-2/PR.json000064400000000210147361033760012436 0ustar00{
  "source": "http://www.geonames.org/PR/administrative-division-puerto-rico.html",
  "country": "Puerto Rico",
  "subdivisions": []
}
validation/data/iso_3166-2/GB.json000064400000013650147361033760012421 0ustar00{
  "source": "http://www.geonames.org/GB/administrative-division-united-kingdom.html",
  "country": "United Kingdom",
  "subdivisions": {
    "ABC": "Armagh City Banbridge and Craigavon",
    "ABD": "Aberdeenshire",
    "ABE": "Aberdeen",
    "AGB": "Argyll and Bute",
    "AGY": "Isle of Anglesey",
    "AND": "Ards and North Down",
    "ANN": "Antrim and Newtownabbey",
    "ANS": "Angus",
    "BAS": "Bath and North East Somerset",
    "BBD": "Blackburn with Darwen",
    "BDF": "Bedford",
    "BDG": "Barking and Dagenham",
    "BEN": "Brent",
    "BEX": "Bexley",
    "BFS": "Belfast",
    "BGE": "Bridgend",
    "BGW": "Blaenau Gwent",
    "BIR": "Birmingham",
    "BKM": "Buckinghamshire",
    "BMH": "Bournemouth",
    "BNE": "Barnet",
    "BNH": "Brighton and Hove",
    "BNS": "Barnsley",
    "BOL": "Bolton",
    "BPL": "Blackpool",
    "BRC": "Bracknell Forest",
    "BRD": "Bradford",
    "BRY": "Bromley",
    "BST": "Bristol City of",
    "BUR": "Bury",
    "CAM": "Cambridgeshire",
    "CAY": "Caerphilly",
    "CBF": "Central Bedfordshire",
    "CCG": "Causeway Coast and Glens",
    "CGN": "Ceredigion",
    "CHE": "Cheshire East",
    "CHW": "Cheshire West and Chester",
    "CLD": "Calderdale",
    "CLK": "Clackmannanshire",
    "CMA": "Cumbria",
    "CMD": "Camden",
    "CMN": "Carmarthenshire",
    "CON": "Cornwall",
    "COV": "Coventry (West Midlands district)",
    "CRF": "Cardiff",
    "CRY": "Croydon",
    "CWY": "Conwy",
    "DAL": "Darlington",
    "DBY": "Derbyshire",
    "DEN": "Denbighshire",
    "DER": "Derby",
    "DEV": "Devon",
    "DGY": "Dumfries and Galloway",
    "DNC": "Doncaster",
    "DND": "Dundee",
    "DOR": "Dorset",
    "DRS": "Derry City and Strabane",
    "DUD": "Dudley (West Midlands district)",
    "DUR": "Durham",
    "EAL": "Ealing",
    "EAY": "East Ayrshire",
    "EDH": "Edinburgh",
    "EDU": "East Dunbartonshire",
    "ELN": "East Lothian",
    "ELS": "Eilean Siar",
    "ENF": "Enfield",
    "ENG": "England",
    "ERW": "East Renfrewshire",
    "ERY": "East Riding of Yorkshire",
    "ESS": "Essex",
    "ESX": "East Sussex",
    "FAL": "Falkirk",
    "FIF": "Fife",
    "FLN": "Flintshire",
    "FMO": "Fermanagh and Omagh",
    "GAT": "Gateshead (Tyne",
    "GLG": "Glasgow",
    "GLS": "Gloucestershire",
    "GRE": "Greenwich",
    "GWN": "Gwynedd",
    "HAL": "Halton",
    "HAM": "Hampshire",
    "HAV": "Havering",
    "HCK": "Hackney",
    "HEF": "Herefordshire County of",
    "HIL": "Hillingdon",
    "HLD": "Highland",
    "HMF": "Hammersmith and Fulham",
    "HNS": "Hounslow",
    "HPL": "Hartlepool",
    "HRT": "Hertfordshire",
    "HRW": "Harrow",
    "HRY": "Haringey",
    "IOS": "Isles of Scilly",
    "IOW": "Isle of Wight",
    "ISL": "Islington",
    "IVC": "Inverclyde",
    "KEC": "Kensington and Chelsea",
    "KEN": "Kent",
    "KHL": "Kingston upon Hull City of",
    "KIR": "Kirklees",
    "KTT": "Kingston upon Thames",
    "KWL": "Knowsley",
    "LAN": "Lancashire",
    "LBC": "Lisburn and Castlereagh",
    "LBH": "Lambeth",
    "LCE": "Leicester",
    "LDS": "Leeds",
    "LEC": "Leicestershire",
    "LEW": "Lewisham",
    "LIN": "Lincolnshire",
    "LIV": "Liverpool",
    "LND": "London City of",
    "LUT": "Luton",
    "MAN": "Manchester",
    "MDB": "Middlesbrough",
    "MDW": "Medway",
    "MEA": "Mid and East Antrim",
    "MIK": "Milton Keynes",
    "MLN": "Midlothian",
    "MON": "Monmouthshire",
    "MRT": "Merton",
    "MRY": "Moray",
    "MTY": "Merthyr Tydfil",
    "MUL": "Mid Ulster",
    "NAY": "North Ayrshire",
    "NBL": "Northumberland",
    "NEL": "North East Lincolnshire",
    "NET": "Newcastle upon Tyne",
    "NFK": "Norfolk",
    "NGM": "Nottingham",
    "NIR": "Northern Ireland",
    "NLK": "North Lanarkshire",
    "NLN": "North Lincolnshire",
    "NMD": "Newry Mourne and Down",
    "NSM": "North Somerset",
    "NTH": "Northamptonshire",
    "NTL": "Neath Port Talbot",
    "NTT": "Nottinghamshire",
    "NTY": "North Tyneside",
    "NWM": "Newham",
    "NWP": "Newport",
    "NYK": "North Yorkshire",
    "OLD": "Oldham",
    "ORK": "Orkney Islands",
    "OXF": "Oxfordshire",
    "PEM": "Pembrokeshire",
    "PKN": "Perth and Kinross",
    "PLY": "Plymouth",
    "POL": "Poole",
    "POR": "Portsmouth",
    "POW": "Powys",
    "PTE": "Peterborough",
    "RCC": "Redcar and Cleveland",
    "RCH": "Rochdale",
    "RCT": "Rhondda Cynon Taf",
    "RDB": "Redbridge",
    "RDG": "Reading",
    "RFW": "Renfrewshire",
    "RIC": "Richmond upon Thames",
    "ROT": "Rotherham",
    "RUT": "Rutland",
    "SAW": "Sandwell",
    "SAY": "South Ayrshire",
    "SCB": "Scottish Borders The",
    "SCT": "Scotland",
    "SFK": "Suffolk",
    "SFT": "Sefton",
    "SGC": "South Gloucestershire",
    "SHF": "Sheffield",
    "SHN": "St Helens",
    "SHR": "Shropshire",
    "SKP": "Stockport",
    "SLF": "Salford",
    "SLG": "Slough",
    "SLK": "South Lanarkshire",
    "SND": "Sunderland",
    "SOL": "Solihull",
    "SOM": "Somerset",
    "SOS": "Southend-on-Sea",
    "SRY": "Surrey",
    "STE": "Stoke-on-Trent",
    "STG": "Stirling",
    "STH": "Southampton",
    "STN": "Sutton",
    "STS": "Staffordshire",
    "STT": "Stockton-on-Tees",
    "STY": "South Tyneside",
    "SWA": "Swansea",
    "SWD": "Swindon",
    "SWK": "Southwark",
    "TAM": "Tameside",
    "TFW": "Telford and Wrekin",
    "THR": "Thurrock",
    "TOB": "Torbay",
    "TOF": "Torfaen",
    "TRF": "Trafford",
    "TWH": "Tower Hamlets",
    "VGL": "Vale of Glamorgan",
    "WAR": "Warwickshire",
    "WBK": "West Berkshire",
    "WDU": "West Dunbartonshire",
    "WFT": "Waltham Forest",
    "WGN": "Wigan",
    "WIL": "Wiltshire",
    "WKF": "Wakefield",
    "WLL": "Walsall",
    "WLN": "West Lothian",
    "WLS": "Wales",
    "WLV": "Wolverhampton",
    "WND": "Wandsworth",
    "WNM": "Windsor and Maidenhead",
    "WOK": "Wokingham",
    "WOR": "Worcestershire",
    "WRL": "Wirral",
    "WRT": "Warrington",
    "WRX": "Wrexham",
    "WSM": "Westminster",
    "WSX": "West Sussex",
    "YOR": "York",
    "ZET": "Shetland Islands"
  }
}
validation/data/iso_3166-2/TJ.json000064400000000412147361033760012436 0ustar00{
  "source": "http://www.geonames.org/TJ/administrative-division-tajikistan.html",
  "country": "Tajikistan",
  "subdivisions": {
    "DU": "Dushanbe",
    "GB": "Gorno-Badakhstan",
    "KT": "Khatlon",
    "RA": "Nohiyahoi Tobei Jumhurí",
    "SU": "Sughd"
  }
}
validation/data/iso_3166-2/ML.json000064400000000473147361033760012440 0ustar00{
  "source": "http://www.geonames.org/ML/administrative-division-mali.html",
  "country": "Mali",
  "subdivisions": {
    "1": "Kayes",
    "2": "Koulikoro",
    "3": "Sikasso",
    "4": "Segou",
    "5": "Mopti",
    "6": "Tombouctou",
    "7": "Gao",
    "8": "Kidal",
    "BKO": "Bamako Capital District"
  }
}
validation/data/iso_3166-2/NP.json000064400000001061147361033760012437 0ustar00{
  "source": "http://www.geonames.org/NP/administrative-division-nepal.html",
  "country": "Nepal",
  "subdivisions": {
    "1": "Madhyamanchal",
    "2": "Madhya Pashchimanchal",
    "3": "Pashchimanchal",
    "4": "Purwanchal",
    "5": "Sudur Pashchimanchal",
    "BA": "Bagmati",
    "BH": "Bheri",
    "DH": "Dhawalagiri",
    "GA": "Gandaki",
    "JA": "Janakpur",
    "KA": "Karnali",
    "KO": "Kosi",
    "LU": "Lumbini",
    "MA": "Mahakali",
    "ME": "Mechi",
    "NA": "Narayani",
    "RA": "Rapti",
    "SA": "Sagarmatha",
    "SE": "Seti"
  }
}
validation/data/iso_3166-2/BT.json000064400000001070147361033760012427 0ustar00{
  "source": "http://www.geonames.org/BT/administrative-division-bhutan.html",
  "country": "Bhutan",
  "subdivisions": {
    "11": "Paro",
    "12": "Chukha",
    "13": "Haa",
    "14": "Samtse",
    "15": "Thimphu",
    "21": "Tsirang",
    "22": "Dagana",
    "23": "Punakha",
    "24": "Wangdue Phodrang",
    "31": "Sarpang",
    "32": "Trongsa",
    "33": "Bumthang",
    "34": "Zhemgang",
    "41": "Trashigang",
    "42": "Mongar",
    "43": "Pemagatshel",
    "44": "Lhuntse",
    "45": "Samdrup Jongkhar",
    "GA": "Gasa",
    "TY": "Trashi Yangste"
  }
}
validation/data/iso_3166-2/GN.json000064400000001703147361033760012431 0ustar00{
  "source": "http://www.geonames.org/GN/administrative-division-guinea.html",
  "country": "Guinea",
  "subdivisions": {
    "B": "Boké",
    "BE": "Beyla",
    "BF": "Boffa",
    "BK": "Boke",
    "C": "Conakry",
    "CO": "Coyah",
    "D": "Kindia",
    "DB": "Dabola",
    "DI": "Dinguiraye",
    "DL": "Dalaba",
    "DU": "Dubreka",
    "F": "Faranah",
    "FA": "Faranah",
    "FO": "Forecariah",
    "FR": "Fria",
    "GA": "Gaoual",
    "GU": "Gueckedou",
    "K": "Kankan",
    "KA": "Kankan",
    "KB": "Koubia",
    "KD": "Kindia",
    "KE": "Kerouane",
    "KN": "Koundara",
    "KO": "Kouroussa",
    "KS": "Kissidougou",
    "L": "Labé",
    "LA": "Labe",
    "LE": "Lelouma",
    "LO": "Lola",
    "M": "Mamou",
    "MC": "Macenta",
    "MD": "Mandiana",
    "ML": "Mali",
    "MM": "Mamou",
    "N": "Nzérékoré",
    "NZ": "Nzerekore",
    "PI": "Pita",
    "SI": "Siguiri",
    "TE": "Telimele",
    "TO": "Tougue",
    "YO": "Yomou"
  }
}
validation/data/iso_3166-2/VG.json000064400000000236147361033760012441 0ustar00{
  "source": "http://www.geonames.org/VG/administrative-division-british-virgin-islands.html",
  "country": "British Virgin Islands",
  "subdivisions": []
}
validation/data/iso_3166-2/TK.json000064400000000275147361033760012446 0ustar00{
  "source": "http://www.geonames.org/TK/administrative-division-tokelau.html",
  "country": "Tokelau",
  "subdivisions": {
    "A": "Atafu",
    "F": "Fakaofo",
    "N": "Nukunonu"
  }
}
validation/data/iso_3166-2/SI.json000064400000012431147361033760012440 0ustar00{
  "source": "http://www.geonames.org/SI/administrative-division-slovenia.html",
  "country": "Slovenia",
  "subdivisions": {
    "001": "Ajdovščina",
    "002": "Beltinci",
    "003": "Bled",
    "004": "Bohinj",
    "005": "Borovnica",
    "006": "Bovec",
    "007": "Brda",
    "008": "Brezovica",
    "009": "Brežice",
    "010": "Tišina",
    "011": "Celje",
    "012": "Cerklje na Gorenjskem",
    "013": "Cerknica",
    "014": "Cerkno",
    "015": "Črenšovci",
    "016": "Črna na Koroškem",
    "017": "Črnomelj",
    "018": "Destrnik",
    "019": "Divača",
    "020": "Dobrepolje",
    "021": "Dobrova-Polhov Gradec",
    "022": "Dol pri Ljubljani",
    "023": "Domžale",
    "024": "Dornava",
    "025": "Dravograd",
    "026": "Duplek",
    "027": "Gorenja Vas-Poljane",
    "028": "Gorišnica",
    "029": "Gornja Radgona",
    "030": "Gornji Grad",
    "031": "Gornji Petrovci",
    "032": "Grosuplje",
    "033": "Šalovci",
    "034": "Hrastnik",
    "035": "Hrpelje-Kozina",
    "036": "Idrija",
    "037": "Ig",
    "038": "Ilirska Bistrica",
    "039": "Ivančna Gorica",
    "040": "Izola/Isola",
    "041": "Jesenice",
    "042": "Juršinci",
    "043": "Kamnik",
    "044": "Kanal",
    "045": "Kidričevo",
    "046": "Kobarid",
    "047": "Kobilje",
    "048": "Kočevje",
    "049": "Komen",
    "050": "Koper/Capodistria",
    "051": "Kozje",
    "052": "Kranj",
    "053": "Kranjska Gora",
    "054": "Krško",
    "055": "Kungota",
    "056": "Kuzma",
    "057": "Laško",
    "058": "Lenart",
    "059": "Lendava/Lendva",
    "060": "Litija",
    "061": "Ljubljana",
    "062": "Ljubno",
    "063": "Ljutomer",
    "064": "Logatec",
    "065": "Loška Dolina",
    "066": "Loški Potok",
    "067": "Luče",
    "068": "Lukovica",
    "069": "Majšperk",
    "070": "Maribor",
    "071": "Medvode",
    "072": "Mengeš",
    "073": "Metlika",
    "074": "Mežica",
    "075": "Miren-Kostanjevica",
    "076": "Mislinja",
    "077": "Moravče",
    "078": "Moravske Toplice",
    "079": "Mozirje",
    "080": "Murska Sobota",
    "081": "Muta",
    "082": "Naklo",
    "083": "Nazarje",
    "084": "Nova Gorica",
    "085": "Novo Mesto",
    "086": "Odranci",
    "087": "Ormož",
    "088": "Osilnica",
    "089": "Pesnica",
    "090": "Piran/Pirano",
    "091": "Pivka",
    "092": "Podčetrtek",
    "093": "Podvelka",
    "094": "Postojna",
    "095": "Preddvor",
    "096": "Ptuj",
    "097": "Puconci",
    "098": "Rače-Fram",
    "099": "Radeče",
    "100": "Radenci",
    "101": "Radlje ob Dravi",
    "102": "Radovljica",
    "103": "Ravne na Koroškem",
    "104": "Ribnica",
    "105": "Rogašovci",
    "106": "Rogaška Slatina",
    "107": "Rogatec",
    "108": "Ruše",
    "109": "Semič",
    "110": "Sevnica",
    "111": "Sežana",
    "112": "Slovenj Gradec",
    "113": "Slovenska Bistrica",
    "114": "Slovenske Konjice",
    "115": "Starše",
    "116": "Sveti Jurij",
    "117": "Šenčur",
    "118": "Šentilj",
    "119": "Šentjernej",
    "120": "Šentjur",
    "121": "Škocjan",
    "122": "Škofja Loka",
    "123": "Škofljica",
    "124": "Šmarje pri Jelšah",
    "125": "Šmartno ob Paki",
    "126": "Šoštanj",
    "127": "Štore",
    "128": "Tolmin",
    "129": "Trbovlje",
    "130": "Trebnje",
    "131": "Tržič",
    "132": "Turnišče",
    "133": "Velenje",
    "134": "Velike Lašče",
    "135": "Videm",
    "136": "Vipava",
    "137": "Vitanje",
    "138": "Vodice",
    "139": "Vojnik",
    "140": "Vrhnika",
    "141": "Vuzenica",
    "142": "Zagorje ob Savi",
    "143": "Zavrč",
    "144": "Zreče",
    "146": "Železniki",
    "147": "Žiri",
    "148": "Benedikt",
    "149": "Bistrica ob Sotli",
    "150": "Bloke",
    "151": "Braslovče",
    "152": "Cankova",
    "153": "Cerkvenjak",
    "154": "Dobje",
    "155": "Dobrna",
    "156": "Dobrovnik-Dobronak",
    "157": "Dolenjske Toplice",
    "158": "Grad",
    "159": "Hajdina",
    "160": "Hoče-Slivnica",
    "161": "Hodoš/Hodos",
    "162": "Horjul",
    "163": "Jezersko",
    "164": "Komenda",
    "165": "Kostel",
    "166": "Križevci",
    "167": "Lovrenc na Pohorju",
    "168": "Markovci",
    "169": "Miklavž na Dravskem polju",
    "170": "Mirna Peč",
    "171": "Oplotnica",
    "172": "Podlehnik",
    "173": "Polzela",
    "174": "Prebold",
    "175": "Prevalje",
    "176": "Razkrižje",
    "177": "Ribnica na Pohorju",
    "178": "Selnica ob Dravi",
    "179": "Sodražica",
    "180": "Solčava",
    "181": "Sveta Ana",
    "182": "Sveti Andraž v Slovenskih goricah",
    "183": "Šempeter-Vrtojba",
    "184": "Tabor",
    "185": "Trnovska vas",
    "186": "Trzin",
    "187": "Velika Polana",
    "188": "Veržej",
    "189": "Vransko",
    "190": "Žalec",
    "191": "Žetale",
    "192": "Žirovnica",
    "193": "Žužemberk",
    "194": "Šmartno pri Litiji",
    "195": "Apače",
    "196": "Cirkulane",
    "197": "Kosanjevica na Krki",
    "198": "Makole",
    "199": "Mokronog-Trebelno",
    "200": "Poljčane",
    "201": "Renče-Vogrsko",
    "202": "Središče ob Dravi",
    "203": "Straža",
    "204": "Sveta Trojica v Slovenskih Goricah",
    "205": "Sveti Tomaž",
    "206": "Šmarješke Toplice",
    "207": "Gorje",
    "208": "Log-Dragomer",
    "209": "Rečica ob Savinji",
    "210": "Sveti Jurij v Slovenskih Goricah",
    "211": "Šentrupert",
    "212": "Mirna",
    "213": "Ankaran"
  }
}
validation/data/iso_3166-2/MS.json000064400000000206147361033760012441 0ustar00{
  "source": "http://www.geonames.org/MS/administrative-division-montserrat.html",
  "country": "Montserrat",
  "subdivisions": []
}
validation/data/iso_3166-2/BS.json000064400000001736147361033760012437 0ustar00{
  "source": "http://www.geonames.org/BS/administrative-division-bahamas.html",
  "country": "Bahamas",
  "subdivisions": {
    "AK": "Acklins Islands",
    "BI": "Bimini and Cat Cay",
    "BP": "Black Point",
    "BY": "Berry Islands",
    "CE": "Central Eleuthera",
    "CI": "Cat Island",
    "CK": "Crooked Island and Long Cay",
    "CO": "Central Abaco",
    "CS": "Central Andros",
    "EG": "East Grand Bahama",
    "EX": "Exuma",
    "FP": "City of Freeport",
    "GC": "Grand Cay",
    "HI": "Harbour Island",
    "HT": "Hope Town",
    "IN": "Inagua",
    "LI": "Long Island",
    "MC": "Mangrove Cay",
    "MG": "Mayaguana",
    "MI": "Moore's Island",
    "NE": "North Eleuthera",
    "NO": "North Abaco",
    "NP": "New Providence",
    "NS": "North Andros",
    "RC": "Rum Cay",
    "RI": "Ragged Island",
    "SA": "South Andros",
    "SE": "South Eleuthera",
    "SO": "South Abaco",
    "SS": "San Salvador",
    "SW": "Spanish Wells",
    "WG": "West Grand Bahama"
  }
}
validation/data/iso_3166-2/HN.json000064400000001057147361033760012434 0ustar00{
  "source": "http://www.geonames.org/HN/administrative-division-honduras.html",
  "country": "Honduras",
  "subdivisions": {
    "AT": "Atlantida",
    "CH": "Choluteca",
    "CL": "Colon",
    "CM": "Comayagua",
    "CP": "Copan",
    "CR": "Cortes",
    "EP": "El Paraiso",
    "FM": "Francisco Morazan",
    "GD": "Gracias a Dios",
    "IB": "Islas de la Bahia (Bay Islands)",
    "IN": "Intibuca",
    "LE": "Lempira",
    "LP": "La Paz",
    "OC": "Ocotepeque",
    "OL": "Olancho",
    "SB": "Santa Barbara",
    "VA": "Valle",
    "YO": "Yoro"
  }
}
validation/data/iso_3166-2/JO.json000064400000000600147361033760012430 0ustar00{
  "source": "http://www.geonames.org/JO/administrative-division-jordan.html",
  "country": "Jordan",
  "subdivisions": {
    "AJ": "Ajlun",
    "AM": "'Amman",
    "AQ": "Al 'Aqabah",
    "AT": "At Tafilah",
    "AZ": "Az Zarqa'",
    "BA": "Al Balqa'",
    "IR": "Irbid",
    "JA": "Jarash",
    "KA": "Al Karak",
    "MA": "Al Mafraq",
    "MD": "Madaba",
    "MN": "Ma'an"
  }
}
validation/data/iso_3166-2/SJ.json000064400000000315147361033760012437 0ustar00{
  "source": "http://www.geonames.org/SJ/administrative-division-svalbard-and-jan-mayen.html",
  "country": "Svalbard and Jan Mayen",
  "subdivisions": {
    "21": "Svalbard",
    "22": "Jan Mayen"
  }
}
validation/data/iso_3166-2/MW.json000064400000001406147361033760012450 0ustar00{
  "source": "http://www.geonames.org/MW/administrative-division-malawi.html",
  "country": "Malawi",
  "subdivisions": {
    "BA": "Balaka",
    "BL": "Blantyre",
    "C": "Central",
    "CK": "Chikwawa",
    "CR": "Chiradzulu",
    "CT": "Chitipa",
    "DE": "Dedza",
    "DO": "Dowa",
    "KR": "Karonga",
    "KS": "Kasungu",
    "LI": "Lilongwe",
    "LK": "Likoma",
    "MC": "Mchinji",
    "MG": "Mangochi",
    "MH": "Machinga",
    "MU": "Mulanje",
    "MW": "Mwanza",
    "MZ": "Mzimba",
    "N": "Northern",
    "NB": "Nkhata Bay",
    "NE": "Neno",
    "NI": "Ntchisi",
    "NK": "Nkhotakota",
    "NS": "Nsanje",
    "NU": "Ntcheu",
    "PH": "Phalombe",
    "RU": "Rumphi",
    "S": "Southern",
    "SA": "Salima",
    "TH": "Thyolo",
    "ZO": "Zomba"
  }
}
validation/data/iso_3166-2/EG.json000064400000001431147361033760012416 0ustar00{
  "source": "http://www.geonames.org/EG/administrative-division-egypt.html",
  "country": "Egypt",
  "subdivisions": {
    "ALX": "Al Iskandariyah",
    "ASN": "Aswan",
    "AST": "Asyut",
    "BA": "Al Bahr al Ahmar",
    "BH": "Al Buhayrah",
    "BNS": "Bani Suwayf",
    "C": "Al Qahirah",
    "DK": "Ad Daqahliyah",
    "DT": "Dumyat",
    "FYM": "Al Fayyum",
    "GH": "Al Gharbiyah",
    "GZ": "Al Jizah",
    "IS": "Al Isma'iliyah",
    "JS": "Janub Sina'",
    "KB": "Al Qalyubiyah",
    "KFS": "Kafr ash Shaykh",
    "KN": "Qina",
    "LX": "Al Uqşur",
    "MN": "Al Minya",
    "MNF": "Al Minufiyah",
    "MT": "Matruh",
    "PTS": "Bur Sa'id",
    "SHG": "Suhaj",
    "SHR": "Ash Sharqiyah",
    "SIN": "Shamal Sina'",
    "SUZ": "As Suways",
    "WAD": "Al Wadi al Jadid"
  }
}
validation/data/iso_3166-2/GR.json000064400000003757147361033760012450 0ustar00{
  "source": "http://www.geonames.org/GR/administrative-division-greece.html",
  "country": "Greece",
  "subdivisions": {
    "01": "Nomós Aitolías kai Akarnanías",
    "03": "Nomós Voiotías",
    "04": "Nomós Evvoías",
    "05": "Nomós Evrytanías",
    "06": "Nomós Fthiótidos",
    "07": "Nomós Fokídos",
    "11": "Nomós Argolídos",
    "12": "Nomós Arkadías",
    "13": "Nomós Achaḯas",
    "14": "Nomós Ileías",
    "15": "Nomós Korinthías",
    "16": "Nomós Lakonías",
    "17": "Nomós Messinías",
    "21": "Nomós Zakýnthou",
    "22": "Nomós Kerkýras",
    "23": "Nomós Kefallinías",
    "24": "Nomós Lefkádas",
    "31": "Nomós Ártis",
    "32": "Nomós Thesprotías",
    "33": "Nomós Ioannínon",
    "34": "Nomós Prevézis",
    "41": "Nomós Kardhítsas",
    "42": "Nomós Larísis",
    "43": "Nomós Magnisías",
    "44": "Nomós Trikálon",
    "51": "Nomós Grevenón",
    "52": "Nomós Drámas",
    "53": "Nomós Imathías",
    "54": "Nomós Thessaloníkis",
    "55": "Nomós Kaválas",
    "56": "Nomós Kastoriás",
    "57": "Nomós Kilkís",
    "58": "Nomós Kozánis",
    "59": "Nomós Péllis",
    "61": "Nomós Pierías",
    "62": "Nomós Serrón",
    "63": "Nomós Florínis",
    "64": "Nomós Chalkidikís",
    "69": "Agio Oros",
    "71": "Nomós Évrou",
    "72": "Nomós Xánthis",
    "73": "Nomós Rodópis",
    "81": "Nomós Dodekanísou",
    "82": "Nomós Kykládon",
    "83": "Nomós Lésvou",
    "84": "Nomós Sámou",
    "85": "Nomós Chíou",
    "91": "Nomós Irakleíou",
    "92": "Nomós Lasithíou",
    "93": "Nomós Rethýmnis",
    "94": "Nomós Chaniás",
    "A": "Anatoliki Makedonia kai Thraki",
    "A1": "Nomós Attikís",
    "B": "Kentriki Makedonia",
    "C": "Dytiki Makedonia",
    "D": "Ipeiros",
    "E": "Thessalia",
    "F": "Ionia Nisia",
    "G": "Dytiki Ellada",
    "H": "Sterea Ellada",
    "I": "Attiki",
    "J": "Peloponnisos",
    "K": "Voreio Aigaio",
    "L": "Notio Aigaio",
    "M": "Kriti"
  }
}
validation/data/iso_3166-2/BY.json000064400000000505147361033760012436 0ustar00{
  "source": "http://www.geonames.org/BY/administrative-division-belarus.html",
  "country": "Belarus",
  "subdivisions": {
    "BR": "Brest voblast",
    "HM": "Horad Minsk",
    "HO": "Homyel voblast",
    "HR": "Hrodna voblast",
    "MA": "Mahilyow voblast",
    "MI": "Minsk voblast",
    "VI": "Vitsebsk voblast"
  }
}
validation/data/iso_3166-2/SH.json000064400000000333147361033760012435 0ustar00{
  "source": "http://www.geonames.org/SH/administrative-division-saint-helena.html",
  "country": "Saint Helena",
  "subdivisions": {
    "AC": "Ascension",
    "HL": "Saint Helena",
    "TA": "Tristan da Cunha"
  }
}
validation/data/iso_3166-2/SE.json000064400000001144147361033760012433 0ustar00{
  "source": "http://www.geonames.org/SE/administrative-division-sweden.html",
  "country": "Sweden",
  "subdivisions": {
    "AB": "Stockholms",
    "AC": "Vasterbottens",
    "BD": "Norrbottens",
    "C": "Uppsala",
    "D": "Sodermanlands",
    "E": "Ostergotlands",
    "F": "Jonkopings",
    "G": "Kronobergs",
    "H": "Kalmar",
    "I": "Gotlands",
    "K": "Blekinge",
    "M": "Skåne",
    "N": "Hallands",
    "O": "Västra Götaland",
    "S": "Varmlands",
    "T": "Orebro",
    "U": "Vastmanlands",
    "W": "Dalarna",
    "X": "Gavleborgs",
    "Y": "Vasternorrlands",
    "Z": "Jamtlands"
  }
}
validation/data/iso_3166-2/MM.json000064400000000747147361033760012445 0ustar00{
  "source": "http://www.geonames.org/MM/administrative-division-myanmar.html",
  "country": "Myanmar [Burma]",
  "subdivisions": {
    "01": "Sagaing",
    "02": "Bago",
    "03": "Magway",
    "04": "Mandalay",
    "05": "Tanintharyi",
    "06": "Yangon",
    "07": "Ayeyarwady",
    "11": "Kachin State",
    "12": "Kayah State",
    "13": "Kayin State",
    "14": "Chin State",
    "15": "Mon State",
    "16": "Rakhine State",
    "17": "Shan State",
    "18": "Nay Pyi Taw"
  }
}
validation/data/iso_3166-2/PH.json000064400000005172147361033760012440 0ustar00{
  "source": "http://www.geonames.org/PH/administrative-division-philippines.html",
  "country": "Philippines",
  "subdivisions": {
    "00": "National Capital Region",
    "01": "Ilocos",
    "02": "Cagayan Valley",
    "03": "Central Luzon",
    "05": "Bicol",
    "06": "Western Visayas",
    "07": "Central Visayas",
    "08": "Eastern Visayas",
    "09": "Zamboanga Peninsula",
    "10": "Northern Mindanao",
    "11": "Davao",
    "12": "Soccsksargen",
    "13": "Caraga",
    "14": "Autonomous Region in Muslim Mindanao,",
    "15": "Cordillera Administrative Region",
    "40": "Calabarzon",
    "41": "Mimaropa",
    "ABR": "Abra",
    "AGN": "Agusan del Norte",
    "AGS": "Agusan del Sur",
    "AKL": "Aklan",
    "ALB": "Albay",
    "ANT": "Antique",
    "APA": "Apayao",
    "AUR": "Aurora",
    "BAN": "Bataan",
    "BAS": "Basilan",
    "BEN": "Benguet",
    "BIL": "Biliran",
    "BOH": "Bohol",
    "BTG": "Batangas",
    "BTN": "Batanes",
    "BUK": "Bukidnon",
    "BUL": "Bulacan",
    "CAG": "Cagayan",
    "CAM": "Camiguin",
    "CAN": "Camarines Norte",
    "CAP": "Capiz",
    "CAS": "Camarines Sur",
    "CAT": "Catanduanes",
    "CAV": "Cavite",
    "CEB": "Cebu",
    "COM": "Compostela Valley",
    "DAO": "Davao Oriental",
    "DAS": "Davao del Sur",
    "DAV": "Davao del Norte",
    "DIN": "Dinagat Islands",
    "DVO": "Davao Occidental",
    "EAS": "Eastern Samar",
    "GUI": "Guimaras",
    "IFU": "Ifugao",
    "ILI": "Iloilo",
    "ILN": "Ilocos Norte",
    "ILS": "Ilocos Sur",
    "ISA": "Isabela",
    "KAL": "Kalinga",
    "LAG": "Laguna",
    "LAN": "Lanao del Norte",
    "LAS": "Lanao del Sur",
    "LEY": "Leyte",
    "LUN": "La Union",
    "MAD": "Marinduque",
    "MAG": "Maguindanao",
    "MAS": "Masbate",
    "MDC": "Mindoro Occidental",
    "MDR": "Mindoro Oriental",
    "MOU": "Mountain Province",
    "MSC": "Misamis Occidental",
    "MSR": "Misamis Oriental",
    "NCO": "North Cotabato",
    "NEC": "Negros Occidental",
    "NER": "Negros Oriental",
    "NSA": "Northern Samar",
    "NUE": "Nueva Ecija",
    "NUV": "Nueva Vizcaya",
    "PAM": "Pampanga",
    "PAN": "Pangasinan",
    "PLW": "Palawan",
    "QUE": "Quezon",
    "QUI": "Quirino",
    "RIZ": "Rizal",
    "ROM": "Romblon",
    "SAR": "Sarangani",
    "SCO": "South Cotabato",
    "SIG": "Siquijor",
    "SLE": "Southern Leyte",
    "SLU": "Sulu",
    "SOR": "Sorsogon",
    "SUK": "Sultan Kudarat",
    "SUN": "Surigao del Norte",
    "SUR": "Surigao del Sur",
    "TAR": "Tarlac",
    "TAW": "Tawi-Tawi",
    "WSA": "Western Samar",
    "ZAN": "Zamboanga del Norte",
    "ZAS": "Zamboanga del Sur",
    "ZMB": "Zambales",
    "ZSI": "Zamboanga Sibugay"
  }
}
validation/data/iso_3166-2/TO.json000064400000000342147361033760012445 0ustar00{
  "source": "http://www.geonames.org/TO/administrative-division-tonga.html",
  "country": "Tonga",
  "subdivisions": {
    "01": "Eua",
    "02": "Ha'apai",
    "03": "Niuas",
    "04": "Tongatapu",
    "05": "Vava'u"
  }
}
validation/data/iso_3166-2/TC.json000064400000001007147361033760012430 0ustar00{
  "source": "http://www.geonames.org/TC/administrative-division-turks-and-caicos-islands.html",
  "country": "Turks and Caicos Islands",
  "subdivisions": {
    "AC": "Ambergris Cays",
    "DC": "Dellis Cay",
    "EC": "East Caicos",
    "FC": "French Cay",
    "GT": "Grand Turk",
    "LW": "Little Water Cay",
    "MC": "Middle Caicos",
    "NC": "North Caicos",
    "PN": "Pine Cay",
    "PR": "Providenciales",
    "RC": "Parrot Cay",
    "SC": "South Caicos",
    "SL": "Salt Cay",
    "WC": "West Caicos"
  }
}
validation/data/iso_3166-2/NG.json000064400000001551147361033760012432 0ustar00{
  "source": "http://www.geonames.org/NG/administrative-division-nigeria.html",
  "country": "Nigeria",
  "subdivisions": {
    "AB": "Abia",
    "AD": "Adamawa",
    "AK": "Akwa Ibom",
    "AN": "Anambra",
    "BA": "Bauchi",
    "BE": "Benue",
    "BO": "Borno",
    "BY": "Bayelsa",
    "CR": "Cross River",
    "DE": "Delta",
    "EB": "Ebonyi",
    "ED": "Edo",
    "EK": "Ekiti",
    "EN": "Enugu",
    "FC": "Federal Capital Territory",
    "GO": "Gombe",
    "IM": "Imo",
    "JI": "Jigawa",
    "KD": "Kaduna",
    "KE": "Kebbi",
    "KN": "Kano",
    "KO": "Kogi",
    "KT": "Katsina",
    "KW": "Kwara",
    "LA": "Lagos",
    "NA": "Nassarawa",
    "NI": "Niger",
    "OG": "Ogun",
    "ON": "Ondo",
    "OS": "Osun",
    "OY": "Oyo",
    "PL": "Plateau",
    "RI": "Rivers",
    "SO": "Sokoto",
    "TA": "Taraba",
    "YO": "Yobe",
    "ZA": "Zamfara"
  }
}
validation/data/iso_3166-2/LV.json000064400000007101147361033760012444 0ustar00{
  "source": "http://www.geonames.org/LV/administrative-division-latvia.html",
  "country": "Latvia",
  "subdivisions": {
    "001": "Aglonas Novads",
    "002": "Aizkraukles Novads",
    "003": "Aizputes Novads",
    "004": "Aknīstes Novads",
    "005": "Alojas Novads",
    "006": "Alsungas Novads",
    "007": "Alūksnes Novads",
    "008": "Amatas Novads",
    "009": "Apes Novads",
    "010": "Auces Novads",
    "011": "Ādažu Novads",
    "012": "Babītes Novads",
    "013": "Baldones Novads",
    "014": "Baltinavas Novads",
    "015": "Balvu Novads",
    "016": "Bauskas Novads",
    "017": "Beverīnas Novads",
    "018": "Brocēnu Novads",
    "019": "Burtnieku Novads",
    "020": "Carnikavas Novads",
    "021": "Cesvaines Novads",
    "022": "Cēsu Novads",
    "023": "Ciblas Novads",
    "024": "Dagdas Novads",
    "025": "Daugavpils Novads",
    "026": "Dobeles Novads",
    "027": "Dundagas Novads",
    "028": "Durbes Novads",
    "029": "Engures Novads",
    "030": "Ērgļu Novads",
    "031": "Garkalnes Novads",
    "032": "Grobiņas Novads",
    "033": "Gulbenes Novads",
    "034": "Iecavas Novads",
    "035": "Ikšķiles Novads",
    "036": "Ilūkstes Novads",
    "037": "Inčukalna Novads",
    "038": "Jaunjelgavas Novads",
    "039": "Jaunpiebalgas Novads",
    "040": "Jaunpils Novads",
    "041": "Jelgavas Novads",
    "042": "Jēkabpils Novads",
    "043": "Kandavas Novads",
    "044": "Kārsavas Novads",
    "045": "Kocēnu Novads",
    "046": "Kokneses Novads",
    "047": "Krāslavas Novads",
    "048": "Krimuldas Novads",
    "049": "Krustpils Novads",
    "050": "Kuldīgas Novads",
    "051": "Ķeguma Novads",
    "052": "Ķekavas Novads",
    "053": "Lielvārdes Novads",
    "054": "Limbažu Novads",
    "055": "Līgatnes Novads",
    "056": "Līvānu Novads",
    "057": "Lubānas Novads",
    "058": "Ludzas Novads",
    "059": "Madonas Novads",
    "060": "Mazsalacas Novads",
    "061": "Mālpils Novads",
    "062": "Mārupes Novads",
    "063": "Mērsraga novads",
    "064": "Naukšēnu Novads",
    "065": "Neretas Novads",
    "066": "Nīcas Novads",
    "067": "Ogres Novads",
    "068": "Olaines Novads",
    "069": "Ozolnieku Novads",
    "070": "Pārgaujas Novads",
    "071": "Pāvilostas Novads",
    "072": "Pļaviņu Novads",
    "073": "Preiļu Novads",
    "074": "Priekules Novads",
    "075": "Priekuļu Novads",
    "076": "Raunas Novads",
    "077": "Rēzeknes Novads",
    "078": "Riebiņu Novads",
    "079": "Rojas Novads",
    "080": "Ropažu Novads",
    "081": "Rucavas Novads",
    "082": "Rugāju Novads",
    "083": "Rundāles Novads",
    "084": "Rūjienas Novads",
    "085": "Salas Novads",
    "086": "Salacgrīvas Novads",
    "087": "Salaspils Novads",
    "088": "Saldus Novads",
    "089": "Saulkrastu Novads",
    "090": "Sējas Novads",
    "091": "Siguldas Novads",
    "092": "Skrīveru Novads",
    "093": "Skrundas Novads",
    "094": "Smiltenes Novads",
    "095": "Stopiņu Novads",
    "096": "Strenču Novads",
    "097": "Talsu Novads",
    "098": "Tērvetes Novads",
    "099": "Tukuma Novads",
    "100": "Vaiņodes Novads",
    "101": "Valkas Novads",
    "102": "Varakļānu Novads",
    "103": "Vārkavas Novads",
    "104": "Vecpiebalgas Novads",
    "105": "Vecumnieku Novads",
    "106": "Ventspils Novads",
    "107": "Viesītes Novads",
    "108": "Viļakas Novads",
    "109": "Viļānu Novads",
    "110": "Zilupes Novads",
    "DGV": "Daugavpils",
    "JEL": "Jelgava",
    "JKB": "Jēkabpils",
    "JUR": "Jurmala",
    "LPX": "Liepaja",
    "REZ": "Rezekne",
    "RIX": "Riga",
    "VEN": "Ventspils",
    "VMR": "Valmiera"
  }
}
validation/data/iso_3166-2/PL.json000064400000001031147361033760012432 0ustar00{
  "source": "http://www.geonames.org/PL/administrative-division-poland.html",
  "country": "Poland",
  "subdivisions": {
    "DS": "Dolnoslaskie",
    "KP": "Kujawsko-Pomorskie",
    "LB": "Lubuskie",
    "LD": "Lodzkie",
    "LU": "Lubelskie",
    "MA": "Malopolskie",
    "MZ": "Mazowieckie",
    "OP": "Opolskie",
    "PD": "Podlaskie",
    "PK": "Podkarpackie",
    "PM": "Pomorskie",
    "SK": "Swietokrzyskie",
    "SL": "Slaskie",
    "WN": "Warminsko-Mazurskie",
    "WP": "Wielkopolskie",
    "ZP": "Zachodniopomorskie"
  }
}
validation/data/iso_3166-2/TT.json000064400000001063147361033760012453 0ustar00{
  "source": "http://www.geonames.org/TT/administrative-division-trinidad-and-tobago.html",
  "country": "Trinidad and Tobago",
  "subdivisions": {
    "ARI": "Arima",
    "CHA": "Chaguanas",
    "CTT": "Couva/Tabaquite/Talparo",
    "DMN": "Diego Martin",
    "MRC": "Mayaro/Rio Claro",
    "PED": "Penal/Debe",
    "POS": "Port of Spain",
    "PRT": "Princes Town",
    "PTF": "Point Fortin",
    "SFO": "San Fernando",
    "SGE": "Sangre Grande",
    "SIP": "Siparia",
    "SJL": "San Juan/Laventille",
    "TOB": "Tobago",
    "TUP": "Tunapuna/Piarco"
  }
}
validation/data/iso_3166-2/GF.json000064400000000214147361033760012415 0ustar00{
  "source": "http://www.geonames.org/GF/administrative-division-french-guiana.html",
  "country": "French Guiana",
  "subdivisions": []
}
validation/data/iso_3166-2/XK.json000064400000000176147361033760012452 0ustar00{
  "source": "http://www.geonames.org/XK/administrative-division-kosovo.html",
  "country": "Kosovo",
  "subdivisions": []
}
validation/data/iso_3166-2/BD.json000064400000004006147361033760012411 0ustar00{
  "source": "http://www.geonames.org/BD/administrative-division-bangladesh.html",
  "country": "Bangladesh",
  "subdivisions": {
    "01": "Bandarban zila",
    "02": "Barguna zila",
    "03": "Bogra zila",
    "04": "Brahmanbaria zila",
    "05": "Bagerhat zila",
    "06": "Barisal zila",
    "07": "Bhola zila",
    "08": "Comilla zila",
    "09": "Chandpur zila",
    "10": "Chittagong zila",
    "11": "Cox's Bazar zila",
    "12": "Chuadanga zila",
    "13": "Dhaka zila",
    "14": "Dinajpur zila",
    "15": "Faridpur zila",
    "16": "Feni zila",
    "17": "Gopalganj zila",
    "18": "Gazipur zila",
    "19": "Gaibandha zila",
    "20": "Habiganj zila",
    "21": "Jamalpur zila",
    "22": "Jessore zila",
    "23": "Jhenaidah zila",
    "24": "Jaipurhat zila",
    "25": "Jhalakati zila",
    "26": "Kishoreganj zila",
    "27": "Khulna zila",
    "28": "Kurigram zila",
    "29": "Khagrachari zila",
    "30": "Kushtia zila",
    "31": "Lakshmipur zila",
    "32": "Lalmonirhat zila",
    "33": "Manikganj zila",
    "34": "Mymensingh zila",
    "35": "Munshiganj zila",
    "36": "Madaripur zila",
    "37": "Magura zila",
    "38": "Moulvibazar zila",
    "39": "Meherpur zila",
    "40": "Narayanganj zila",
    "41": "Netrakona zila",
    "42": "Narsingdi zila",
    "43": "Narail zila",
    "44": "Natore zila",
    "45": "Nawabganj zila",
    "46": "Nilphamari zila",
    "47": "Noakhali zila",
    "48": "Naogaon zila",
    "49": "Pabna zila",
    "50": "Pirojpur zila",
    "51": "Patuakhali zila",
    "52": "Panchagarh zila",
    "53": "Rajbari zila",
    "54": "Rajshahi zila",
    "55": "Rangpur zila",
    "56": "Rangamati zila",
    "57": "Sherpur zila",
    "58": "Satkhira zila",
    "59": "Sirajganj zila",
    "60": "Sylhet zila",
    "61": "Sunamganj zila",
    "62": "Shariatpur zila",
    "63": "Tangail zila",
    "64": "Thakurgaon zila",
    "A": "Barisal",
    "B": "Chittagong",
    "C": "Dhaka",
    "D": "Khulna",
    "E": "Rajshahi",
    "F": "Rangpur",
    "G": "Sylhet",
    "H": "Mymensingh Division"
  }
}
validation/data/iso_3166-2/ER.json000064400000000537147361033760012437 0ustar00{
  "source": "http://www.geonames.org/ER/administrative-division-eritrea.html",
  "country": "Eritrea",
  "subdivisions": {
    "AN": "Anseba (Keren)",
    "DK": "Southern Red Sea (Debub-Keih-Bahri)",
    "DU": "Southern (Debub)",
    "GB": "Gash-Barka (Barentu)",
    "MA": "Central (Maekel)",
    "SK": "Northern Red Sea (Semien-Keih-Bahri)"
  }
}
validation/data/iso_3166-2/WS.json000064400000000603147361033760012454 0ustar00{
  "source": "http://www.geonames.org/WS/administrative-division-samoa.html",
  "country": "Samoa",
  "subdivisions": {
    "AA": "A'ana",
    "AL": "Aiga-i-le-Tai",
    "AT": "Atua",
    "FA": "Fa'asaleleaga",
    "GE": "Gaga'emauga",
    "GI": "Gagaifomauga",
    "PA": "Palauli",
    "SA": "Satupa'itea",
    "TU": "Tuamasaga",
    "VF": "Va'a-o-Fonoti",
    "VS": "Vaisigano"
  }
}
validation/data/iso_3166-2/HR.json000064400000001503147361033760012434 0ustar00{
  "source": "http://www.geonames.org/HR/administrative-division-croatia.html",
  "country": "Croatia",
  "subdivisions": {
    "01": "Zagreb county",
    "02": "Krapina-Zagorje county",
    "03": "Sisak-Moslavina county",
    "04": "Karlovac county",
    "05": "Varazdin county",
    "06": "Koprivnica-Krizevci county",
    "07": "Bjelovar-Bilogora county",
    "08": "Primorje-Gorski Kotar county",
    "09": "Lika-Senj county",
    "10": "Virovitica-Podravina county",
    "11": "Pozega-Slavonia county",
    "12": "Brod-Posavina county",
    "13": "Zadar county",
    "14": "Osijek-Baranja county",
    "15": "Sibenik-Knin county",
    "16": "Vukovar-Srijem county",
    "17": "Split-Dalmatia county",
    "18": "Istria county",
    "19": "Dubrovnik-Neretva county",
    "20": "Medjimurje county",
    "21": "Zagreb (city)"
  }
}
validation/data/iso_3166-2/TV.json000064400000000463147361033760012460 0ustar00{
  "source": "http://www.geonames.org/TV/administrative-division-tuvalu.html",
  "country": "Tuvalu",
  "subdivisions": {
    "FUN": "Funafuti",
    "NIT": "Niutao",
    "NKF": "Nukufetau",
    "NKL": "Nukulaelae",
    "NMA": "Nanumea",
    "NMG": "Nanumanga",
    "NUI": "Nui",
    "VAI": "Vaitupu"
  }
}
validation/data/iso_3166-2/PT.json000064400000001065147361033760012451 0ustar00{
  "source": "http://www.geonames.org/PT/administrative-division-portugal.html",
  "country": "Portugal",
  "subdivisions": {
    "01": "Aveiro",
    "02": "Beja",
    "03": "Braga",
    "04": "Braganca",
    "05": "Castelo Branco",
    "06": "Coimbra",
    "07": "Evora",
    "08": "Faro",
    "09": "Guarda",
    "10": "Leiria",
    "11": "Lisboa",
    "12": "Portalegre",
    "13": "Porto",
    "14": "Santarem",
    "15": "Setubal",
    "16": "Viana do Castelo",
    "17": "Vila Real",
    "18": "Viseu",
    "20": "Acores (Azores)",
    "30": "Madeira"
  }
}
validation/CHANGELOG.md000064400000007150147361033760010524 0ustar00# Changes in Respect\Validation 1.0

All notable changes of the Respect\Validation releases are documented in this file.

## 1.1.0 - 2016-04-24

### Added

- Create "Fibonacci" rule (#637)
- Create "IdentityCard" rule (#632)
- Create "Image" rule (#621)
- Create "LanguageCode" rule (#597)
- Create "Pesel" rule (#616)
- Create "PhpLabel" rule (#652)

### Changed

- Allow the define brands for credit card validation (#661)
- Define names for the child of Not rule (#641)
- Ensure namespace separator on appended prefixes (#666)
- Length gets length of integers (#643)
- Set template for the only rule in the chain (#663)
- Throw an exception when age is not an integer (#667)
- Use "{less/greater} than or equal to" phrasing (#604)

## 1.0.0 - 2015-10-24

### Added

- Add "alpha-3" and "numeric" formats for "CountryCode" rule (#530)
- Add support for PHP 7 (#426)
- Create "BoolVal" rule (#583)
- Create "Bsn" rule (#450)
- Create "CallableType" rule (#397)
- Create "Countable" rule (#566)
- Create "CurrencyCode" rule (#567)
- Create "Extension" rule (#360)
- Create "Factor" rule (#405)
- Create "Finite" rule (#397)
- Create "FloatType" rule (#565)
- Create "Identical" rule (#442)
- Create "Imei" rule (#590)
- Create "Infinite" rule (#397)
- Create "IntType" rule (#451)
- Create "Iterable" rule (#570)
- Create "KeyNested" rule (#429)
- Create "KeySet" rule (#374)
- Create "KeyValue" rule (#441)
- Create "Mimetype" rule (#361)
- Create "NotBlank" rule (#443)
- Create "NotOptional" rule (#448)
- Create "Optional" rule (#423)
- Create "ResourceType" rule (#397)
- Create "ScalarVal" rule (#397)
- Create "Size" rule (#359)
- Create "SubdivisionCode" rule for 252 countries (#411)
- Create "VideoUrl" rule (#410)
- Create method `getMessages()` for nested exceptions (#406)

### Changed

- Add country code to the message of "PostalCode" exception rule (#413)
- Make "ArrayVal" validate only if the input can be used as an array (#574)
- Make "Between" rule inclusive (#445)
- Make "Max" rule inclusive (#445)
- Make "Min" rule inclusive (#445)
- New generic top-level domains (#368)
- On `AbstractRelated` (`Attribute`, `Call` and `Key`) define names for child rules (#365)
- On exceptions, convert `Array` to string (#387)
- On exceptions, convert `Exception` to string (#399)
- On exceptions, convert `Traversable` to string (#399)
- On exceptions, convert resources to string (#399)
- On exceptions, do not display parent message then rule has only one child (#407)
- On exceptions, improve `Object` conversion to string (#399)
- On exceptions, improve conversion of all values by using JSON (#399)
- On exceptions, nested messages are displayed in a Markdown list (#588)
- Rename exception class "AbstractGroupedException" to "GroupedValidationException" (#591)
- Rename exception class "AbstractNestedException" to "NestedValidationException" (#591)
- Rename rule "Arr" to "ArrayVal"
- Rename rule "Bool" to "BoolType" (#426)
- Rename rule "False" to "FalseVal" (#426)
- Rename rule "Float" to "FloatVal" (#426)
- Rename rule "Int" to "IntVal" (#426)
- Rename rule "NullValue" to "NullType"
- Rename rule "Object" to "ObjectType"
- Rename rule "String" to "StringType" (#426)
- Rename rule "True" to "TrueVal" (#426)
- Use `filter_var()` on "TrueVal" and "FalseVal" rules (#409)

### Removed

- Drop support for PHP 5.3 (#466)
- Remove `addOr()` shortcut (#444)
- Remove `NestedValidationExceptionInterface` interface (#591)
- Remove `not()` shortcut (#444)
- Remove `ValidationExceptionInterface` interface (#591)
- Remove identical checking from "Equals" rule (#442)
- Removed Deprecated Rules (#277)
- Validation rules do not accept an empty string by default (#422)
validation/LICENSE000064400000002115147361033760007714 0ustar00MIT License

Copyright (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>

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.
validation/library/Message/ParameterStringifier.php000064400000000705147361033760016601 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Message;

interface ParameterStringifier
{
    /**
     * @param mixed $value
     */
    public function stringify(string $name, $value): string;
}
validation/library/Message/Formatter.php000064400000002664147361033760014424 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Message;

use function call_user_func;
use function preg_replace_callback;
use function Respect\Stringifier\stringify;

final class Formatter
{
    /**
     * @var callable
     */
    private $translator;

    /**
     * @var ParameterStringifier
     */
    private $parameterStringifier;

    public function __construct(callable $translator, ParameterStringifier $parameterStringifier)
    {
        $this->translator = $translator;
        $this->parameterStringifier = $parameterStringifier;
    }

    /**
     * @param mixed $input
     * @param mixed[] $parameters
     */
    public function format(string $template, $input, array $parameters): string
    {
        $parameters['name'] = $parameters['name'] ?? stringify($input);

        return preg_replace_callback(
            '/{{(\w+)}}/',
            function ($match) use ($parameters) {
                if (!isset($parameters[$match[1]])) {
                    return $match[0];
                }

                return $this->parameterStringifier->stringify($match[1], $parameters[$match[1]]);
            },
            call_user_func($this->translator, $template)
        );
    }
}
validation/library/Message/Stringifier/KeepOriginalStringName.php000064400000001362147361033760021301 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Message\Stringifier;

use Respect\Validation\Message\ParameterStringifier;

use function is_string;
use function Respect\Stringifier\stringify;

final class KeepOriginalStringName implements ParameterStringifier
{
    /**
     * {@inheritDoc}
     */
    public function stringify(string $name, $value): string
    {
        if ($name === 'name' && is_string($value)) {
            return $value;
        }

        return stringify($value);
    }
}
validation/library/Validator.php000064400000003531147361033760013014 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Rules\AllOf;

use function count;

/**
 * @mixin StaticValidator
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Validator extends AllOf
{
    /**
     * Create instance validator.
     */
    public static function create(): self
    {
        return new self();
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        try {
            parent::check($input);
        } catch (ValidationException $exception) {
            if (count($this->getRules()) == 1 && $this->template) {
                $exception->updateTemplate($this->template);
            }

            throw $exception;
        }
    }

    /**
     * Creates a new Validator instance with a rule that was called on the static method.
     *
     * @param mixed[] $arguments
     *
     * @throws ComponentException
     */
    public static function __callStatic(string $ruleName, array $arguments): self
    {
        return self::create()->__call($ruleName, $arguments);
    }

    /**
     * Create a new rule by the name of the method and adds the rule to the chain.
     *
     * @param mixed[] $arguments
     *
     * @throws ComponentException
     */
    public function __call(string $ruleName, array $arguments): self
    {
        $this->addRule(Factory::getDefaultInstance()->rule($ruleName, $arguments));

        return $this;
    }
}
validation/library/StaticValidator.php000064400000027574147361033760014201 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation;

use finfo;
use Respect\Validation\Rules\Key;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidator;
use Zend\Validator\ValidatorInterface as ZendValidator;

interface StaticValidator
{
    public static function allOf(Validatable ...$rule): ChainedValidator;

    public static function alnum(string ...$additionalChars): ChainedValidator;

    public static function alpha(string ...$additionalChars): ChainedValidator;

    public static function alwaysInvalid(): ChainedValidator;

    public static function alwaysValid(): ChainedValidator;

    public static function anyOf(Validatable ...$rule): ChainedValidator;

    public static function arrayType(): ChainedValidator;

    public static function arrayVal(): ChainedValidator;

    public static function attribute(
        string $reference,
        ?Validatable $validator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public static function base(int $base, ?string $chars = null): ChainedValidator;

    public static function base64(): ChainedValidator;

    /**
     * @param mixed $minimum
     * @param mixed $maximum
     */
    public static function between($minimum, $maximum): ChainedValidator;

    public static function bic(string $countryCode): ChainedValidator;

    public static function boolType(): ChainedValidator;

    public static function boolVal(): ChainedValidator;

    public static function bsn(): ChainedValidator;

    public static function call(callable $callable, Validatable $rule): ChainedValidator;

    public static function callableType(): ChainedValidator;

    public static function callback(callable $callback): ChainedValidator;

    public static function charset(string ...$charset): ChainedValidator;

    public static function cnh(): ChainedValidator;

    public static function cnpj(): ChainedValidator;

    public static function control(string ...$additionalChars): ChainedValidator;

    public static function consonant(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $containsValue
     */
    public static function contains($containsValue, bool $identical = false): ChainedValidator;

    /**
     * @param mixed[] $needles
     */
    public static function containsAny(array $needles, bool $strictCompareArray = false): ChainedValidator;

    public static function countable(): ChainedValidator;

    public static function countryCode(?string $set = null): ChainedValidator;

    public static function currencyCode(): ChainedValidator;

    public static function cpf(): ChainedValidator;

    public static function creditCard(?string $brand = null): ChainedValidator;

    public static function date(string $format = 'Y-m-d'): ChainedValidator;

    public static function dateTime(?string $format = null): ChainedValidator;

    public static function decimal(int $decimals): ChainedValidator;

    public static function digit(string ...$additionalChars): ChainedValidator;

    public static function directory(): ChainedValidator;

    public static function domain(bool $tldCheck = true): ChainedValidator;

    public static function each(Validatable $rule): ChainedValidator;

    public static function email(): ChainedValidator;

    /**
     * @param mixed $endValue
     */
    public static function endsWith($endValue, bool $identical = false): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function equals($compareTo): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function equivalent($compareTo): ChainedValidator;

    public static function even(): ChainedValidator;

    public static function executable(): ChainedValidator;

    public static function exists(): ChainedValidator;

    public static function extension(string $extension): ChainedValidator;

    public static function factor(int $dividend): ChainedValidator;

    public static function falseVal(): ChainedValidator;

    public static function fibonacci(): ChainedValidator;

    public static function file(): ChainedValidator;

    /**
     * @param mixed[]|int $options
     */
    public static function filterVar(int $filter, $options = null): ChainedValidator;

    public static function finite(): ChainedValidator;

    public static function floatVal(): ChainedValidator;

    public static function floatType(): ChainedValidator;

    public static function graph(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function greaterThan($compareTo): ChainedValidator;

    public static function hexRgbColor(): ChainedValidator;

    public static function iban(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function identical($compareTo): ChainedValidator;

    public static function image(?finfo $fileInfo = null): ChainedValidator;

    public static function imei(): ChainedValidator;

    /**
     * @param mixed[]|mixed $haystack
     */
    public static function in($haystack, bool $compareIdentical = false): ChainedValidator;

    public static function infinite(): ChainedValidator;

    public static function instance(string $instanceName): ChainedValidator;

    public static function intVal(): ChainedValidator;

    public static function intType(): ChainedValidator;

    public static function ip(string $range = '*', ?int $options = null): ChainedValidator;

    public static function isbn(): ChainedValidator;

    public static function iterableType(): ChainedValidator;

    public static function json(): ChainedValidator;

    public static function key(
        string $reference,
        ?Validatable $referenceValidator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public static function keyNested(
        string $reference,
        ?Validatable $referenceValidator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public static function keySet(Key ...$rule): ChainedValidator;

    public static function keyValue(string $comparedKey, string $ruleName, string $baseKey): ChainedValidator;

    public static function languageCode(?string $set = null): ChainedValidator;

    public static function leapDate(string $format): ChainedValidator;

    public static function leapYear(): ChainedValidator;

    public static function length(?int $min = null, ?int $max = null, bool $inclusive = true): ChainedValidator;

    public static function lowercase(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function lessThan($compareTo): ChainedValidator;

    public static function luhn(): ChainedValidator;

    public static function macAddress(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function max($compareTo): ChainedValidator;

    public static function maxAge(int $age, ?string $format = null): ChainedValidator;

    public static function mimetype(string $mimetype): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public static function min($compareTo): ChainedValidator;

    public static function minAge(int $age, ?string $format = null): ChainedValidator;

    public static function multiple(int $multipleOf): ChainedValidator;

    public static function negative(): ChainedValidator;

    public static function nfeAccessKey(): ChainedValidator;

    public static function nif(): ChainedValidator;

    public static function nip(): ChainedValidator;

    public static function no(bool $useLocale = false): ChainedValidator;

    public static function noneOf(Validatable ...$rule): ChainedValidator;

    public static function not(Validatable $rule): ChainedValidator;

    public static function notBlank(): ChainedValidator;

    public static function notEmoji(): ChainedValidator;

    public static function notEmpty(): ChainedValidator;

    public static function notOptional(): ChainedValidator;

    public static function noWhitespace(): ChainedValidator;

    public static function nullable(Validatable $rule): ChainedValidator;

    public static function nullType(): ChainedValidator;

    public static function number(): ChainedValidator;

    public static function numericVal(): ChainedValidator;

    public static function objectType(): ChainedValidator;

    public static function odd(): ChainedValidator;

    public static function oneOf(Validatable ...$rule): ChainedValidator;

    public static function optional(Validatable $rule): ChainedValidator;

    public static function perfectSquare(): ChainedValidator;

    public static function pesel(): ChainedValidator;

    public static function phone(): ChainedValidator;

    public static function phpLabel(): ChainedValidator;

    public static function pis(): ChainedValidator;

    public static function polishIdCard(): ChainedValidator;

    public static function positive(): ChainedValidator;

    public static function postalCode(string $countryCode): ChainedValidator;

    public static function primeNumber(): ChainedValidator;

    public static function printable(string ...$additionalChars): ChainedValidator;

    public static function punct(string ...$additionalChars): ChainedValidator;

    public static function readable(): ChainedValidator;

    public static function regex(string $regex): ChainedValidator;

    public static function resourceType(): ChainedValidator;

    public static function roman(): ChainedValidator;

    public static function scalarVal(): ChainedValidator;

    public static function sf(Constraint $constraint, ?SymfonyValidator $validator = null): ChainedValidator;

    public static function size(?string $minSize = null, ?string $maxSize = null): ChainedValidator;

    public static function slug(): ChainedValidator;

    public static function sorted(string $direction): ChainedValidator;

    public static function space(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $startValue
     */
    public static function startsWith($startValue, bool $identical = false): ChainedValidator;

    public static function stringType(): ChainedValidator;

    public static function stringVal(): ChainedValidator;

    public static function subdivisionCode(string $countryCode): ChainedValidator;

    /**
     * @param mixed[] $superset
     */
    public static function subset(array $superset): ChainedValidator;

    public static function symbolicLink(): ChainedValidator;

    public static function time(string $format = 'H:i:s'): ChainedValidator;

    public static function tld(): ChainedValidator;

    public static function trueVal(): ChainedValidator;

    public static function type(string $type): ChainedValidator;

    public static function unique(): ChainedValidator;

    public static function uploaded(): ChainedValidator;

    public static function uppercase(): ChainedValidator;

    public static function url(): ChainedValidator;

    public static function uuid(?int $version = null): ChainedValidator;

    public static function version(): ChainedValidator;

    public static function videoUrl(?string $service = null): ChainedValidator;

    public static function vowel(string ...$additionalChars): ChainedValidator;

    public static function when(Validatable $if, Validatable $then, ?Validatable $else = null): ChainedValidator;

    public static function writable(): ChainedValidator;

    public static function xdigit(string ...$additionalChars): ChainedValidator;

    public static function yes(bool $useLocale = false): ChainedValidator;

    /**
     * @param string|ZendValidator $validator
     * @param mixed[] $params
     */
    public static function zend($validator, ?array $params = null): ChainedValidator;
}
validation/library/Rules/Each.php000064400000004375147361033760013030 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\EachException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Helpers\CanValidateIterable;
use Respect\Validation\Validatable;

/**
 * Validates whether each value in the input is valid according to another rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Each extends AbstractRule
{
    use CanValidateIterable;

    /**
     * @var Validatable
     */
    private $rule;

    /**
     * Initializes the constructor.
     */
    public function __construct(Validatable $rule)
    {
        $this->rule = $rule;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if (!$this->isIterable($input)) {
            throw $this->reportError($input);
        }

        $exceptions = [];
        foreach ($input as $value) {
            try {
                $this->rule->assert($value);
            } catch (ValidationException $exception) {
                $exceptions[] = $exception;
            }
        }

        if (!empty($exceptions)) {
            /** @var EachException $eachException */
            $eachException = $this->reportError($input);
            $eachException->addChildren($exceptions);

            throw $eachException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        if (!$this->isIterable($input)) {
            throw $this->reportError($input);
        }

        foreach ($input as $value) {
            $this->rule->check($value);
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        try {
            $this->check($input);
        } catch (ValidationException $exception) {
            return false;
        }

        return true;
    }
}
validation/library/Rules/Uppercase.php000064400000001623147361033760014110 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function mb_strtoupper;

/**
 * Validates whether the characters in the input are uppercase.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class Uppercase extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return $input === mb_strtoupper($input);
    }
}
validation/library/Rules/AbstractRelated.php000064400000007247147361033760015235 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;

use function is_scalar;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
abstract class AbstractRelated extends AbstractRule
{
    /**
     * @var bool
     */
    private $mandatory = true;

    /**
     * @var mixed
     */
    private $reference;

    /**
     * @var Validatable|null
     */
    private $rule;

    /**
     * @param mixed $input
     */
    abstract public function hasReference($input): bool;

    /**
     * @param mixed $input
     *
     * @return mixed
     */
    abstract public function getReferenceValue($input);

    /**
     * @param mixed $reference
     */
    public function __construct($reference, ?Validatable $rule = null, bool $mandatory = true)
    {
        $this->reference = $reference;
        $this->rule = $rule;
        $this->mandatory = $mandatory;

        if ($rule && $rule->getName() !== null) {
            $this->setName($rule->getName());
        } elseif (is_scalar($reference)) {
            $this->setName((string) $reference);
        }
    }

    /**
     * @return mixed
     */
    public function getReference()
    {
        return $this->reference;
    }

    public function isMandatory(): bool
    {
        return $this->mandatory;
    }

    /**
     * {@inheritDoc}
     */
    public function setName(string $name): Validatable
    {
        parent::setName($name);

        if ($this->rule instanceof Validatable) {
            $this->rule->setName($name);
        }

        return $this;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $hasReference = $this->hasReference($input);
        if ($this->mandatory && !$hasReference) {
            throw $this->reportError($input, ['hasReference' => false]);
        }

        if ($this->rule === null || !$hasReference) {
            return;
        }

        try {
            $this->rule->assert($this->getReferenceValue($input));
        } catch (ValidationException $validationException) {
            /** @var NestedValidationException $nestedValidationException */
            $nestedValidationException = $this->reportError($this->reference, ['hasReference' => true]);
            $nestedValidationException->addChild($validationException);

            throw $nestedValidationException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $hasReference = $this->hasReference($input);
        if ($this->mandatory && !$hasReference) {
            throw $this->reportError($input, ['hasReference' => false]);
        }

        if ($this->rule === null || !$hasReference) {
            return;
        }

        $this->rule->check($this->getReferenceValue($input));
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $hasReference = $this->hasReference($input);
        if ($this->mandatory && !$hasReference) {
            return false;
        }

        if ($this->rule === null || !$hasReference) {
            return true;
        }

        return $this->rule->validate($this->getReferenceValue($input));
    }
}
validation/library/Rules/MinAge.php000064400000001406147361033760013320 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates a minimum age for a given date.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author Kennedy Tedesco <kennedyt.tw@gmail.com>
 */
final class MinAge extends AbstractAge
{
    /**
     * {@inheritDoc}
     */
    protected function compare(int $baseDate, int $givenDate): bool
    {
        return $baseDate >= $givenDate;
    }
}
validation/library/Rules/Base64.php000064400000001670147361033760013207 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function mb_strlen;
use function preg_match;

/**
 * Validate if a string is Base64-encoded.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jens Segers <segers.jens@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Base64 extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        if (!preg_match('#^[A-Za-z0-9+/\n\r]+={0,2}$#', $input)) {
            return false;
        }

        return mb_strlen($input) % 4 === 0;
    }
}
validation/library/Rules/NoneOf.php000064400000002447147361033760013352 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\NoneOfException;

use function count;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NoneOf extends AbstractComposite
{
    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $exceptions = $this->getAllThrownExceptions($input);
        $numRules = count($this->getRules());
        $numExceptions = count($exceptions);
        if ($numRules !== $numExceptions) {
            /** @var NoneOfException $noneOfException */
            $noneOfException = $this->reportError($input);
            $noneOfException->addChildren($exceptions);

            throw $noneOfException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        foreach ($this->getRules() as $rule) {
            if ($rule->validate($input)) {
                return false;
            }
        }

        return true;
    }
}
validation/library/Rules/NfeAccessKey.php000064400000002733147361033760014467 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_map;
use function floor;
use function mb_strlen;
use function str_split;

/**
 * Validates the access key of the Brazilian electronic invoice (NFe).
 *
 *
 * (pt-br) Valida chave de acesso de NFe, mais especificamente, relacionada ao DANFE.
 *
 * @see (pt-br) Manual de Integração do Contribuinte v4.0.1 em http://www.nfe.fazenda.gov.br
 *
 * @author Andrey Knupp Vital <andreykvital@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NfeAccessKey extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (mb_strlen($input) !== 44) {
            return false;
        }

        $digits = array_map('intval', str_split($input));
        $w = [];
        for ($i = 0, $z = 5, $m = 43; $i <= $m; ++$i) {
            $z = $i < $m ? $z - 1 == 1 ? 9 : $z - 1 : 0;
            $w[] = $z;
        }

        for ($i = 0, $s = 0, $k = 44; $i < $k; ++$i) {
            $s += $digits[$i] * $w[$i];
        }

        $s -= 11 * floor($s / 11);
        $v = $s == 0 || $s == 1 ? 0 : 11 - $s;

        return $v == $digits[43];
    }
}
validation/library/Rules/AbstractWrapper.php000064400000002574147361033760015273 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Validatable;

/**
 * Abstract class to help on creating rules that wrap rules.
 *
 * @author Alasdair North <alasdair@runway.io>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
abstract class AbstractWrapper extends AbstractRule
{
    /**
     * @var Validatable
     */
    private $validatable;

    /**
     * Initializes the rule.
     */
    public function __construct(Validatable $validatable)
    {
        $this->validatable = $validatable;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $this->validatable->assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $this->validatable->check($input);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $this->validatable->validate($input);
    }

    /**
     * {@inheritDoc}
     */
    public function setName(string $name): Validatable
    {
        $this->validatable->setName($name);

        return parent::setName($name);
    }
}
validation/library/Rules/Between.php000064400000002473147361033760013556 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Helpers\CanCompareValues;

/**
 * Validates whether the input is between two other values.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Between extends AbstractEnvelope
{
    use CanCompareValues;

    /**
     * Initializes the rule.
     *
     * @param mixed $minValue
     * @param mixed $maxValue
     *
     * @throws ComponentException
     */
    public function __construct($minValue, $maxValue)
    {
        if ($this->toComparable($minValue) >= $this->toComparable($maxValue)) {
            throw new ComponentException('Minimum cannot be less than or equals to maximum');
        }

        parent::__construct(
            new AllOf(
                new Min($minValue),
                new Max($maxValue)
            ),
            [
                'minValue' => $minValue,
                'maxValue' => $maxValue,
            ]
        );
    }
}
validation/library/Rules/Image.php000064400000002570147361033760013205 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use finfo;
use SplFileInfo;

use function is_file;
use function is_string;
use function mb_strpos;

use const FILEINFO_MIME_TYPE;

/**
 * Validates if the file is a valid image by checking its MIME type.
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Guilherme Siani <guilherme@siani.com.br>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Image extends AbstractRule
{
    /**
     * @var finfo
     */
    private $fileInfo;

    /**
     * Initializes the rule.
     */
    public function __construct(?finfo $fileInfo = null)
    {
        $this->fileInfo = $fileInfo ?: new finfo(FILEINFO_MIME_TYPE);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $this->validate($input->getPathname());
        }

        if (!is_string($input)) {
            return false;
        }

        if (!is_file($input)) {
            return false;
        }

        return mb_strpos((string) $this->fileInfo->file($input), 'image/') === 0;
    }
}
validation/library/Rules/Regex.php000064400000002052147361033760013230 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function preg_match;

/**
 * Validates whether the input matches a defined regular expression.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Regex extends AbstractRule
{
    /**
     * @var string
     */
    private $regex;

    /**
     * Initializes the rule.
     */
    public function __construct(string $regex)
    {
        $this->regex = $regex;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return preg_match($this->regex, (string) $input) > 0;
    }
}
validation/library/Rules/Printable.php000064400000001560147361033760014101 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_print;

/**
 * Validates whether an input is printable character(s).
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Printable extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_print($input);
    }
}
validation/library/Rules/MacAddress.php000064400000001705147361033760014170 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function preg_match;

/**
 * Validates whether the input is a valid MAC address.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Fábio da Silva Ribeiro <fabiorphp@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MacAddress extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return preg_match('/^(([0-9a-fA-F]{2}-){5}|([0-9a-fA-F]{2}:){5})[0-9a-fA-F]{2}$/', $input) > 0;
    }
}
validation/library/Rules/ObjectType.php000064400000001250147361033760014225 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_object;

/**
 * Validates whether the input is an object.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ObjectType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_object($input);
    }
}
validation/library/Rules/NumericVal.php000064400000001333147361033760014224 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_numeric;

/**
 * Validates whether the input is numeric.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NumericVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_numeric($input);
    }
}
validation/library/Rules/Multiple.php000064400000001607147361033760013756 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class Multiple extends AbstractRule
{
    /**
     * @var int
     */
    private $multipleOf;

    public function __construct(int $multipleOf)
    {
        $this->multipleOf = $multipleOf;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->multipleOf == 0) {
            return $input == 0;
        }

        return $input % $this->multipleOf == 0;
    }
}
validation/library/Rules/FalseVal.php000064400000001442147361033760013655 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;

use const FILTER_NULL_ON_FAILURE;
use const FILTER_VALIDATE_BOOLEAN;

/**
 * Validates if a value is considered as false.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FalseVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false;
    }
}
validation/library/Rules/LeapDate.php000064400000002320147361033760013633 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use DateTimeImmutable;
use DateTimeInterface;

use function is_scalar;

/**
 * Validates if a date is leap.
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jayson Reis <santosdosreis@gmail.com>
 */
final class LeapDate extends AbstractRule
{
    /**
     * @var string
     */
    private $format;

    /**
     * Initializes the rule with the expected format.
     */
    public function __construct(string $format)
    {
        $this->format = $format;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof DateTimeInterface) {
            return $input->format('m-d') === '02-29';
        }

        if (is_scalar($input)) {
            return $this->validate(DateTimeImmutable::createFromFormat($this->format, (string) $input));
        }

        return false;
    }
}
validation/library/Rules/Alnum.php000064400000001536147361033760013240 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_alnum;

/**
 * Validates whether the input is alphanumeric or not.
 *
 * Alphanumeric is a combination of alphabetic (a-z and A-Z) and numeric (0-9)
 * characters.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Alnum extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_alnum($input);
    }
}
validation/library/Rules/StartsWith.php000064400000003362147361033760014277 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_array;
use function mb_stripos;
use function mb_strpos;
use function reset;

/**
 * Validates whether the input starts with a given value.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Marcelo Araujo <msaraujo@php.net>
 */
final class StartsWith extends AbstractRule
{
    /**
     * @var mixed
     */
    private $startValue;

    /**
     * @var bool
     */
    private $identical;

    /**
     * @param mixed $startValue
     */
    public function __construct($startValue, bool $identical = false)
    {
        $this->startValue = $startValue;
        $this->identical = $identical;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->identical) {
            return $this->validateIdentical($input);
        }

        return $this->validateEquals($input);
    }

    /**
     * @param mixed $input
     */
    protected function validateEquals($input): bool
    {
        if (is_array($input)) {
            return reset($input) == $this->startValue;
        }

        return mb_stripos($input, $this->startValue) === 0;
    }

    /**
     * @param mixed $input
     */
    protected function validateIdentical($input): bool
    {
        if (is_array($input)) {
            return reset($input) === $this->startValue;
        }

        return mb_strpos($input, $this->startValue) === 0;
    }
}
validation/library/Rules/Isbn.php000064400000002404147361033760013052 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function implode;
use function is_scalar;
use function preg_match;
use function sprintf;

/**
 * Validates whether the input is a valid ISBN (International Standard Book Number) or not.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Moritz Fromm <moritzgitfromm@gmail.com>
 */
final class Isbn extends AbstractRule
{
    /**
     * @see https://howtodoinjava.com/regex/java-regex-validate-international-standard-book-number-isbns
     */
    private const PIECES = [
        '^(?:ISBN(?:-1[03])?:? )?(?=[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]$',
    ];

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return preg_match(sprintf('/%s/', implode(self::PIECES)), (string) $input) > 0;
    }
}
validation/library/Rules/Key.php000064400000002544147361033760012714 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Validatable;

use function array_key_exists;
use function is_array;
use function is_scalar;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Key extends AbstractRelated
{
    /**
     * @param mixed $reference
     */
    public function __construct($reference, ?Validatable $rule = null, bool $mandatory = true)
    {
        if (!is_scalar($reference) || $reference === '') {
            throw new ComponentException('Invalid array key name');
        }

        parent::__construct($reference, $rule, $mandatory);
    }

    /**
     * {@inheritDoc}
     */
    public function getReferenceValue($input)
    {
        return $input[$this->getReference()];
    }

    /**
     * {@inheritDoc}
     */
    public function hasReference($input): bool
    {
        return is_array($input) && array_key_exists($this->getReference(), $input);
    }
}
validation/library/Rules/Attribute.php000064400000002624147361033760014126 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use ReflectionException;
use ReflectionProperty;
use Respect\Validation\Validatable;

use function is_object;
use function property_exists;

/**
 * Validates an object attribute, event private ones.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Attribute extends AbstractRelated
{
    public function __construct(string $reference, ?Validatable $rule = null, bool $mandatory = true)
    {
        parent::__construct($reference, $rule, $mandatory);
    }

    /**
     * {@inheritDoc}
     *
     * @throws ReflectionException
     */
    public function getReferenceValue($input)
    {
        $propertyMirror = new ReflectionProperty($input, (string) $this->getReference());
        $propertyMirror->setAccessible(true);

        return $propertyMirror->getValue($input);
    }

    /**
     * {@inheritDoc}
     */
    public function hasReference($input): bool
    {
        return is_object($input) && property_exists($input, (string) $this->getReference());
    }
}
validation/library/Rules/Equivalent.php000064400000002352147361033760014276 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function mb_strtoupper;

/**
 * Validates if the input is equivalent to some value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Equivalent extends AbstractRule
{
    /**
     * @var mixed
     */
    private $compareTo;

    /**
     * Initializes the rule.
     *
     * @param mixed $compareTo
     */
    public function __construct($compareTo)
    {
        $this->compareTo = $compareTo;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_scalar($input)) {
            return $this->isStringEquivalent((string) $input);
        }

        return $input == $this->compareTo;
    }

    private function isStringEquivalent(string $input): bool
    {
        if (!is_scalar($this->compareTo)) {
            return false;
        }

        return mb_strtoupper((string) $input) === mb_strtoupper((string) $this->compareTo);
    }
}
validation/library/Rules/ArrayType.php000064400000001425147361033760014101 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_array;

/**
 * Validates whether the type of an input is array.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author João Torquato <joao.otl@gmail.com>
 */
final class ArrayType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_array($input);
    }
}
validation/library/Rules/Graph.php000064400000001537147361033760013226 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_graph;

/**
 * Validates if all characters in the input are printable and actually creates visible output (no white space).
 *
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Graph extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_graph($input);
    }
}
validation/library/Rules/StringType.php000064400000001267147361033760014275 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;

/**
 * Validates whether the type of an input is string or not.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StringType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_string($input);
    }
}
validation/library/Rules/BoolType.php000064400000001237147361033760013717 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_bool;

/**
 * Validates whether the type of the input is boolean.
 *
 * @author Devin Torres <devin@devintorres.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class BoolType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_bool($input);
    }
}
validation/library/Rules/NoWhitespace.php000064400000002024147361033760014546 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_null;
use function is_scalar;
use function preg_match;

/**
 * Validates whether a string contains no whitespace (spaces, tabs and line breaks).
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Augusto Pascutti <augusto@phpsp.org.br>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NoWhitespace extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_null($input)) {
            return true;
        }

        if (is_scalar($input) === false) {
            return false;
        }

        return !preg_match('#\s#', (string) $input);
    }
}
validation/library/Rules/FloatType.php000064400000001237147361033760014071 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_float;

/**
 * Validates whether the type of the input is float.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Reginaldo Junior <76regi@gmail.com>
 */
final class FloatType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_float($input);
    }
}
validation/library/Rules/Extension.php000064400000002214147361033760014132 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use SplFileInfo;

use function is_string;
use function pathinfo;

use const PATHINFO_EXTENSION;

/**
 * Validate file extensions.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Extension extends AbstractRule
{
    /**
     * @var string
     */
    private $extension;

    /**
     * Initializes the rule.
     */
    public function __construct(string $extension)
    {
        $this->extension = $extension;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $this->extension === $input->getExtension();
        }

        if (!is_string($input)) {
            return false;
        }

        return $this->extension === pathinfo($input, PATHINFO_EXTENSION);
    }
}
validation/library/Rules/Iban.php000064400000006527147361033760013042 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function bcmod;
use function is_string;
use function ord;
use function preg_match;
use function preg_replace_callback;
use function str_replace;
use function strlen;
use function substr;

/**
 * Validates whether the input is a valid IBAN (International Bank Account Number) or not.
 *
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class Iban extends AbstractRule
{
    private const COUNTRIES_LENGTHS = [
        'AL' => 28,
        'AD' => 24,
        'AT' => 20,
        'AZ' => 28,
        'BH' => 22,
        'BE' => 16,
        'BA' => 20,
        'BR' => 29,
        'BG' => 22,
        'CR' => 21,
        'HR' => 21,
        'CY' => 28,
        'CZ' => 24,
        'DK' => 18,
        'DO' => 28,
        'EE' => 20,
        'FO' => 18,
        'FI' => 18,
        'FR' => 27,
        'GE' => 22,
        'DE' => 22,
        'GI' => 23,
        'GR' => 27,
        'GL' => 18,
        'GT' => 28,
        'HU' => 28,
        'IS' => 26,
        'IE' => 22,
        'IL' => 23,
        'IT' => 27,
        'JO' => 30,
        'KZ' => 20,
        'KW' => 30,
        'LV' => 21,
        'LB' => 28,
        'LI' => 21,
        'LT' => 20,
        'LU' => 20,
        'MK' => 19,
        'MT' => 31,
        'MR' => 27,
        'MU' => 30,
        'MD' => 24,
        'MC' => 27,
        'ME' => 22,
        'NL' => 18,
        'NO' => 15,
        'PK' => 24,
        'PL' => 28,
        'PS' => 29,
        'PT' => 25,
        'QA' => 29,
        'XK' => 20,
        'RO' => 24,
        'LC' => 32,
        'SM' => 27,
        'ST' => 25,
        'SA' => 24,
        'RS' => 22,
        'SC' => 31,
        'SK' => 24,
        'SI' => 19,
        'ES' => 24,
        'SE' => 24,
        'CH' => 21,
        'TL' => 23,
        'TN' => 24,
        'TR' => 26,
        'UA' => 29,
        'AE' => 23,
        'GB' => 22,
        'VG' => 24,
    ];

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        $iban = str_replace(' ', '', $input);
        if (!preg_match('/[A-Z0-9]{15,34}/', $iban)) {
            return false;
        }

        $countryCode = substr($iban, 0, 2);
        if (!$this->hasValidCountryLength($iban, $countryCode)) {
            return false;
        }

        $checkDigits = substr($iban, 2, 2);
        $bban = substr($iban, 4);
        $rearranged = $bban . $countryCode . $checkDigits;

        return bcmod($this->convertToInteger($rearranged), '97') === '1';
    }

    private function hasValidCountryLength(string $iban, string $countryCode): bool
    {
        if (!isset(self::COUNTRIES_LENGTHS[$countryCode])) {
            return false;
        }

        return strlen($iban) === self::COUNTRIES_LENGTHS[$countryCode];
    }

    private function convertToInteger(string $reArrangedIban): string
    {
        return (string) preg_replace_callback(
            '/[A-Z]/',
            static function (array $match): int {
                return ord($match[0]) - 55;
            },
            $reArrangedIban
        );
    }
}
validation/library/Rules/IntVal.php000064400000001633147361033760013357 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_digit;
use function is_int;

/**
 * Validates if the input is an integer.
 *
 * @author Adam Benson <adam.benson@bigcommerce.com>
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Andrei Drulchenko <andrdru@gmail.com>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IntVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_int($input)) {
            return true;
        }

        return ctype_digit($input);
    }
}
validation/library/Rules/Nullable.php000064400000002044147361033760013715 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates the given input with a defined rule when input is not NULL.
 *
 * @author Jens Segers <segers.jens@gmail.com>
 */
final class Nullable extends AbstractWrapper
{
    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if ($input === null) {
            return;
        }

        parent::assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        if ($input === null) {
            return;
        }

        parent::check($input);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input === null) {
            return true;
        }

        return parent::validate($input);
    }
}
validation/library/Rules/AlwaysInvalid.php000064400000001266147361033760014733 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates any input as invalid.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class AlwaysInvalid extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return false;
    }
}
validation/library/Rules/IntType.php000064400000001154147361033760013554 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_int;

/**
 * Validates whether the type of the input is integer.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IntType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_int($input);
    }
}
validation/library/Rules/Version.php000064400000001541147361033760013605 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function preg_match;

/**
 * Validates version numbers using Semantic Versioning.
 *
 * @see http://semver.org/
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Version extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return preg_match('/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/', $input) > 0;
    }
}
validation/library/Rules/Even.php000064400000001535147361033760013060 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;

use const FILTER_VALIDATE_INT;

/**
 * Validates whether the input is an even number or not.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Even extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (filter_var($input, FILTER_VALIDATE_INT) === false) {
            return false;
        }

        return (int) $input % 2 === 0;
    }
}
validation/library/Rules/Cnpj.php000064400000004002147361033760013045 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_map;
use function array_sum;
use function count;
use function is_scalar;
use function preg_replace;
use function str_split;

/**
 * Validates if the input is a Brazilian National Registry of Legal Entities (CNPJ) number.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jayson Reis <santosdosreis@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author Renato Moura <renato@naturalweb.com.br>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Cnpj extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        // Code ported from jsfromhell.com
        $bases = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
        $digits = $this->getDigits((string) $input);

        if (array_sum($digits) < 1) {
            return false;
        }

        if (count($digits) !== 14) {
            return false;
        }

        $n = 0;
        for ($i = 0; $i < 12; ++$i) {
            $n += $digits[$i] * $bases[$i + 1];
        }

        if ($digits[12] != (($n %= 11) < 2 ? 0 : 11 - $n)) {
            return false;
        }

        $n = 0;
        for ($i = 0; $i <= 12; ++$i) {
            $n += $digits[$i] * $bases[$i];
        }

        $check = ($n %= 11) < 2 ? 0 : 11 - $n;

        return $digits[13] == $check;
    }

    /**
     * @return int[]
     */
    private function getDigits(string $input): array
    {
        return array_map(
            'intval',
            str_split(
                (string) preg_replace('/\D/', '', $input)
            )
        );
    }
}
validation/library/Rules/Phone.php000064400000002507147361033760013234 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function preg_match;
use function sprintf;

/**
 * Validates whether the input is a valid phone number.
 *
 * Validates a valid 7, 10, 11 digit phone number (North America, Europe and
 * most Asian and Middle East countries), supporting country and area codes (in
 * dot,space or dashed notations)
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Graham Campbell <graham@mineuk.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Phone extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return preg_match($this->getPregFormat(), (string) $input) > 0;
    }

    private function getPregFormat(): string
    {
        return sprintf(
            '/^\+?(%1$s)? ?(?(?=\()(\(%2$s\) ?%3$s)|([. -]?(%2$s[. -]*)?%3$s))$/',
            '\d{0,3}',
            '\d{1,3}',
            '((\d{3,5})[. -]?(\d{4})|(\d{2}[. -]?){4})'
        );
    }
}
validation/library/Rules/Negative.php000064400000001441147361033760013721 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_numeric;

/**
 * Validates whether the input is a negative number.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 */
final class Negative extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        return $input < 0;
    }
}
validation/library/Rules/KeyValue.php000064400000006757147361033760013723 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Factory;
use Respect\Validation\Validatable;

use function array_keys;
use function in_array;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class KeyValue extends AbstractRule
{
    /**
     * @var int|string
     */
    private $comparedKey;

    /**
     * @var string
     */
    private $ruleName;

    /**
     * @var int|string
     */
    private $baseKey;

    /**
     * @param int|string $comparedKey
     * @param int|string $baseKey
     */
    public function __construct($comparedKey, string $ruleName, $baseKey)
    {
        $this->comparedKey = $comparedKey;
        $this->ruleName = $ruleName;
        $this->baseKey = $baseKey;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $rule = $this->getRule($input);

        try {
            $rule->assert($input[$this->comparedKey]);
        } catch (ValidationException $exception) {
            throw $this->overwriteExceptionParams($exception);
        }
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $rule = $this->getRule($input);

        try {
            $rule->check($input[$this->comparedKey]);
        } catch (ValidationException $exception) {
            throw $this->overwriteExceptionParams($exception);
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        try {
            $rule = $this->getRule($input);
        } catch (ValidationException $e) {
            return false;
        }

        return $rule->validate($input[$this->comparedKey]);
    }

    /**
     * {@inheritDoc}
     */
    public function reportError($input, array $extraParams = []): ValidationException
    {
        try {
            return $this->overwriteExceptionParams($this->getRule($input)->reportError($input));
        } catch (ValidationException $exception) {
            return $this->overwriteExceptionParams($exception);
        }
    }

    /**
     * @param mixed $input
     */
    private function getRule($input): Validatable
    {
        if (!isset($input[$this->comparedKey])) {
            throw parent::reportError($this->comparedKey);
        }

        if (!isset($input[$this->baseKey])) {
            throw parent::reportError($this->baseKey);
        }

        try {
            $rule = Factory::getDefaultInstance()->rule($this->ruleName, [$input[$this->baseKey]]);
            $rule->setName((string) $this->comparedKey);
        } catch (ComponentException $exception) {
            throw parent::reportError($input, ['component' => true]);
        }

        return $rule;
    }

    private function overwriteExceptionParams(ValidationException $exception): ValidationException
    {
        $params = [];
        foreach (array_keys($exception->getParams()) as $key) {
            if (in_array($key, ['template', 'translator'])) {
                continue;
            }

            $params[$key] = $this->baseKey;
        }
        $params['name'] = $this->comparedKey;

        $exception->updateParams($params);

        return $exception;
    }
}
validation/library/Rules/GreaterThan.php000064400000001147147361033760014366 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates whether the input is less than a value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class GreaterThan extends AbstractComparison
{
    /**
     * {@inheritDoc}
     */
    protected function compare($left, $right): bool
    {
        return $left > $right;
    }
}
validation/library/Rules/Digit.php000064400000001373147361033760013223 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_digit;

/**
 * Validates whether the input contains only digits.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Digit extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_digit($input);
    }
}
validation/library/Rules/ResourceType.php000064400000001162147361033760014610 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_resource;

/**
 * Validates whether the input is a resource.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ResourceType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_resource($input);
    }
}
validation/library/Rules/ScalarVal.php000064400000001166147361033760014033 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;

/**
 * Validates whether the input is a scalar value or not.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ScalarVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_scalar($input);
    }
}
validation/library/Rules/Call.php000064400000004772147361033760013044 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;
use Throwable;

use function call_user_func;
use function restore_error_handler;
use function set_error_handler;

/**
 * Validates the return of a callable for a given input.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Call extends AbstractRule
{
    /**
     * @var callable
     */
    private $callable;

    /**
     * @var Validatable
     */
    private $rule;

    /**
     * Initializes the rule with the callable to be executed after the input is passed.
     */
    public function __construct(callable $callable, Validatable $rule)
    {
        $this->callable = $callable;
        $this->rule = $rule;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $this->setErrorHandler($input);

        try {
            $this->rule->assert(call_user_func($this->callable, $input));
        } catch (ValidationException $exception) {
            throw $exception;
        } catch (Throwable $throwable) {
            throw $this->reportError($input);
        } finally {
            restore_error_handler();
        }
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $this->setErrorHandler($input);

        try {
            $this->rule->check(call_user_func($this->callable, $input));
        } catch (ValidationException $exception) {
            throw $exception;
        } catch (Throwable $throwable) {
            throw $this->reportError($input);
        } finally {
            restore_error_handler();
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        try {
            $this->check($input);
        } catch (ValidationException $exception) {
            return false;
        }

        return true;
    }

    /**
     * @param mixed $input
     */
    private function setErrorHandler($input): void
    {
        set_error_handler(function () use ($input): void {
            throw $this->reportError($input);
        });
    }
}
validation/library/Rules/PerfectSquare.php000064400000001564147361033760014736 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function floor;
use function is_numeric;
use function sqrt;

/**
 * Validates whether the input is a perfect square.
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class PerfectSquare extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_numeric($input) && floor(sqrt((float) $input)) == sqrt((float) $input);
    }
}
validation/library/Rules/Fibonacci.php000064400000002057147361033760014040 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_numeric;

/**
 * Validates whether the input follows the Fibonacci integer sequence.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
 */
final class Fibonacci extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        $sequence = [0, 1];
        $position = 1;
        while ($input > $sequence[$position]) {
            ++$position;
            $sequence[$position] = $sequence[$position - 1] + $sequence[$position - 2];
        }

        return $sequence[$position] === (int) $input;
    }
}
validation/library/Rules/Min.php000064400000001254147361033760012704 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates whether the input is greater than or equal to a value.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Min extends AbstractComparison
{
    /**
     * {@inheritDoc}
     */
    protected function compare($left, $right): bool
    {
        return $left >= $right;
    }
}
validation/library/Rules/Roman.php000064400000001321147361033760013230 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates if the input is a Roman numeral.
 *
 * @author Alexander Wühr <wuehr@sc-networks.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class Roman extends AbstractEnvelope
{
    public function __construct()
    {
        parent::__construct(new Regex('/^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/'));
    }
}
validation/library/Rules/ArrayVal.php000064400000001703147361033760013701 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use ArrayAccess;
use SimpleXMLElement;

use function is_array;

/**
 * Validates if the input is an array or if the input can be used as an array.
 *
 * Instance of `ArrayAccess` or `SimpleXMLElement` are also considered as valid.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ArrayVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_array($input) || $input instanceof ArrayAccess || $input instanceof SimpleXMLElement;
    }
}
validation/library/Rules/Unique.php000064400000001567147361033760013436 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_unique;
use function is_array;

use const SORT_REGULAR;

/**
 * Validates whether the input array contains only unique values.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Krzysztof Śmiałek <admin@avensome.net>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Unique extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_array($input)) {
            return false;
        }

        return $input == array_unique($input, SORT_REGULAR);
    }
}
validation/library/Rules/When.php000064400000003700147361033760013060 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\AlwaysInvalidException;
use Respect\Validation\Validatable;

/**
 * A ternary validator that accepts three parameters.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 */
final class When extends AbstractRule
{
    /**
     * @var Validatable
     */
    private $when;

    /**
     * @var Validatable
     */
    private $then;

    /**
     * @var Validatable
     */
    private $else;

    public function __construct(Validatable $when, Validatable $then, ?Validatable $else = null)
    {
        $this->when = $when;
        $this->then = $then;
        if ($else === null) {
            $else = new AlwaysInvalid();
            $else->setTemplate(AlwaysInvalidException::SIMPLE);
        }

        $this->else = $else;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->when->validate($input)) {
            return $this->then->validate($input);
        }

        return $this->else->validate($input);
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if ($this->when->validate($input)) {
            $this->then->assert($input);

            return;
        }

        $this->else->assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        if ($this->when->validate($input)) {
            $this->then->check($input);

            return;
        }

        $this->else->check($input);
    }
}
validation/library/Rules/SubdivisionCode.php000064400000002314147361033760015250 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\Subdivisions;

use function array_keys;

/**
 * Validates country subdivision codes according to ISO 3166-2.
 *
 * @see http://en.wikipedia.org/wiki/ISO_3166-2
 * @see http://www.geonames.org/countries/
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class SubdivisionCode extends AbstractSearcher
{
    /**
     * @var string
     */
    private $countryName;

    /**
     * @var string[]
     */
    private $subdivisions;

    public function __construct(string $countryCode)
    {
        $subdivisions = new Subdivisions($countryCode);

        $this->countryName = $subdivisions->getCountry();
        $this->subdivisions = array_keys($subdivisions->getSubdivisions());
    }

    /**
     * {@inheritDoc}
     */
    protected function getDataSource(): array
    {
        return $this->subdivisions;
    }
}
validation/library/Rules/AbstractEnvelope.php000064400000002666147361033760015432 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;

/**
 * Abstract class that creates an envelope around another rule.
 *
 * This class is usefull when you want to create rules that use other rules, but
 * having an custom message.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
abstract class AbstractEnvelope extends AbstractRule
{
    /**
     * @var Validatable
     */
    private $validatable;

    /**
     * @var mixed[]
     */
    private $parameters;

    /**
     * Initializes the rule.
     *
     * @param mixed[] $parameters
     */
    public function __construct(Validatable $validatable, array $parameters = [])
    {
        $this->validatable = $validatable;
        $this->parameters = $parameters;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $this->validatable->validate($input);
    }

    /**
     * {@inheritDoc}
     */
    public function reportError($input, array $extraParameters = []): ValidationException
    {
        return parent::reportError($input, $extraParameters + $this->parameters);
    }
}
validation/library/Rules/Control.php000064400000001507147361033760013602 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_cntrl;

/**
 * Validates if all of the characters in the provided string, are control characters.
 *
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Control extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_cntrl($input);
    }
}
validation/library/Rules/Base.php000064400000003051147361033760013030 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function is_null;
use function mb_strlen;
use function mb_substr;
use function preg_match;
use function sprintf;

/**
 * Validate numbers in any base, even with non regular bases.
 *
 * @author Carlos André Ferrari <caferrari@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Base extends AbstractRule
{
    /**
     * @var string
     */
    private $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

    /**
     * @var int
     */
    private $base;

    /**
     * Initializes the Base rule.
     */
    public function __construct(int $base, ?string $chars = null)
    {
        if (!is_null($chars)) {
            $this->chars = $chars;
        }

        $max = mb_strlen($this->chars);
        if ($base > $max) {
            throw new ComponentException(sprintf('a base between 1 and %s is required', $max));
        }
        $this->base = $base;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $valid = mb_substr($this->chars, 0, $this->base);

        return (bool) preg_match('@^[' . $valid . ']+$@', (string) $input);
    }
}
validation/library/Rules/LanguageCode.php000064400000047014147361033760014503 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_column;
use function array_filter;
use function array_search;
use function sprintf;

/**
 * Validates whether the input is language code based on ISO 639.
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LanguageCode extends AbstractEnvelope
{
    public const ALPHA2 = 'alpha-2';
    public const ALPHA3 = 'alpha-3';

    public const AVAILABLE_SETS = [self::ALPHA2, self::ALPHA3];

    /**
     * @see http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
     */
    public const LANGUAGE_CODES = [
        // phpcs:disable Squiz.PHP.CommentedOutCode.Found
        ['aa', 'aar'], // Afar
        ['ab', 'abk'], // Abkhazian
        ['', 'ace'], // Achinese
        ['', 'ach'], // Acoli
        ['', 'ada'], // Adangme
        ['', 'ady'], // Adyghe; Adygei
        ['', 'afa'], // Afro-Asiatic languages
        ['', 'afh'], // Afrihili
        ['af', 'afr'], // Afrikaans
        ['', 'ain'], // Ainu
        ['ak', 'aka'], // Akan
        ['', 'akk'], // Akkadian
        ['sq', 'alb'], // Albanian
        ['', 'ale'], // Aleut
        ['', 'alg'], // Algonquian languages
        ['', 'alt'], // Southern Altai
        ['am', 'amh'], // Amharic
        ['', 'ang'], // English, Old (ca.450-1100)
        ['', 'anp'], // Angika
        ['', 'apa'], // Apache languages
        ['ar', 'ara'], // Arabic
        ['', 'arc'], // Official Aramaic (700-300 BCE); Imperial Aramaic (700-300 BCE)
        ['an', 'arg'], // Aragonese
        ['hy', 'arm'], // Armenian
        ['', 'arn'], // Mapudungun; Mapuche
        ['', 'arp'], // Arapaho
        ['', 'art'], // Artificial languages
        ['', 'arw'], // Arawak
        ['as', 'asm'], // Assamese
        ['', 'ast'], // Asturian; Bable; Leonese; Asturleonese
        ['', 'ath'], // Athapascan languages
        ['', 'aus'], // Australian languages
        ['av', 'ava'], // Avaric
        ['ae', 'ave'], // Avestan
        ['', 'awa'], // Awadhi
        ['ay', 'aym'], // Aymara
        ['az', 'aze'], // Azerbaijani
        ['', 'bad'], // Banda languages
        ['', 'bai'], // Bamileke languages
        ['ba', 'bak'], // Bashkir
        ['', 'bal'], // Baluchi
        ['bm', 'bam'], // Bambara
        ['', 'ban'], // Balinese
        ['eu', 'baq'], // Basque
        ['', 'bas'], // Basa
        ['', 'bat'], // Baltic languages
        ['', 'bej'], // Beja; Bedawiyet
        ['be', 'bel'], // Belarusian
        ['', 'bem'], // Bemba
        ['bn', 'ben'], // Bengali
        ['', 'ber'], // Berber languages
        ['', 'bho'], // Bhojpuri
        ['bh', 'bih'], // Bihari languages
        ['', 'bik'], // Bikol
        ['', 'bin'], // Bini; Edo
        ['bi', 'bis'], // Bislama
        ['', 'bla'], // Siksika
        ['', 'bnt'], // Bantu languages
        ['bs', 'bos'], // Bosnian
        ['', 'bra'], // Braj
        ['br', 'bre'], // Breton
        ['', 'btk'], // Batak languages
        ['', 'bua'], // Buriat
        ['', 'bug'], // Buginese
        ['bg', 'bul'], // Bulgarian
        ['my', 'bur'], // Burmese
        ['', 'byn'], // Blin; Bilin
        ['', 'cad'], // Caddo
        ['', 'cai'], // Central American Indian languages
        ['', 'car'], // Galibi Carib
        ['ca', 'cat'], // Catalan; Valencian
        ['', 'cau'], // Caucasian languages
        ['', 'ceb'], // Cebuano
        ['', 'cel'], // Celtic languages
        ['ch', 'cha'], // Chamorro
        ['', 'chb'], // Chibcha
        ['ce', 'che'], // Chechen
        ['', 'chg'], // Chagatai
        ['zh', 'chi'], // Chinese
        ['', 'chk'], // Chuukese
        ['', 'chm'], // Mari
        ['', 'chn'], // Chinook jargon
        ['', 'cho'], // Choctaw
        ['', 'chp'], // Chipewyan; Dene Suline
        ['', 'chr'], // Cherokee
        ['cu', 'chu'], // Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic
        ['cv', 'chv'], // Chuvash
        ['', 'chy'], // Cheyenne
        ['', 'cmc'], // Chamic languages
        ['', 'cnr'], // Montenegrin
        ['', 'cop'], // Coptic
        ['kw', 'cor'], // Cornish
        ['co', 'cos'], // Corsican
        ['', 'cpe'], // Creoles and pidgins, English based
        ['', 'cpf'], // Creoles and pidgins, French-based
        ['', 'cpp'], // Creoles and pidgins, Portuguese-based
        ['cr', 'cre'], // Cree
        ['', 'crh'], // Crimean Tatar; Crimean Turkish
        ['', 'crp'], // Creoles and pidgins
        ['', 'csb'], // Kashubian
        ['', 'cus'], // Cushitic languages
        ['cs', 'cze'], // Czech
        ['', 'dak'], // Dakota
        ['da', 'dan'], // Danish
        ['', 'dar'], // Dargwa
        ['', 'day'], // Land Dayak languages
        ['', 'del'], // Delaware
        ['', 'den'], // Slave (Athapascan)
        ['', 'dgr'], // Dogrib
        ['', 'din'], // Dinka
        ['dv', 'div'], // Divehi; Dhivehi; Maldivian
        ['', 'doi'], // Dogri
        ['', 'dra'], // Dravidian languages
        ['', 'dsb'], // Lower Sorbian
        ['', 'dua'], // Duala
        ['', 'dum'], // Dutch, Middle (ca.1050-1350)
        ['nl', 'dut'], // Dutch; Flemish
        ['', 'dyu'], // Dyula
        ['dz', 'dzo'], // Dzongkha
        ['', 'efi'], // Efik
        ['', 'egy'], // Egyptian (Ancient)
        ['', 'eka'], // Ekajuk
        ['', 'elx'], // Elamite
        ['en', 'eng'], // English
        ['', 'enm'], // English, Middle (1100-1500)
        ['eo', 'epo'], // Esperanto
        ['et', 'est'], // Estonian
        ['ee', 'ewe'], // Ewe
        ['', 'ewo'], // Ewondo
        ['', 'fan'], // Fang
        ['fo', 'fao'], // Faroese
        ['', 'fat'], // Fanti
        ['fj', 'fij'], // Fijian
        ['', 'fil'], // Filipino; Pilipino
        ['fi', 'fin'], // Finnish
        ['', 'fiu'], // Finno-Ugrian languages
        ['', 'fon'], // Fon
        ['fr', 'fre'], // French
        ['', 'frm'], // French, Middle (ca.1400-1600)
        ['', 'fro'], // French, Old (842-ca.1400)
        ['', 'frr'], // Northern Frisian
        ['', 'frs'], // Eastern Frisian
        ['fy', 'fry'], // Western Frisian
        ['ff', 'ful'], // Fulah
        ['', 'fur'], // Friulian
        ['', 'gaa'], // Ga
        ['', 'gay'], // Gayo
        ['', 'gba'], // Gbaya
        ['', 'gem'], // Germanic languages
        ['ka', 'geo'], // Georgian
        ['de', 'ger'], // German
        ['', 'gez'], // Geez
        ['', 'gil'], // Gilbertese
        ['gd', 'gla'], // Gaelic; Scottish Gaelic
        ['ga', 'gle'], // Irish
        ['gl', 'glg'], // Galician
        ['gv', 'glv'], // Manx
        ['', 'gmh'], // German, Middle High (ca.1050-1500)
        ['', 'goh'], // German, Old High (ca.750-1050)
        ['', 'gon'], // Gondi
        ['', 'gor'], // Gorontalo
        ['', 'got'], // Gothic
        ['', 'grb'], // Grebo
        ['', 'grc'], // Greek, Ancient (to 1453)
        ['el', 'gre'], // Greek, Modern (1453-)
        ['gn', 'grn'], // Guarani
        ['', 'gsw'], // Swiss German; Alemannic; Alsatian
        ['gu', 'guj'], // Gujarati
        ['', 'gwi'], // Gwich'in
        ['', 'hai'], // Haida
        ['ht', 'hat'], // Haitian; Haitian Creole
        ['ha', 'hau'], // Hausa
        ['', 'haw'], // Hawaiian
        ['he', 'heb'], // Hebrew
        ['hz', 'her'], // Herero
        ['', 'hil'], // Hiligaynon
        ['', 'him'], // Himachali languages; Western Pahari languages
        ['hi', 'hin'], // Hindi
        ['', 'hit'], // Hittite
        ['', 'hmn'], // Hmong; Mong
        ['ho', 'hmo'], // Hiri Motu
        ['hr', 'hrv'], // Croatian
        ['', 'hsb'], // Upper Sorbian
        ['hu', 'hun'], // Hungarian
        ['', 'hup'], // Hupa
        ['', 'iba'], // Iban
        ['ig', 'ibo'], // Igbo
        ['is', 'ice'], // Icelandic
        ['io', 'ido'], // Ido
        ['ii', 'iii'], // Sichuan Yi; Nuosu
        ['', 'ijo'], // Ijo languages
        ['iu', 'iku'], // Inuktitut
        ['ie', 'ile'], // Interlingue; Occidental
        ['', 'ilo'], // Iloko
        ['ia', 'ina'], // Interlingua (International Auxiliary Language Association)
        ['', 'inc'], // Indic languages
        ['id', 'ind'], // Indonesian
        ['', 'ine'], // Indo-European languages
        ['', 'inh'], // Ingush
        ['ik', 'ipk'], // Inupiaq
        ['', 'ira'], // Iranian languages
        ['', 'iro'], // Iroquoian languages
        ['it', 'ita'], // Italian
        ['jv', 'jav'], // Javanese
        ['', 'jbo'], // Lojban
        ['ja', 'jpn'], // Japanese
        ['', 'jpr'], // Judeo-Persian
        ['', 'jrb'], // Judeo-Arabic
        ['', 'kaa'], // Kara-Kalpak
        ['', 'kab'], // Kabyle
        ['', 'kac'], // Kachin; Jingpho
        ['kl', 'kal'], // Kalaallisut; Greenlandic
        ['', 'kam'], // Kamba
        ['kn', 'kan'], // Kannada
        ['', 'kar'], // Karen languages
        ['ks', 'kas'], // Kashmiri
        ['kr', 'kau'], // Kanuri
        ['', 'kaw'], // Kawi
        ['kk', 'kaz'], // Kazakh
        ['', 'kbd'], // Kabardian
        ['', 'kha'], // Khasi
        ['', 'khi'], // Khoisan languages
        ['km', 'khm'], // Central Khmer
        ['', 'kho'], // Khotanese; Sakan
        ['ki', 'kik'], // Kikuyu; Gikuyu
        ['rw', 'kin'], // Kinyarwanda
        ['ky', 'kir'], // Kirghiz; Kyrgyz
        ['', 'kmb'], // Kimbundu
        ['', 'kok'], // Konkani
        ['kv', 'kom'], // Komi
        ['kg', 'kon'], // Kongo
        ['ko', 'kor'], // Korean
        ['', 'kos'], // Kosraean
        ['', 'kpe'], // Kpelle
        ['', 'krc'], // Karachay-Balkar
        ['', 'krl'], // Karelian
        ['', 'kro'], // Kru languages
        ['', 'kru'], // Kurukh
        ['kj', 'kua'], // Kuanyama; Kwanyama
        ['', 'kum'], // Kumyk
        ['ku', 'kur'], // Kurdish
        ['', 'kut'], // Kutenai
        ['', 'lad'], // Ladino
        ['', 'lah'], // Lahnda
        ['', 'lam'], // Lamba
        ['lo', 'lao'], // Lao
        ['la', 'lat'], // Latin
        ['lv', 'lav'], // Latvian
        ['', 'lez'], // Lezghian
        ['li', 'lim'], // Limburgan; Limburger; Limburgish
        ['ln', 'lin'], // Lingala
        ['lt', 'lit'], // Lithuanian
        ['', 'lol'], // Mongo
        ['', 'loz'], // Lozi
        ['lb', 'ltz'], // Luxembourgish; Letzeburgesch
        ['', 'lua'], // Luba-Lulua
        ['lu', 'lub'], // Luba-Katanga
        ['lg', 'lug'], // Ganda
        ['', 'lui'], // Luiseno
        ['', 'lun'], // Lunda
        ['', 'luo'], // Luo (Kenya and Tanzania)
        ['', 'lus'], // Lushai
        ['mk', 'mac'], // Macedonian
        ['', 'mad'], // Madurese
        ['', 'mag'], // Magahi
        ['mh', 'mah'], // Marshallese
        ['', 'mai'], // Maithili
        ['', 'mak'], // Makasar
        ['ml', 'mal'], // Malayalam
        ['', 'man'], // Mandingo
        ['mi', 'mao'], // Maori
        ['', 'map'], // Austronesian languages
        ['mr', 'mar'], // Marathi
        ['', 'mas'], // Masai
        ['ms', 'may'], // Malay
        ['', 'mdf'], // Moksha
        ['', 'mdr'], // Mandar
        ['', 'men'], // Mende
        ['', 'mga'], // Irish, Middle (900-1200)
        ['', 'mic'], // Mi'kmaq; Micmac
        ['', 'min'], // Minangkabau
        ['', 'mis'], // Uncoded languages
        ['', 'mkh'], // Mon-Khmer languages
        ['mg', 'mlg'], // Malagasy
        ['mt', 'mlt'], // Maltese
        ['', 'mnc'], // Manchu
        ['', 'mni'], // Manipuri
        ['', 'mno'], // Manobo languages
        ['', 'moh'], // Mohawk
        ['mn', 'mon'], // Mongolian
        ['', 'mos'], // Mossi
        ['', 'mul'], // Multiple languages
        ['', 'mun'], // Munda languages
        ['', 'mus'], // Creek
        ['', 'mwl'], // Mirandese
        ['', 'mwr'], // Marwari
        ['', 'myn'], // Mayan languages
        ['', 'myv'], // Erzya
        ['', 'nah'], // Nahuatl languages
        ['', 'nai'], // North American Indian languages
        ['', 'nap'], // Neapolitan
        ['na', 'nau'], // Nauru
        ['nv', 'nav'], // Navajo; Navaho
        ['nr', 'nbl'], // Ndebele, South; South Ndebele
        ['nd', 'nde'], // Ndebele, North; North Ndebele
        ['ng', 'ndo'], // Ndonga
        ['', 'nds'], // Low German; Low Saxon; German, Low; Saxon, Low
        ['ne', 'nep'], // Nepali
        ['', 'new'], // Nepal Bhasa; Newari
        ['', 'nia'], // Nias
        ['', 'nic'], // Niger-Kordofanian languages
        ['', 'niu'], // Niuean
        ['nn', 'nno'], // Norwegian Nynorsk; Nynorsk, Norwegian
        ['nb', 'nob'], // Bokmål, Norwegian; Norwegian Bokmål
        ['', 'nog'], // Nogai
        ['', 'non'], // Norse, Old
        ['no', 'nor'], // Norwegian
        ['', 'nqo'], // N'Ko
        ['', 'nso'], // Pedi; Sepedi; Northern Sotho
        ['', 'nub'], // Nubian languages
        ['', 'nwc'], // Classical Newari; Old Newari; Classical Nepal Bhasa
        ['ny', 'nya'], // Chichewa; Chewa; Nyanja
        ['', 'nym'], // Nyamwezi
        ['', 'nyn'], // Nyankole
        ['', 'nyo'], // Nyoro
        ['', 'nzi'], // Nzima
        ['oc', 'oci'], // Occitan (post 1500)
        ['oj', 'oji'], // Ojibwa
        ['or', 'ori'], // Oriya
        ['om', 'orm'], // Oromo
        ['', 'osa'], // Osage
        ['os', 'oss'], // Ossetian; Ossetic
        ['', 'ota'], // Turkish, Ottoman (1500-1928)
        ['', 'oto'], // Otomian languages
        ['', 'paa'], // Papuan languages
        ['', 'pag'], // Pangasinan
        ['', 'pal'], // Pahlavi
        ['', 'pam'], // Pampanga; Kapampangan
        ['pa', 'pan'], // Panjabi; Punjabi
        ['', 'pap'], // Papiamento
        ['', 'pau'], // Palauan
        ['', 'peo'], // Persian, Old (ca.600-400 B.C.)
        ['fa', 'per'], // Persian
        ['', 'phi'], // Philippine languages
        ['', 'phn'], // Phoenician
        ['pi', 'pli'], // Pali
        ['pl', 'pol'], // Polish
        ['', 'pon'], // Pohnpeian
        ['pt', 'por'], // Portuguese
        ['', 'pra'], // Prakrit languages
        ['', 'pro'], // Provençal, Old (to 1500); Occitan, Old (to 1500)
        ['ps', 'pus'], // Pushto; Pashto
        ['', 'qaaqtz'], // Reserved for local use
        ['qu', 'que'], // Quechua
        ['', 'raj'], // Rajasthani
        ['', 'rap'], // Rapanui
        ['', 'rar'], // Rarotongan; Cook Islands Maori
        ['', 'roa'], // Romance languages
        ['rm', 'roh'], // Romansh
        ['', 'rom'], // Romany
        ['ro', 'rum'], // Romanian; Moldavian; Moldovan
        ['rn', 'run'], // Rundi
        ['', 'rup'], // Aromanian; Arumanian; Macedo-Romanian
        ['ru', 'rus'], // Russian
        ['', 'sad'], // Sandawe
        ['sg', 'sag'], // Sango
        ['', 'sah'], // Yakut
        ['', 'sai'], // South American Indian languages
        ['', 'sal'], // Salishan languages
        ['', 'sam'], // Samaritan Aramaic
        ['sa', 'san'], // Sanskrit
        ['', 'sas'], // Sasak
        ['', 'sat'], // Santali
        ['', 'scn'], // Sicilian
        ['', 'sco'], // Scots
        ['', 'sel'], // Selkup
        ['', 'sem'], // Semitic languages
        ['', 'sga'], // Irish, Old (to 900)
        ['', 'sgn'], // Sign Languages
        ['', 'shn'], // Shan
        ['', 'sid'], // Sidamo
        ['si', 'sin'], // Sinhala; Sinhalese
        ['', 'sio'], // Siouan languages
        ['', 'sit'], // Sino-Tibetan languages
        ['', 'sla'], // Slavic languages
        ['sk', 'slo'], // Slovak
        ['sl', 'slv'], // Slovenian
        ['', 'sma'], // Southern Sami
        ['se', 'sme'], // Northern Sami
        ['', 'smi'], // Sami languages
        ['', 'smj'], // Lule Sami
        ['', 'smn'], // Inari Sami
        ['sm', 'smo'], // Samoan
        ['', 'sms'], // Skolt Sami
        ['sn', 'sna'], // Shona
        ['sd', 'snd'], // Sindhi
        ['', 'snk'], // Soninke
        ['', 'sog'], // Sogdian
        ['so', 'som'], // Somali
        ['', 'son'], // Songhai languages
        ['st', 'sot'], // Sotho, Southern
        ['es', 'spa'], // Spanish; Castilian
        ['sc', 'srd'], // Sardinian
        ['', 'srn'], // Sranan Tongo
        ['sr', 'srp'], // Serbian
        ['', 'srr'], // Serer
        ['', 'ssa'], // Nilo-Saharan languages
        ['ss', 'ssw'], // Swati
        ['', 'suk'], // Sukuma
        ['su', 'sun'], // Sundanese
        ['', 'sus'], // Susu
        ['', 'sux'], // Sumerian
        ['sw', 'swa'], // Swahili
        ['sv', 'swe'], // Swedish
        ['', 'syc'], // Classical Syriac
        ['', 'syr'], // Syriac
        ['ty', 'tah'], // Tahitian
        ['', 'tai'], // Tai languages
        ['ta', 'tam'], // Tamil
        ['tt', 'tat'], // Tatar
        ['te', 'tel'], // Telugu
        ['', 'tem'], // Timne
        ['', 'ter'], // Tereno
        ['', 'tet'], // Tetum
        ['tg', 'tgk'], // Tajik
        ['tl', 'tgl'], // Tagalog
        ['th', 'tha'], // Thai
        ['bo', 'tib'], // Tibetan
        ['', 'tig'], // Tigre
        ['ti', 'tir'], // Tigrinya
        ['', 'tiv'], // Tiv
        ['', 'tkl'], // Tokelau
        ['', 'tlh'], // Klingon; tlhIngan-Hol
        ['', 'tli'], // Tlingit
        ['', 'tmh'], // Tamashek
        ['', 'tog'], // Tonga (Nyasa)
        ['to', 'ton'], // Tonga (Tonga Islands)
        ['', 'tpi'], // Tok Pisin
        ['', 'tsi'], // Tsimshian
        ['tn', 'tsn'], // Tswana
        ['ts', 'tso'], // Tsonga
        ['tk', 'tuk'], // Turkmen
        ['', 'tum'], // Tumbuka
        ['', 'tup'], // Tupi languages
        ['tr', 'tur'], // Turkish
        ['', 'tut'], // Altaic languages
        ['', 'tvl'], // Tuvalu
        ['tw', 'twi'], // Twi
        ['', 'tyv'], // Tuvinian
        ['', 'udm'], // Udmurt
        ['', 'uga'], // Ugaritic
        ['ug', 'uig'], // Uighur; Uyghur
        ['uk', 'ukr'], // Ukrainian
        ['', 'umb'], // Umbundu
        ['', 'und'], // Undetermined
        ['ur', 'urd'], // Urdu
        ['uz', 'uzb'], // Uzbek
        ['', 'vai'], // Vai
        ['ve', 'ven'], // Venda
        ['vi', 'vie'], // Vietnamese
        ['vo', 'vol'], // Volapük
        ['', 'vot'], // Votic
        ['', 'wak'], // Wakashan languages
        ['', 'wal'], // Wolaitta; Wolaytta
        ['', 'war'], // Waray
        ['', 'was'], // Washo
        ['cy', 'wel'], // Welsh
        ['', 'wen'], // Sorbian languages
        ['wa', 'wln'], // Walloon
        ['wo', 'wol'], // Wolof
        ['', 'xal'], // Kalmyk; Oirat
        ['xh', 'xho'], // Xhosa
        ['', 'yao'], // Yao
        ['', 'yap'], // Yapese
        ['yi', 'yid'], // Yiddish
        ['yo', 'yor'], // Yoruba
        ['', 'ypk'], // Yupik languages
        ['', 'zap'], // Zapotec
        ['', 'zbl'], // Blissymbols; Blissymbolics; Bliss
        ['', 'zen'], // Zenaga
        ['', 'zgh'], // Standard Moroccan Tamazight
        ['za', 'zha'], // Zhuang; Chuang
        ['', 'znd'], // Zande languages
        ['zu', 'zul'], // Zulu
        ['', 'zun'], // Zuni
        ['', 'zxx'], // No linguistic content; Not applicable
        // phpcs:enable Squiz.PHP.CommentedOutCode.Found
    ];

    /**
     * Initializes the rule defining the ISO 639 set.
     *
     * @throws ComponentException
     */
    public function __construct(string $set = self::ALPHA2)
    {
        $index = array_search($set, self::AVAILABLE_SETS, true);
        if ($index === false) {
            throw new ComponentException(sprintf('"%s" is not a valid language set for ISO 639', $set));
        }

        parent::__construct(new In($this->getHaystack($index), true), ['set' => $set]);
    }

    /**
     * @return string[]
     */
    private function getHaystack(int $index): array
    {
        return array_filter(array_column(self::LANGUAGE_CODES, $index));
    }
}
validation/library/Rules/No.php000064400000001376147361033760012542 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function nl_langinfo;

use const NOEXPR;

/**
 * Validates if value is considered as "No".
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class No extends AbstractEnvelope
{
    public function __construct(bool $useLocale = false)
    {
        $pattern = '^n(o(t|pe)?|ix|ay)?$';
        if ($useLocale) {
            $pattern = nl_langinfo(NOEXPR);
        }

        parent::__construct(new Regex('/' . $pattern . '/i'));
    }
}
validation/library/Rules/Uploaded.php000064400000002073147361033760013716 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Psr\Http\Message\UploadedFileInterface;
use SplFileInfo;

use function is_scalar;
use function is_uploaded_file;

/**
 * Validates if the given data is a file that was uploaded via HTTP POST.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Uploaded extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $this->validate($input->getPathname());
        }

        if ($input instanceof UploadedFileInterface) {
            return true;
        }

        if (!is_scalar($input)) {
            return false;
        }

        return is_uploaded_file((string) $input);
    }
}
validation/library/Rules/Vowel.php000064400000001325147361033760013254 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function preg_match;

/**
 * Validates whether the input contains only vowels.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Vowel extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return preg_match('/^[aeiouAEIOU]+$/', $input) > 0;
    }
}
validation/library/Rules/Contains.php000064400000003667147361033760013751 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function in_array;
use function is_array;
use function is_scalar;
use function mb_stripos;
use function mb_strpos;

/**
 * Validates if the input contains some value.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Marcelo Araujo <msaraujo@php.net>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Contains extends AbstractRule
{
    /**
     * @var mixed
     */
    private $containsValue;

    /**
     * @var bool
     */
    private $identical;

    /**
     * Initializes the Contains rule.
     *
     * @param mixed $containsValue Value that will be sought
     * @param bool $identical Defines whether the value is identical, default is false
     */
    public function __construct($containsValue, bool $identical = false)
    {
        $this->containsValue = $containsValue;
        $this->identical = $identical;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_array($input)) {
            return in_array($this->containsValue, $input, $this->identical);
        }

        if (!is_scalar($input) || !is_scalar($this->containsValue)) {
            return false;
        }

        return $this->validateString((string) $input, (string) $this->containsValue);
    }

    private function validateString(string $haystack, string $needle): bool
    {
        if ($needle === '') {
            return false;
        }

        if ($this->identical) {
            return mb_strpos($haystack, $needle) !== false;
        }

        return mb_stripos($haystack, $needle) !== false;
    }
}
validation/library/Rules/CurrencyCode.php000064400000016332147361033760014551 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates currency codes in ISO 4217.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Justin Hook <justinhook88@yahoo.co.uk>
 * @author Tim Strijdhorst <tstrijdhorst@users.noreply.github.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CurrencyCode extends AbstractSearcher
{
    /**
     * @see http://www.currency-iso.org/en/home/tables/table-a1.html
     *
     * {@inheritDoc}
     */
    protected function getDataSource(): array
    {
        return [
            'AED', // UAE Dirham
            'AFN', // Afghani
            'ALL', // Lek
            'AMD', // Armenian Dram
            'ANG', // Netherlands Antillean Guilder
            'AOA', // Kwanza
            'ARS', // Argentine Peso
            'AUD', // Australian Dollar
            'AWG', // Aruban Florin
            'AZN', // Azerbaijan Manat
            'BAM', // Convertible Mark
            'BBD', // Barbados Dollar
            'BDT', // Taka
            'BGN', // Bulgarian Lev
            'BHD', // Bahraini Dinar
            'BIF', // Burundi Franc
            'BMD', // Bermudian Dollar
            'BND', // Brunei Dollar
            'BOB', // Boliviano
            'BOV', // Mvdol
            'BRL', // Brazilian Real
            'BSD', // Bahamian Dollar
            'BTN', // Ngultrum
            'BWP', // Pula
            'BYN', // Belarusian Ruble
            'BZD', // Belize Dollar
            'CAD', // Canadian Dollar
            'CDF', // Congolese Franc
            'CHE', // WIR Euro
            'CHF', // Swiss Franc
            'CHW', // WIR Franc
            'CLF', // Unidad de Fomento
            'CLP', // Chilean Peso
            'CNY', // Yuan Renminbi
            'COP', // Colombian Peso
            'COU', // Unidad de Valor Real
            'CRC', // Costa Rican Colon
            'CUC', // Peso Convertible
            'CUP', // Cuban Peso
            'CVE', // Cabo Verde Escudo
            'CZK', // Czech Koruna
            'DJF', // Djibouti Franc
            'DKK', // Danish Krone
            'DOP', // Dominican Peso
            'DZD', // Algerian Dinar
            'EGP', // Egyptian Pound
            'ERN', // Nakfa
            'ETB', // Ethiopian Birr
            'EUR', // Euro
            'FJD', // Fiji Dollar
            'FKP', // Falkland Islands Pound
            'GBP', // Pound Sterling
            'GEL', // Lari
            'GHS', // Ghana Cedi
            'GIP', // Gibraltar Pound
            'GMD', // Dalasi
            'GNF', // Guinean Franc
            'GTQ', // Quetzal
            'GYD', // Guyana Dollar
            'HKD', // Hong Kong Dollar
            'HNL', // Lempira
            'HRK', // Kuna
            'HTG', // Gourde
            'HUF', // Forint
            'IDR', // Rupiah
            'ILS', // New Israeli Sheqel
            'INR', // Indian Rupee
            'IQD', // Iraqi Dinar
            'IRR', // Iranian Rial
            'ISK', // Iceland Krona
            'JMD', // Jamaican Dollar
            'JOD', // Jordanian Dinar
            'JPY', // Yen
            'KES', // Kenyan Shilling
            'KGS', // Som
            'KHR', // Riel
            'KMF', // Comorian Franc
            'KPW', // North Korean Won
            'KRW', // Won
            'KWD', // Kuwaiti Dinar
            'KYD', // Cayman Islands Dollar
            'KZT', // Tenge
            'LAK', // Lao Kip
            'LBP', // Lebanese Pound
            'LKR', // Sri Lanka Rupee
            'LRD', // Liberian Dollar
            'LSL', // Loti
            'LYD', // Libyan Dinar
            'MAD', // Moroccan Dirham
            'MDL', // Moldovan Leu
            'MGA', // Malagasy Ariary
            'MKD', // Denar
            'MMK', // Kyat
            'MNT', // Tugrik
            'MOP', // Pataca
            'MRU', // Ouguiya
            'MUR', // Mauritius Rupee
            'MVR', // Rufiyaa
            'MWK', // Malawi Kwacha
            'MXN', // Mexican Peso
            'MXV', // Mexican Unidad de Inversion (UDI)
            'MYR', // Malaysian Ringgit
            'MZN', // Mozambique Metical
            'NAD', // Namibia Dollar
            'NGN', // Naira
            'NIO', // Cordoba Oro
            'NOK', // Norwegian Krone
            'NPR', // Nepalese Rupee
            'NZD', // New Zealand Dollar
            'OMR', // Rial Omani
            'PAB', // Balboa
            'PEN', // Sol
            'PGK', // Kina
            'PHP', // Philippine Peso
            'PKR', // Pakistan Rupee
            'PLN', // Zloty
            'PYG', // Guarani
            'QAR', // Qatari Rial
            'RON', // Romanian Leu
            'RSD', // Serbian Dinar
            'RUB', // Russian Ruble
            'RWF', // Rwanda Franc
            'SAR', // Saudi Riyal
            'SBD', // Solomon Islands Dollar
            'SCR', // Seychelles Rupee
            'SDG', // Sudanese Pound
            'SEK', // Swedish Krona
            'SGD', // Singapore Dollar
            'SHP', // Saint Helena Pound
            'SLL', // Leone
            'SOS', // Somali Shilling
            'SRD', // Surinam Dollar
            'SSP', // South Sudanese Pound
            'STN', // Dobra
            'SVC', // El Salvador Colon
            'SYP', // Syrian Pound
            'SZL', // Lilangeni
            'THB', // Baht
            'TJS', // Somoni
            'TMT', // Turkmenistan New Manat
            'TND', // Tunisian Dinar
            'TOP', // Pa’anga
            'TRY', // Turkish Lira
            'TTD', // Trinidad and Tobago Dollar
            'TWD', // New Taiwan Dollar
            'TZS', // Tanzanian Shilling
            'UAH', // Hryvnia
            'UGX', // Uganda Shilling
            'USD', // US Dollar
            'USN', // US Dollar (Next day)
            'UYI', // Uruguay Peso en Unidades Indexadas (UI)
            'UYU', // Peso Uruguayo
            'UYW', // Unidad Previsional
            'UZS', // Uzbekistan Sum
            'VES', // Bolívar Soberano
            'VND', // Dong
            'VUV', // Vatu
            'WST', // Tala
            'XAF', // CFA Franc BEAC
            'XAG', // Silver
            'XAU', // Gold
            'XBA', // Bond Markets Unit European Composite Unit (EURCO)
            'XBB', // Bond Markets Unit European Monetary Unit (E.M.U.-6)
            'XBC', // Bond Markets Unit European Unit of Account 9 (E.U.A.-9)
            'XBD', // Bond Markets Unit European Unit of Account 17 (E.U.A.-17)
            'XCD', // East Caribbean Dollar
            'XDR', // SDR (Special Drawing Right)
            'XOF', // CFA Franc BCEAO
            'XPD', // Palladium
            'XPF', // CFP Franc
            'XPT', // Platinum
            'XSU', // Sucre
            'XTS', // Codes specifically reserved for testing purposes
            'XUA', // ADB Unit of Account
            'XXX', // The codes assigned for transactions where no currency is involved
            'YER', // Yemeni Rial
            'ZAR', // Rand
            'ZMW', // Zambian Kwacha
            'ZWL', // Zimbabwe Dollar
        ];
    }
}
validation/library/Rules/Cpf.php000064400000003027147361033760012671 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function mb_strlen;
use function preg_match;
use function preg_replace;

/**
 * Validates whether the input is a CPF (Brazilian Natural Persons Register) number.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jair Henrique <jair.henrique@gmail.com>
 * @author Jayson Reis <santosdosreis@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Cpf extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        // Code ported from jsfromhell.com
        $c = preg_replace('/\D/', '', $input);

        if (mb_strlen($c) != 11 || preg_match('/^' . $c[0] . '{11}$/', $c) || $c === '01234567890') {
            return false;
        }

        $n = 0;
        for ($s = 10, $i = 0; $s >= 2; ++$i, --$s) {
            $n += $c[$i] * $s;
        }

        if ($c[9] != (($n %= 11) < 2 ? 0 : 11 - $n)) {
            return false;
        }

        $n = 0;
        for ($s = 11, $i = 0; $s >= 2; ++$i, --$s) {
            $n += $c[$i] * $s;
        }

        $check = ($n %= 11) < 2 ? 0 : 11 - $n;

        return $c[10] == $check;
    }
}
validation/library/Rules/Charset.php000064400000002524147361033760013553 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_diff;
use function in_array;
use function mb_detect_encoding;
use function mb_list_encodings;

/**
 * Validates if a string is in a specific charset.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Charset extends AbstractRule
{
    /**
     * @var string[]
     */
    private $charset;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException
     */
    public function __construct(string ...$charset)
    {
        $available = mb_list_encodings();
        if (!empty(array_diff($charset, $available))) {
            throw new ComponentException('Invalid charset');
        }

        $this->charset = $charset;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return in_array(mb_detect_encoding($input, $this->charset, true), $this->charset, true);
    }
}
validation/library/Rules/SymbolicLink.php000064400000001501147361033760014553 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use SplFileInfo;

use function is_link;
use function is_string;

/**
 * Validates if the given input is a symbolic link.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Gus Antoniassi <gus.antoniassi@gmail.com>
 */
final class SymbolicLink extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isLink();
        }

        return is_string($input) && is_link($input);
    }
}
validation/library/Rules/PostalCode.php000064400000016100147361033760014212 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function sprintf;

/**
 * Validates whether the input is a valid postal code or not.
 *
 * @see http://download.geonames.org/export/dump/countryInfo.txt
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PostalCode extends AbstractEnvelope
{
    private const DEFAULT_PATTERN = '/^$/';
    private const POSTAL_CODES = [
        // phpcs:disable Generic.Files.LineLength.TooLong
        'AD' => '/^(?:AD)*(\d{3})$/',
        'AL' => '/^(\d{4})$/',
        'AM' => '/^(\d{4})$/',
        'AR' => '/^[A-Z]?\d{4}[A-Z]{0,3}$/',
        'AS' => '/96799/',
        'AT' => '/^(\d{4})$/',
        'AU' => '/^(\d{4})$/',
        'AX' => '/^(?:FI)*(\d{5})$/',
        'AZ' => '/^(?:AZ)*(\d{4})$/',
        'BA' => '/^(\d{5})$/',
        'BB' => '/^(?:BB)*(\d{5})$/',
        'BD' => '/^(\d{4})$/',
        'BE' => '/^(\d{4})$/',
        'BG' => '/^(\d{4})$/',
        'BH' => '/^(\d{3}\d?)$/',
        'BL' => '/^(\d{5})$/',
        'BM' => '/^([A-Z]{2}\d{2})$/',
        'BN' => '/^([A-Z]{2}\d{4})$/',
        'BR' => '/^\d{5}-?\d{3}$/',
        'BY' => '/^(\d{6})$/',
        'CA' => '/^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]) ?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$/',
        'CH' => '/^(\d{4})$/',
        'CL' => '/^(\d{7})$/',
        'CN' => '/^(\d{6})$/',
        'CO' => '/^(\d{6})$/',
        'CR' => '/^(\d{5})$/',
        'CS' => '/^(\d{5})$/',
        'CU' => '/^(?:CP)*(\d{5})$/',
        'CV' => '/^(\d{4})$/',
        'CX' => '/^(\d{4})$/',
        'CY' => '/^(\d{4})$/',
        'CZ' => '/^\d{3}\s?\d{2}$/',
        'DE' => '/^(\d{5})$/',
        'DK' => '/^(\d{4})$/',
        'DO' => '/^(\d{5})$/',
        'DZ' => '/^(\d{5})$/',
        'EC' => '/^(\d{6})$/',
        'EE' => '/^(\d{5})$/',
        'EG' => '/^(\d{5})$/',
        'ES' => '/^(\d{5})$/',
        'ET' => '/^(\d{4})$/',
        'FI' => '/^(?:FI)*(\d{5})$/',
        'FM' => '/^(\d{5})$/',
        'FO' => '/^(?:FO)*(\d{3})$/',
        'FR' => '/^(\d{5})$/',
        'GB' => '/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$/',
        'GE' => '/^(\d{4})$/',
        'GF' => '/^((97|98)3\d{2})$/',
        'GG' => '/^((?:(?:[A-PR-UWYZ][A-HK-Y]\d[ABEHMNPRV-Y0-9]|[A-PR-UWYZ]\d[A-HJKPS-UW0-9])\s\d[ABD-HJLNP-UW-Z]{2})|GIR\s?0AA)$/',
        'GL' => '/^(\d{4})$/',
        'GP' => '/^((97|98)\d{3})$/',
        'GR' => '/^(\d{3}\s?\d{2})$/',
        'GT' => '/^(\d{5})$/',
        'GU' => '/^(969\d{2})$/',
        'GW' => '/^(\d{4})$/',
        'HN' => '/^([A-Z]{2}\d{4})$/',
        'HR' => '/^(?:HR)*(\d{5})$/',
        'HT' => '/^(?:HT)*(\d{4})$/',
        'HU' => '/^(\d{4})$/',
        'ID' => '/^(\d{5})$/',
        'IE' => '/^(D6W|[AC-FHKNPRTV-Y][0-9]{2})\s?([AC-FHKNPRTV-Y0-9]{4})/',
        'IL' => '/^(\d{7}|\d{5})$/',
        'IM' => '/^((?:(?:[A-PR-UWYZ][A-HK-Y]\d[ABEHMNPRV-Y0-9]|[A-PR-UWYZ]\d[A-HJKPS-UW0-9])\s\d[ABD-HJLNP-UW-Z]{2})|GIR\s?0AA)$/',
        'IN' => '/^(\d{6})$/',
        'IQ' => '/^(\d{5})$/',
        'IR' => '/^(\d{10})$/',
        'IS' => '/^(\d{3})$/',
        'IT' => '/^(\d{5})$/',
        'JE' => '/^((?:(?:[A-PR-UWYZ][A-HK-Y]\d[ABEHMNPRV-Y0-9]|[A-PR-UWYZ]\d[A-HJKPS-UW0-9])\s\d[ABD-HJLNP-UW-Z]{2})|GIR\s?0AA)$/',
        'JO' => '/^(\d{5})$/',
        'JP' => '/^\d{3}-\d{4}$/',
        'KE' => '/^(\d{5})$/',
        'KG' => '/^(\d{6})$/',
        'KH' => '/^(\d{5})$/',
        'KP' => '/^(\d{6})$/',
        'KR' => '/^(\d{5})$/',
        'KW' => '/^(\d{5})$/',
        'KY' => '/^KY[1-3]-\d{4}$/',
        'KZ' => '/^(\d{6})$/',
        'LA' => '/^(\d{5})$/',
        'LB' => '/^(\d{4}(\d{4})?)$/',
        'LI' => '/^(\d{4})$/',
        'LK' => '/^(\d{5})$/',
        'LR' => '/^(\d{4})$/',
        'LS' => '/^(\d{3})$/',
        'LT' => '/^(?:LT)*(\d{5})$/',
        'LU' => '/^(?:L-)?\d{4}$/',
        'LV' => '/^(?:LV)*(\d{4})$/',
        'MA' => '/^(\d{5})$/',
        'MC' => '/^(\d{5})$/',
        'MD' => '/^MD-\d{4}$/',
        'ME' => '/^(\d{5})$/',
        'MF' => '/^(\d{5})$/',
        'MG' => '/^(\d{3})$/',
        'MH' => '/^969\d{2}(-\d{4})$/',
        'MK' => '/^(\d{4})$/',
        'MM' => '/^(\d{5})$/',
        'MN' => '/^(\d{6})$/',
        'MP' => '/^9695\d{1}$/',
        'MQ' => '/^(\d{5})$/',
        'MT' => '/^[A-Z]{3}\s?\d{4}$/',
        'MV' => '/^(\d{5})$/',
        'MW' => '/^(\d{6})$/',
        'MX' => '/^(\d{5})$/',
        'MY' => '/^(\d{5})$/',
        'MZ' => '/^(\d{4})$/',
        'NC' => '/^(\d{5})$/',
        'NE' => '/^(\d{4})$/',
        'NF' => '/^(\d{4})$/',
        'NG' => '/^(\d{6})$/',
        'NI' => '/^(\d{7})$/',
        'NL' => '/^(\d{4} ?[A-Z]{2})$/',
        'NO' => '/^(\d{4})$/',
        'NP' => '/^(\d{5})$/',
        'NZ' => '/^(\d{4})$/',
        'OM' => '/^(\d{3})$/',
        'PF' => '/^((97|98)7\d{2})$/',
        'PG' => '/^(\d{3})$/',
        'PH' => '/^(\d{4})$/',
        'PK' => '/^(\d{5})$/',
        'PL' => '/^\d{2}-\d{3}$/',
        'PM' => '/^(97500)$/',
        'PR' => '/^00[679]\d{2}(?:-\d{4})?$/',
        'PT' => '/^\d{4}-?\d{3}$/',
        'PW' => '/^(96940)$/',
        'PY' => '/^(\d{4})$/',
        'RE' => '/^((97|98)(4|7|8)\d{2})$/',
        'RO' => '/^(\d{6})$/',
        'RS' => '/^(\d{5})$/',
        'RU' => '/^(\d{6})$/',
        'SA' => '/^(\d{5})$/',
        'SD' => '/^(\d{5})$/',
        'SE' => '/^(?:SE)?\d{3}\s\d{2}$/',
        'SG' => '/^(\d{6})$/',
        'SH' => '/^(STHL1ZZ)$/',
        'SI' => '/^(?:SI)*(\d{4})$/',
        'SJ' => '/^(\d{4})$/',
        'SK' => '/^\d{3}\s?\d{2}$/',
        'SM' => '/^(4789\d)$/',
        'SN' => '/^(\d{5})$/',
        'SO' => '/^([A-Z]{2}\d{5})$/',
        'SV' => '/^(?:CP)*(\d{4})$/',
        'SZ' => '/^([A-Z]\d{3})$/',
        'TC' => '/^(TKCA 1ZZ)$/',
        'TH' => '/^(\d{5})$/',
        'TJ' => '/^(\d{6})$/',
        'TM' => '/^(\d{6})$/',
        'TN' => '/^(\d{4})$/',
        'TR' => '/^(\d{5})$/',
        'TW' => '/^(\d{5})$/',
        'UA' => '/^(\d{5})$/',
        'US' => '/^\d{5}(-\d{4})?$/',
        'UY' => '/^(\d{5})$/',
        'UZ' => '/^(\d{6})$/',
        'VA' => '/^(\d{5})$/',
        'VE' => '/^(\d{4})$/',
        'VI' => '/^008\d{2}(?:-\d{4})?$/',
        'VN' => '/^(\d{6})$/',
        'WF' => '/^(986\d{2})$/',
        'YT' => '/^(\d{5})$/',
        'ZA' => '/^(\d{4})$/',
        'ZM' => '/^(\d{5})$/',
        // phpcs:enable Generic.Files.LineLength.TooLong
    ];

    public function __construct(string $countryCode)
    {
        $countryCodeRule = new CountryCode();
        if (!$countryCodeRule->validate($countryCode)) {
            throw new ComponentException(sprintf('Cannot validate postal code from "%s" country', $countryCode));
        }

        parent::__construct(
            new Regex(self::POSTAL_CODES[$countryCode] ?? self::DEFAULT_PATTERN),
            ['countryCode' => $countryCode]
        );
    }
}
validation/library/Rules/Positive.php000064400000001441147361033760013761 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_numeric;

/**
 * Validates whether the input is a positive number.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 */
final class Positive extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        return $input > 0;
    }
}
validation/library/Rules/Directory.php000064400000001755147361033760014133 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Directory as NativeDirectory;
use SplFileInfo;

use function is_dir;
use function is_scalar;

/**
 * Validates if the given path is a directory.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Directory extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isDir();
        }

        if ($input instanceof NativeDirectory) {
            return true;
        }

        if (!is_scalar($input)) {
            return false;
        }

        return is_dir((string) $input);
    }
}
validation/library/Rules/Luhn.php000064400000002656147361033760013076 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_map;
use function count;
use function str_split;

/**
 * Validate whether a given input is a Luhn number.
 *
 * @see https://en.wikipedia.org/wiki/Luhn_algorithm
 *
 * @author Alexander Gorshkov <mazanax@yandex.ru>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Luhn extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!(new Digit())->validate($input)) {
            return false;
        }

        return $this->isValid((string) $input);
    }

    private function isValid(string $input): bool
    {
        $sum = 0;
        $digits = array_map('intval', str_split($input));
        $numDigits = count($digits);
        $parity = $numDigits % 2;
        for ($i = 0; $i < $numDigits; ++$i) {
            $digit = $digits[$i];
            if ($parity == $i % 2) {
                $digit <<= 1;
                if (9 < $digit) {
                    $digit = $digit - 9;
                }
            }
            $sum += $digit;
        }

        return $sum % 10 == 0;
    }
}
validation/library/Rules/CountryCode.php000064400000036061147361033760014423 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_column;
use function array_keys;
use function implode;
use function sprintf;

/**
 * Validates whether the input is a country code in ISO 3166-1 standard.
 *
 * This rule supports the three sets of country codes (alpha-2, alpha-3, and numeric).
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Felipe Martins <me@fefas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CountryCode extends AbstractSearcher
{
    /**
     * The ISO representation of a country code.
     */
    public const ALPHA2 = 'alpha-2';

    /**
     * The ISO3 representation of a country code.
     */
    public const ALPHA3 = 'alpha-3';

    /**
     * The ISO-number representation of a country code.
     */
    public const NUMERIC = 'numeric';

    /**
     * Position of the indexes of each set in the list of country codes.
     */
    private const SET_INDEXES = [
        self::ALPHA2 => 0,
        self::ALPHA3 => 1,
        self::NUMERIC => 2,
    ];

    /**
     * @see https://salsa.debian.org/iso-codes-team/iso-codes
     */
    private const COUNTRY_CODES = [
        ['AD', 'AND', '020'], // Andorra
        ['AE', 'ARE', '784'], // United Arab Emirates
        ['AF', 'AFG', '004'], // Afghanistan
        ['AG', 'ATG', '028'], // Antigua and Barbuda
        ['AI', 'AFI', '262'], // French Afars and Issas
        ['AI', 'AIA', '660'], // Anguilla
        ['AL', 'ALB', '008'], // Albania
        ['AM', 'ARM', '051'], // Armenia
        ['AN', 'ANT', '530'], // Netherlands Antilles
        ['AO', 'AGO', '024'], // Angola
        ['AQ', 'ATA', '010'], // Antarctica
        ['AR', 'ARG', '032'], // Argentina
        ['AS', 'ASM', '016'], // American Samoa
        ['AT', 'AUT', '040'], // Austria
        ['AU', 'AUS', '036'], // Australia
        ['AW', 'ABW', '533'], // Aruba
        ['AX', 'ALA', '248'], // Åland Islands
        ['AZ', 'AZE', '031'], // Azerbaijan
        ['BA', 'BIH', '070'], // Bosnia and Herzegovina
        ['BB', 'BRB', '052'], // Barbados
        ['BD', 'BGD', '050'], // Bangladesh
        ['BE', 'BEL', '056'], // Belgium
        ['BF', 'BFA', '854'], // Burkina Faso
        ['BG', 'BGR', '100'], // Bulgaria
        ['BH', 'BHR', '048'], // Bahrain
        ['BI', 'BDI', '108'], // Burundi
        ['BJ', 'BEN', '204'], // Benin
        ['BL', 'BLM', '652'], // Saint Barthélemy
        ['BM', 'BMU', '060'], // Bermuda
        ['BN', 'BRN', '096'], // Brunei Darussalam
        ['BO', 'BOL', '068'], // Bolivia, Plurinational State of
        ['BQ', 'ATB', null], // British Antarctic Territory
        ['BQ', 'BES', '535'], // Bonaire, Sint Eustatius and Saba
        ['BR', 'BRA', '076'], // Brazil
        ['BS', 'BHS', '044'], // Bahamas
        ['BT', 'BTN', '064'], // Bhutan
        ['BU', 'BUR', '104'], // Burma, Socialist Republic of the Union of
        ['BV', 'BVT', '074'], // Bouvet Island
        ['BW', 'BWA', '072'], // Botswana
        ['BY', 'BLR', '112'], // Belarus
        ['BY', 'BYS', '112'], // Byelorussian SSR Soviet Socialist Republic
        ['BZ', 'BLZ', '084'], // Belize
        ['CA', 'CAN', '124'], // Canada
        ['CC', 'CCK', '166'], // Cocos (Keeling) Islands
        ['CD', 'COD', '180'], // Congo, The Democratic Republic of the
        ['CF', 'CAF', '140'], // Central African Republic
        ['CG', 'COG', '178'], // Congo
        ['CH', 'CHE', '756'], // Switzerland
        ['CI', 'CIV', '384'], // Côte d'Ivoire
        ['CK', 'COK', '184'], // Cook Islands
        ['CL', 'CHL', '152'], // Chile
        ['CM', 'CMR', '120'], // Cameroon
        ['CN', 'CHN', '156'], // China
        ['CO', 'COL', '170'], // Colombia
        ['CR', 'CRI', '188'], // Costa Rica
        ['CS', 'CSK', '200'], // Czechoslovakia, Czechoslovak Socialist Republic
        ['CS', 'SCG', '891'], // Serbia and Montenegro
        ['CT', 'CTE', '128'], // Canton and Enderbury Islands
        ['CU', 'CUB', '192'], // Cuba
        ['CV', 'CPV', '132'], // Cabo Verde
        ['CW', 'CUW', '531'], // Curaçao
        ['CX', 'CXR', '162'], // Christmas Island
        ['CY', 'CYP', '196'], // Cyprus
        ['CZ', 'CZE', '203'], // Czechia
        ['DD', 'DDR', '278'], // German Democratic Republic
        ['DE', 'DEU', '276'], // Germany
        ['DJ', 'DJI', '262'], // Djibouti
        ['DK', 'DNK', '208'], // Denmark
        ['DM', 'DMA', '212'], // Dominica
        ['DO', 'DOM', '214'], // Dominican Republic
        ['DY', 'DHY', '204'], // Dahomey
        ['DZ', 'DZA', '012'], // Algeria
        ['EC', 'ECU', '218'], // Ecuador
        ['EE', 'EST', '233'], // Estonia
        ['EG', 'EGY', '818'], // Egypt
        ['EH', 'ESH', '732'], // Western Sahara
        ['ER', 'ERI', '232'], // Eritrea
        ['ES', 'ESP', '724'], // Spain
        ['ET', 'ETH', '231'], // Ethiopia
        ['FI', 'FIN', '246'], // Finland
        ['FJ', 'FJI', '242'], // Fiji
        ['FK', 'FLK', '238'], // Falkland Islands (Malvinas)
        ['FM', 'FSM', '583'], // Micronesia, Federated States of
        ['FO', 'FRO', '234'], // Faroe Islands
        ['FQ', 'ATF', null], // French Southern and Antarctic Territories
        ['FR', 'FRA', '250'], // France
        ['FX', 'FXX', '249'], // France, Metropolitan
        ['GA', 'GAB', '266'], // Gabon
        ['GB', 'GBR', '826'], // United Kingdom
        ['GD', 'GRD', '308'], // Grenada
        ['GE', 'GEL', '296'], // Gilbert and Ellice Islands
        ['GE', 'GEO', '268'], // Georgia
        ['GF', 'GUF', '254'], // French Guiana
        ['GG', 'GGY', '831'], // Guernsey
        ['GH', 'GHA', '288'], // Ghana
        ['GI', 'GIB', '292'], // Gibraltar
        ['GL', 'GRL', '304'], // Greenland
        ['GM', 'GMB', '270'], // Gambia
        ['GN', 'GIN', '324'], // Guinea
        ['GP', 'GLP', '312'], // Guadeloupe
        ['GQ', 'GNQ', '226'], // Equatorial Guinea
        ['GR', 'GRC', '300'], // Greece
        ['GS', 'SGS', '239'], // South Georgia and the South Sandwich Islands
        ['GT', 'GTM', '320'], // Guatemala
        ['GU', 'GUM', '316'], // Guam
        ['GW', 'GNB', '624'], // Guinea-Bissau
        ['GY', 'GUY', '328'], // Guyana
        ['HK', 'HKG', '344'], // Hong Kong
        ['HM', 'HMD', '334'], // Heard Island and McDonald Islands
        ['HN', 'HND', '340'], // Honduras
        ['HR', 'HRV', '191'], // Croatia
        ['HT', 'HTI', '332'], // Haiti
        ['HU', 'HUN', '348'], // Hungary
        ['HV', 'HVO', '854'], // Upper Volta, Republic of
        ['ID', 'IDN', '360'], // Indonesia
        ['IE', 'IRL', '372'], // Ireland
        ['IL', 'ISR', '376'], // Israel
        ['IM', 'IMN', '833'], // Isle of Man
        ['IN', 'IND', '356'], // India
        ['IO', 'IOT', '086'], // British Indian Ocean Territory
        ['IQ', 'IRQ', '368'], // Iraq
        ['IR', 'IRN', '364'], // Iran, Islamic Republic of
        ['IS', 'ISL', '352'], // Iceland
        ['IT', 'ITA', '380'], // Italy
        ['JE', 'JEY', '832'], // Jersey
        ['JM', 'JAM', '388'], // Jamaica
        ['JO', 'JOR', '400'], // Jordan
        ['JP', 'JPN', '392'], // Japan
        ['JT', 'JTN', '396'], // Johnston Island
        ['KE', 'KEN', '404'], // Kenya
        ['KG', 'KGZ', '417'], // Kyrgyzstan
        ['KH', 'KHM', '116'], // Cambodia
        ['KI', 'KIR', '296'], // Kiribati
        ['KM', 'COM', '174'], // Comoros
        ['KN', 'KNA', '659'], // Saint Kitts and Nevis
        ['KP', 'PRK', '408'], // Korea, Democratic People's Republic of
        ['KR', 'KOR', '410'], // Korea, Republic of
        ['KW', 'KWT', '414'], // Kuwait
        ['KY', 'CYM', '136'], // Cayman Islands
        ['KZ', 'KAZ', '398'], // Kazakhstan
        ['LA', 'LAO', '418'], // Lao People's Democratic Republic
        ['LB', 'LBN', '422'], // Lebanon
        ['LC', 'LCA', '662'], // Saint Lucia
        ['LI', 'LIE', '438'], // Liechtenstein
        ['LK', 'LKA', '144'], // Sri Lanka
        ['LR', 'LBR', '430'], // Liberia
        ['LS', 'LSO', '426'], // Lesotho
        ['LT', 'LTU', '440'], // Lithuania
        ['LU', 'LUX', '442'], // Luxembourg
        ['LV', 'LVA', '428'], // Latvia
        ['LY', 'LBY', '434'], // Libya
        ['MA', 'MAR', '504'], // Morocco
        ['MC', 'MCO', '492'], // Monaco
        ['MD', 'MDA', '498'], // Moldova, Republic of
        ['ME', 'MNE', '499'], // Montenegro
        ['MF', 'MAF', '663'], // Saint Martin (French part)
        ['MG', 'MDG', '450'], // Madagascar
        ['MH', 'MHL', '584'], // Marshall Islands
        ['MI', 'MID', '488'], // Midway Islands
        ['MK', 'MKD', '807'], // North Macedonia
        ['ML', 'MLI', '466'], // Mali
        ['MM', 'MMR', '104'], // Myanmar
        ['MN', 'MNG', '496'], // Mongolia
        ['MO', 'MAC', '446'], // Macao
        ['MP', 'MNP', '580'], // Northern Mariana Islands
        ['MQ', 'MTQ', '474'], // Martinique
        ['MR', 'MRT', '478'], // Mauritania
        ['MS', 'MSR', '500'], // Montserrat
        ['MT', 'MLT', '470'], // Malta
        ['MU', 'MUS', '480'], // Mauritius
        ['MV', 'MDV', '462'], // Maldives
        ['MW', 'MWI', '454'], // Malawi
        ['MX', 'MEX', '484'], // Mexico
        ['MY', 'MYS', '458'], // Malaysia
        ['MZ', 'MOZ', '508'], // Mozambique
        ['NA', 'NAM', '516'], // Namibia
        ['NC', 'NCL', '540'], // New Caledonia
        ['NE', 'NER', '562'], // Niger
        ['NF', 'NFK', '574'], // Norfolk Island
        ['NG', 'NGA', '566'], // Nigeria
        ['NH', 'NHB', '548'], // New Hebrides
        ['NI', 'NIC', '558'], // Nicaragua
        ['NL', 'NLD', '528'], // Netherlands
        ['NO', 'NOR', '578'], // Norway
        ['NP', 'NPL', '524'], // Nepal
        ['NQ', 'ATN', '216'], // Dronning Maud Land
        ['NR', 'NRU', '520'], // Nauru
        ['NT', 'NTZ', '536'], // Neutral Zone
        ['NU', 'NIU', '570'], // Niue
        ['NZ', 'NZL', '554'], // New Zealand
        ['OM', 'OMN', '512'], // Oman
        ['PA', 'PAN', '591'], // Panama
        ['PC', 'PCI', '582'], // Pacific Islands (trust territory)
        ['PE', 'PER', '604'], // Peru
        ['PF', 'PYF', '258'], // French Polynesia
        ['PG', 'PNG', '598'], // Papua New Guinea
        ['PH', 'PHL', '608'], // Philippines
        ['PK', 'PAK', '586'], // Pakistan
        ['PL', 'POL', '616'], // Poland
        ['PM', 'SPM', '666'], // Saint Pierre and Miquelon
        ['PN', 'PCN', '612'], // Pitcairn
        ['PR', 'PRI', '630'], // Puerto Rico
        ['PS', 'PSE', '275'], // Palestine, State of
        ['PT', 'PRT', '620'], // Portugal
        ['PU', 'PUS', '849'], // US Miscellaneous Pacific Islands
        ['PW', 'PLW', '585'], // Palau
        ['PY', 'PRY', '600'], // Paraguay
        ['PZ', 'PCZ', null], // Panama Canal Zone
        ['QA', 'QAT', '634'], // Qatar
        ['RE', 'REU', '638'], // Réunion
        ['RH', 'RHO', '716'], // Southern Rhodesia
        ['RO', 'ROU', '642'], // Romania
        ['RS', 'SRB', '688'], // Serbia
        ['RU', 'RUS', '643'], // Russian Federation
        ['RW', 'RWA', '646'], // Rwanda
        ['SA', 'SAU', '682'], // Saudi Arabia
        ['SB', 'SLB', '090'], // Solomon Islands
        ['SC', 'SYC', '690'], // Seychelles
        ['SD', 'SDN', '729'], // Sudan
        ['SE', 'SWE', '752'], // Sweden
        ['SG', 'SGP', '702'], // Singapore
        ['SH', 'SHN', '654'], // Saint Helena, Ascension and Tristan da Cunha
        ['SI', 'SVN', '705'], // Slovenia
        ['SJ', 'SJM', '744'], // Svalbard and Jan Mayen
        ['SK', 'SKM', null], // Sikkim
        ['SK', 'SVK', '703'], // Slovakia
        ['SL', 'SLE', '694'], // Sierra Leone
        ['SM', 'SMR', '674'], // San Marino
        ['SN', 'SEN', '686'], // Senegal
        ['SO', 'SOM', '706'], // Somalia
        ['SR', 'SUR', '740'], // Suriname
        ['SS', 'SSD', '728'], // South Sudan
        ['ST', 'STP', '678'], // Sao Tome and Principe
        ['SU', 'SUN', '810'], // USSR, Union of Soviet Socialist Republics
        ['SV', 'SLV', '222'], // El Salvador
        ['SX', 'SXM', '534'], // Sint Maarten (Dutch part)
        ['SY', 'SYR', '760'], // Syrian Arab Republic
        ['SZ', 'SWZ', '748'], // Eswatini
        ['TC', 'TCA', '796'], // Turks and Caicos Islands
        ['TD', 'TCD', '148'], // Chad
        ['TF', 'ATF', '260'], // French Southern Territories
        ['TG', 'TGO', '768'], // Togo
        ['TH', 'THA', '764'], // Thailand
        ['TJ', 'TJK', '762'], // Tajikistan
        ['TK', 'TKL', '772'], // Tokelau
        ['TL', 'TLS', '626'], // Timor-Leste
        ['TM', 'TKM', '795'], // Turkmenistan
        ['TN', 'TUN', '788'], // Tunisia
        ['TO', 'TON', '776'], // Tonga
        ['TP', 'TMP', '626'], // East Timor
        ['TR', 'TUR', '792'], // Turkey
        ['TT', 'TTO', '780'], // Trinidad and Tobago
        ['TV', 'TUV', '798'], // Tuvalu
        ['TW', 'TWN', '158'], // Taiwan, Province of China
        ['TZ', 'TZA', '834'], // Tanzania, United Republic of
        ['UA', 'UKR', '804'], // Ukraine
        ['UG', 'UGA', '800'], // Uganda
        ['UM', 'UMI', '581'], // United States Minor Outlying Islands
        ['US', 'USA', '840'], // United States
        ['UY', 'URY', '858'], // Uruguay
        ['UZ', 'UZB', '860'], // Uzbekistan
        ['VA', 'VAT', '336'], // Holy See (Vatican City State)
        ['VC', 'VCT', '670'], // Saint Vincent and the Grenadines
        ['VD', 'VDR', null], // Viet-Nam, Democratic Republic of
        ['VE', 'VEN', '862'], // Venezuela, Bolivarian Republic of
        ['VG', 'VGB', '092'], // Virgin Islands, British
        ['VI', 'VIR', '850'], // Virgin Islands, U.S.
        ['VN', 'VNM', '704'], // Viet Nam
        ['VU', 'VUT', '548'], // Vanuatu
        ['WF', 'WLF', '876'], // Wallis and Futuna
        ['WK', 'WAK', '872'], // Wake Island
        ['WS', 'WSM', '882'], // Samoa
        ['YD', 'YMD', '720'], // Yemen, Democratic, People's Democratic Republic of
        ['YE', 'YEM', '887'], // Yemen
        ['YT', 'MYT', '175'], // Mayotte
        ['YU', 'YUG', '891'], // Yugoslavia, Socialist Federal Republic of
        ['ZA', 'ZAF', '710'], // South Africa
        ['ZM', 'ZMB', '894'], // Zambia
        ['ZR', 'ZAR', '180'], // Zaire, Republic of
        ['ZW', 'ZWE', '716'], // Zimbabwe
    ];

    /**
     * @var string
     */
    private $set;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException If $set is not a valid set
     */
    public function __construct(string $set = self::ALPHA2)
    {
        if (!isset(self::SET_INDEXES[$set])) {
            throw new ComponentException(
                sprintf(
                    '"%s" is not a valid set for ISO 3166-1 (Available: %s)',
                    $set,
                    implode(', ', array_keys(self::SET_INDEXES))
                )
            );
        }

        $this->set = $set;
    }

    /**
     * {@inheritDoc}
     */
    protected function getDataSource(): array
    {
        return array_column(self::COUNTRY_CODES, self::SET_INDEXES[$this->set]);
    }
}
validation/library/Rules/ContainsAny.php000064400000002611147361033760014405 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_map;

/**
 * Validates if the input contains at least one of defined values
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kirill Dlussky <kirill@dlussky.ru>
 */
final class ContainsAny extends AbstractEnvelope
{
    /**
     * Initializes the rule.
     *
     * @param mixed[] $needles At least one of the values provided must be found in input string or array
     * @param bool $identical Defines whether the value should be compared strictly, when validating array
     */
    public function __construct(array $needles, bool $identical = false)
    {
        parent::__construct(
            new AnyOf(...$this->getRules($needles, $identical)),
            ['needles' => $needles]
        );
    }

    /**
     * @param mixed[] $needles
     *
     * @return Contains[]
     */
    private function getRules(array $needles, bool $identical): array
    {
        return array_map(
            static function ($needle) use ($identical): Contains {
                return new Contains($needle, $identical);
            },
            $needles
        );
    }
}
validation/library/Rules/Executable.php000064400000001606147361033760014243 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use SplFileInfo;

use function is_executable;
use function is_scalar;

/**
 * Validates if a file is an executable.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Executable extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isExecutable();
        }

        if (!is_scalar($input)) {
            return false;
        }

        return is_executable((string) $input);
    }
}
validation/library/Rules/Type.php000064400000004057147361033760013106 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_keys;
use function gettype;
use function implode;
use function is_callable;
use function sprintf;

/**
 * Validates the type of input.
 *
 * @author Gabriel Caruso <carusogabriel34@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Type extends AbstractRule
{
    /**
     * Collection of available types for validation.
     *
     */
    private const AVAILABLE_TYPES = [
        'array' => 'array',
        'bool' => 'boolean',
        'boolean' => 'boolean',
        'callable' => 'callable',
        'double' => 'double',
        'float' => 'double',
        'int' => 'integer',
        'integer' => 'integer',
        'null' => 'NULL',
        'object' => 'object',
        'resource' => 'resource',
        'string' => 'string',
    ];

    /**
     * Type to validate input against.
     *
     * @var string
     */
    private $type;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException When $type is not a valid one
     */
    public function __construct(string $type)
    {
        if (!isset(self::AVAILABLE_TYPES[$type])) {
            throw new ComponentException(
                sprintf(
                    '"%s" is not a valid type (Available: %s)',
                    $type,
                    implode(', ', array_keys(self::AVAILABLE_TYPES))
                )
            );
        }

        $this->type = $type;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->type === 'callable') {
            return is_callable($input);
        }

        return self::AVAILABLE_TYPES[$this->type] === gettype($input);
    }
}
validation/library/Rules/IterableType.php000064400000001310147361033760014543 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanValidateIterable;

/**
 * Validates whether the pseudo-type of the input is iterable or not.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IterableType extends AbstractRule
{
    use CanValidateIterable;

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $this->isIterable($input);
    }
}
validation/library/Rules/Identical.php000064400000001522147361033760014053 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates if the input is identical to some value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Identical extends AbstractRule
{
    /**
     * @var mixed
     */
    private $compareTo;

    /**
     * Initializes the rule.
     *
     * @param mixed $compareTo
     */
    public function __construct($compareTo)
    {
        $this->compareTo = $compareTo;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $input === $this->compareTo;
    }
}
validation/library/Rules/Factor.php000064400000003017147361033760013376 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function abs;
use function is_integer;
use function is_numeric;

/**
 * Validates if the input is a factor of the defined dividend.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author David Meister <thedavidmeister@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Factor extends AbstractRule
{
    /**
     * @var int
     */
    private $dividend;

    /**
     * Initializes the rule.
     */
    public function __construct(int $dividend)
    {
        $this->dividend = $dividend;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        // Every integer is a factor of zero, and zero is the only integer that
        // has zero for a factor.
        if ($this->dividend === 0) {
            return true;
        }

        // Factors must be integers that are not zero.
        if (!is_numeric($input) || (int) $input != $input || $input == 0) {
            return false;
        }

        $input = (int) abs((int) $input);
        $dividend = (int) abs($this->dividend);

        // The dividend divided by the input must be an integer if input is a
        // factor of the dividend.
        return is_integer($dividend / $input);
    }
}
validation/library/Rules/FilterVar.php000064400000003255147361033760014062 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function in_array;
use function is_array;
use function is_int;

use const FILTER_VALIDATE_BOOLEAN;
use const FILTER_VALIDATE_DOMAIN;
use const FILTER_VALIDATE_EMAIL;
use const FILTER_VALIDATE_FLOAT;
use const FILTER_VALIDATE_INT;
use const FILTER_VALIDATE_IP;
use const FILTER_VALIDATE_REGEXP;
use const FILTER_VALIDATE_URL;

/**
 * Validates the input with the PHP's filter_var() function.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FilterVar extends AbstractEnvelope
{
    private const ALLOWED_FILTERS = [
        FILTER_VALIDATE_BOOLEAN,
        FILTER_VALIDATE_DOMAIN,
        FILTER_VALIDATE_EMAIL,
        FILTER_VALIDATE_FLOAT,
        FILTER_VALIDATE_INT,
        FILTER_VALIDATE_IP,
        FILTER_VALIDATE_REGEXP,
        FILTER_VALIDATE_URL,
    ];

    /**
     * Initializes the rule.
     *
     * @param mixed $options
     *
     * @throws ComponentException
     */
    public function __construct(int $filter, $options = null)
    {
        if (!in_array($filter, self::ALLOWED_FILTERS)) {
            throw new ComponentException('Cannot accept the given filter');
        }

        $arguments = [$filter];
        if (is_array($options) || is_int($options)) {
            $arguments[] = $options;
        }

        parent::__construct(new Callback('filter_var', ...$arguments));
    }
}
validation/library/Rules/Pis.php000064400000002556147361033760012722 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function mb_strlen;
use function preg_match;
use function preg_replace;

/**
 * Validates a Brazilian PIS/NIS number.
 *
 * @author Bruno Koga <brunokoga187@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Pis extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        $digits = (string) preg_replace('/\D/', '', (string) $input);
        if (mb_strlen($digits) != 11 || preg_match('/^' . $digits[0] . '{11}$/', $digits)) {
            return false;
        }

        $multipliers = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];

        $summation = 0;
        for ($position = 0; $position < 10; ++$position) {
            $summation += (int) $digits[$position] * $multipliers[$position];
        }

        $checkDigit = (int) $digits[10];

        $modulo = $summation % 11;

        return $checkDigit === ($modulo < 2 ? 0 : 11 - $modulo);
    }
}
validation/library/Rules/Time.php000064400000002704147361033760013060 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Helpers\CanValidateDateTime;

use function date;
use function is_scalar;
use function preg_match;
use function sprintf;
use function strtotime;

/**
 * Validates whether an input is a time or not
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Time extends AbstractRule
{
    use CanValidateDateTime;

    /**
     * @var string
     */
    private $format;

    /**
     * @var string
     */
    private $sample;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException
     */
    public function __construct(string $format = 'H:i:s')
    {
        if (!preg_match('/^[gGhHisuvaA\W]+$/', $format)) {
            throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
        }

        $this->format = $format;
        $this->sample = date($format, strtotime('23:59:59'));
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return $this->isDateTime($this->format, (string) $input);
    }
}
validation/library/Rules/Date.php000064400000002756147361033760013046 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Helpers\CanValidateDateTime;

use function date;
use function is_scalar;
use function preg_match;
use function sprintf;
use function strtotime;

/**
 * Validates if input is a date.
 *
 * @author Bruno Luiz da Silva <contato@brunoluiz.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Date extends AbstractRule
{
    use CanValidateDateTime;

    /**
     * @var string
     */
    private $format;

    /**
     * @var string
     */
    private $sample;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException
     */
    public function __construct(string $format = 'Y-m-d')
    {
        if (!preg_match('/^[djSFmMnYy\W]+$/', $format)) {
            throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
        }

        $this->format = $format;
        $this->sample = date($format, strtotime('2005-12-30'));
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return $this->isDateTime($this->format, (string) $input);
    }
}
validation/library/Rules/MaxAge.php000064400000001246147361033760013324 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates a maximum age for a given date.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MaxAge extends AbstractAge
{
    /**
     * {@inheritDoc}
     */
    protected function compare(int $baseDate, int $givenDate): bool
    {
        return $baseDate <= $givenDate;
    }
}
validation/library/Rules/Size.php000064400000006054147361033760013076 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use Respect\Validation\Exceptions\ComponentException;
use SplFileInfo;

use function filesize;
use function is_numeric;
use function is_string;
use function preg_match;
use function sprintf;

/**
 * Validates whether the input is a file that is of a certain size or not.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Felipe Stival <v0idpwn@gmail.com>
 */
final class Size extends AbstractRule
{
    /**
     * @var string|int|null
     */
    private $minSize;

    /**
     * @var float|null
     */
    private $minValue;

    /**
     * @var string|int|null
     */
    private $maxSize;

    /**
     * @var float|null
     */
    private $maxValue;

    /**
     * @param string|int|null $minSize
     * @param string|int|null $maxSize
     */
    public function __construct($minSize = null, $maxSize = null)
    {
        $this->minSize = $minSize;
        $this->minValue = $minSize ? $this->toBytes($minSize) : null;
        $this->maxSize = $maxSize;
        $this->maxValue = $maxSize ? $this->toBytes($maxSize) : null;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $this->isValidSize($input->getSize());
        }

        if ($input instanceof UploadedFileInterface) {
            return $this->isValidSize($input->getSize());
        }

        if ($input instanceof StreamInterface) {
            return $this->isValidSize($input->getSize());
        }

        if (is_string($input)) {
            return $this->isValidSize((int) filesize($input));
        }

        return false;
    }

    /**
     * @todo Move it to a trait
     *
     * @param mixed $size
     */
    private function toBytes($size): float
    {
        $value = $size;
        $units = ['b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb'];
        foreach ($units as $exponent => $unit) {
            if (!preg_match('/^(\d+(.\d+)?)' . $unit . '$/i', (string) $size, $matches)) {
                continue;
            }
            $value = $matches[1] * 1024 ** $exponent;
            break;
        }

        if (!is_numeric($value)) {
            throw new ComponentException(sprintf('"%s" is not a recognized file size.', (string) $size));
        }

        return (float) $value;
    }

    private function isValidSize(float $size): bool
    {
        if ($this->minValue !== null && $this->maxValue !== null) {
            return $size >= $this->minValue && $size <= $this->maxValue;
        }

        if ($this->minValue !== null) {
            return $size >= $this->minValue;
        }

        return $size <= $this->maxValue;
    }
}
validation/library/Rules/Equals.php000064400000001671147361033760013416 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates if the input is equal to some value.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 */
final class Equals extends AbstractRule
{
    /**
     * @var mixed
     */
    private $compareTo;

    /**
     * Initializes the rule.
     *
     * @param mixed $compareTo
     */
    public function __construct($compareTo)
    {
        $this->compareTo = $compareTo;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $input == $this->compareTo;
    }
}
validation/library/Rules/Countable.php000064400000001432147361033760014073 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Countable as CountableInterface;

use function is_array;

/**
 * Validates if the input is countable.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author João Torquato <joao.otl@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Countable extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_array($input) || $input instanceof CountableInterface;
    }
}
validation/library/Rules/AnyOf.php000064400000003571147361033760013201 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\AnyOfException;
use Respect\Validation\Exceptions\ValidationException;

use function count;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class AnyOf extends AbstractComposite
{
    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $validators = $this->getRules();
        $exceptions = $this->getAllThrownExceptions($input);
        $numRules = count($validators);
        $numExceptions = count($exceptions);
        if ($numExceptions === $numRules) {
            /** @var AnyOfException $anyOfException */
            $anyOfException = $this->reportError($input);
            $anyOfException->addChildren($exceptions);

            throw $anyOfException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        foreach ($this->getRules() as $v) {
            if ($v->validate($input)) {
                return true;
            }
        }

        return false;
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        foreach ($this->getRules() as $v) {
            try {
                $v->check($input);

                return;
            } catch (ValidationException $e) {
                if (!isset($firstException)) {
                    $firstException = $e;
                }
            }
        }

        if (isset($firstException)) {
            throw $firstException;
        }

        throw $this->reportError($input);
    }
}
validation/library/Rules/PhpLabel.php000064400000001577147361033760013660 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function preg_match;

/**
 * Validates if a value is considered a valid PHP Label, so that it can be used as a variable, function or class name.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PhpLabel extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_string($input) && preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $input);
    }
}
validation/library/Rules/AbstractComposite.php000064400000006660147361033760015615 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;

use function array_filter;
use function array_map;

/**
 * Abstract class for rules that are composed by other rules.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Wojciech Frącz <fraczwojciech@gmail.com>
 */
abstract class AbstractComposite extends AbstractRule
{
    /**
     * @var Validatable[]
     */
    private $rules = [];

    /**
     * Initializes the rule adding other rules to the stack.
     */
    public function __construct(Validatable ...$rules)
    {
        $this->rules = $rules;
    }

    /**
     * {@inheritDoc}
     */
    public function setName(string $name): Validatable
    {
        $parentName = $this->getName();
        foreach ($this->rules as $rule) {
            $ruleName = $rule->getName();
            if ($ruleName && $parentName !== $ruleName) {
                continue;
            }

            $rule->setName($name);
        }

        return parent::setName($name);
    }

    /**
     * Append a rule into the stack of rules.
     *
     * @return AbstractComposite
     */
    public function addRule(Validatable $rule): self
    {
        if ($this->shouldHaveNameOverwritten($rule) && $this->getName() !== null) {
            $rule->setName($this->getName());
        }

        $this->rules[] = $rule;

        return $this;
    }

    /**
     * Returns all the rules in the stack.
     *
     * @return Validatable[]
     */
    public function getRules(): array
    {
        return $this->rules;
    }

    /**
     * Returns all the exceptions throw when asserting all rules.
     *
     * @param mixed $input
     *
     * @return ValidationException[]
     */
    protected function getAllThrownExceptions($input): array
    {
        return array_filter(
            array_map(
                function (Validatable $rule) use ($input): ?ValidationException {
                    try {
                        $rule->assert($input);
                    } catch (ValidationException $exception) {
                        $this->updateExceptionTemplate($exception);

                        return $exception;
                    }

                    return null;
                },
                $this->getRules()
            )
        );
    }

    private function shouldHaveNameOverwritten(Validatable $rule): bool
    {
        return $this->hasName($this) && !$this->hasName($rule);
    }

    private function hasName(Validatable $rule): bool
    {
        return $rule->getName() !== null;
    }

    private function updateExceptionTemplate(ValidationException $exception): void
    {
        if ($this->template === null || $exception->hasCustomTemplate()) {
            return;
        }

        $exception->updateTemplate($this->template);

        if (!$exception instanceof NestedValidationException) {
            return;
        }

        foreach ($exception->getChildren() as $childException) {
            $this->updateExceptionTemplate($childException);
        }
    }
}
validation/library/Rules/Yes.php000064400000002310147361033760012713 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function nl_langinfo;
use function preg_match;

use const YESEXPR;

/**
 * Validates if the input considered as "Yes".
 *
 * @author Cameron Hall <me@chall.id.au>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Yes extends AbstractRule
{
    /**
     * @var bool
     */
    private $useLocale;

    /**
     * Initializes the rule.
     */
    public function __construct(bool $useLocale = false)
    {
        $this->useLocale = $useLocale;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return preg_match($this->getPattern(), $input) > 0;
    }

    private function getPattern(): string
    {
        if ($this->useLocale) {
            return '/' . nl_langinfo(YESEXPR) . '/';
        }

        return '/^y(eah?|ep|es)?$/i';
    }
}
validation/library/Rules/EndsWith.php000064400000003612147361033760013706 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function end;
use function is_array;
use function mb_strlen;
use function mb_strripos;
use function mb_strrpos;

/**
 * Validates only if the value is at the end of the input.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class EndsWith extends AbstractRule
{
    /**
     * @var mixed
     */
    private $endValue;

    /**
     * @var bool
     */
    private $identical;

    /**
     * @param mixed $endValue
     */
    public function __construct($endValue, bool $identical = false)
    {
        $this->endValue = $endValue;
        $this->identical = $identical;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->identical) {
            return $this->validateIdentical($input);
        }

        return $this->validateEquals($input);
    }

    /**
     * @param mixed $input
     */
    private function validateEquals($input): bool
    {
        if (is_array($input)) {
            return end($input) == $this->endValue;
        }

        return mb_strripos($input, $this->endValue) === mb_strlen($input) - mb_strlen($this->endValue);
    }

    /**
     * @param mixed $input
     */
    private function validateIdentical($input): bool
    {
        if (is_array($input)) {
            return end($input) === $this->endValue;
        }

        return mb_strrpos($input, $this->endValue) === mb_strlen($input) - mb_strlen($this->endValue);
    }
}
validation/library/Rules/Length.php000064400000006006147361033760013402 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Countable as CountableInterface;
use Respect\Validation\Exceptions\ComponentException;

use function count;
use function get_object_vars;
use function is_array;
use function is_int;
use function is_object;
use function is_string;
use function mb_strlen;
use function sprintf;

/**
 * Validates the length of the given input.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Blake Hair <blake.hair@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 * @author João Torquato <joao.otl@gmail.com>
 * @author Marcelo Araujo <msaraujo@php.net>
 */
final class Length extends AbstractRule
{
    /**
     * @var int|null
     */
    private $minValue;

    /**
     * @var int|null
     */
    private $maxValue;

    /**
     * @var bool
     */
    private $inclusive;

    /**
     * Creates the rule with a minimum and maximum value.
     *
     * @throws ComponentException
     */
    public function __construct(?int $min = null, ?int $max = null, bool $inclusive = true)
    {
        $this->minValue = $min;
        $this->maxValue = $max;
        $this->inclusive = $inclusive;

        if ($max !== null && $min > $max) {
            throw new ComponentException(sprintf('%d cannot be less than %d for validation', $min, $max));
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $length = $this->extractLength($input);
        if ($length === null) {
            return false;
        }

        return $this->validateMin($length) && $this->validateMax($length);
    }

    /**
     * @param mixed $input
     */
    private function extractLength($input): ?int
    {
        if (is_string($input)) {
            return (int) mb_strlen($input);
        }

        if (is_array($input) || $input instanceof CountableInterface) {
            return count($input);
        }

        if (is_object($input)) {
            return $this->extractLength(get_object_vars($input));
        }

        if (is_int($input)) {
            return $this->extractLength((string) $input);
        }

        return null;
    }

    private function validateMin(int $length): bool
    {
        if ($this->minValue === null) {
            return true;
        }

        if ($this->inclusive) {
            return $length >= $this->minValue;
        }

        return $length > $this->minValue;
    }

    private function validateMax(int $length): bool
    {
        if ($this->maxValue === null) {
            return true;
        }

        if ($this->inclusive) {
            return $length <= $this->maxValue;
        }

        return $length < $this->maxValue;
    }
}
validation/library/Rules/Sorted.php000064400000004266147361033760013427 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_values;
use function count;
use function is_array;
use function is_string;
use function sprintf;
use function str_split;

/**
 * Validates whether the input is sorted in a certain order or not.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Mikhail Vyrtsev <reeywhaar@gmail.com>
 */
final class Sorted extends AbstractRule
{
    public const ASCENDING = 'ASC';
    public const DESCENDING = 'DESC';

    /**
     * @var string
     */
    private $direction;

    public function __construct(string $direction)
    {
        if ($direction !== self::ASCENDING && $direction !== self::DESCENDING) {
            throw new ComponentException(
                sprintf('Direction should be either "%s" or "%s"', self::ASCENDING, self::DESCENDING)
            );
        }

        $this->direction = $direction;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_array($input) && !is_string($input)) {
            return false;
        }

        $values = $this->getValues($input);
        $count = count($values);
        for ($position = 1; $position < $count; ++$position) {
            if (!$this->isSorted($values[$position], $values[$position - 1])) {
                return false;
            }
        }

        return true;
    }

    /**
     * @param mixed $current
     * @param mixed $last
     */
    private function isSorted($current, $last): bool
    {
        if ($this->direction === self::ASCENDING) {
            return $current > $last;
        }

        return $current < $last;
    }

    /**
     * @param string|mixed[] $input
     *
     * @return mixed[]
     */
    private function getValues($input): array
    {
        if (is_array($input)) {
            return array_values($input);
        }

        return str_split($input);
    }
}
validation/library/Rules/Zend.php000064400000007513147361033760013065 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use ReflectionClass;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Exceptions\ZendException;
use Throwable;
use Zend\Validator\ValidatorInterface;

use function array_map;
use function class_exists;
use function current;
use function is_string;
use function sprintf;
use function stripos;

/**
 * Use Zend validators inside Respect\Validation flow.
 *
 * Messages are preserved.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 */
final class Zend extends AbstractRule
{
    /**
     * @var ValidatorInterface
     */
    private $zendValidator;

    /**
     * @param string|ValidatorInterface $validator
     * @param mixed[] $params
     *
     * @throws ComponentException
     */
    public function __construct($validator, array $params = [])
    {
        $this->zendValidator = $this->zendValidator($validator, $params);
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $validator = clone $this->zendValidator;
        if ($validator->isValid($input)) {
            return;
        }

        /** @var ZendException $zendException */
        $zendException = $this->reportError($input);
        $zendException->addChildren(
            array_map(
                function (string $message) use ($input): ValidationException {
                    $exception = $this->reportError($input);
                    $exception->updateTemplate($message);

                    return $exception;
                },
                $validator->getMessages()
            )
        );

        throw $zendException;
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $validator = clone $this->zendValidator;
        if ($validator->isValid($input)) {
            return;
        }

        /** @var ZendException $zendException */
        $zendException = $this->reportError($input);
        $zendException->updateTemplate(current($validator->getMessages()));

        throw $zendException;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return (clone $this->zendValidator)->isValid($input);
    }

    /**
     * @param mixed $validator
     * @param mixed[] $params
     *
     * @throws ComponentException
     */
    private function zendValidator($validator, array $params = []): ValidatorInterface
    {
        if ($validator instanceof ValidatorInterface) {
            return $validator;
        }

        if (!is_string($validator)) {
            throw new ComponentException('The given argument is not a valid Zend Validator');
        }

        $className = stripos($validator, 'Zend') === false ? 'Zend\\Validator\\' . $validator : '\\' . $validator;

        try {
            if (!class_exists($className)) {
                throw new ComponentException(sprintf('"%s" is not a valid class name', $className));
            }

            $reflection = new ReflectionClass($className);
            if (!$reflection->isInstantiable()) {
                throw new ComponentException(sprintf('"%s" is not instantiable', $className));
            }

            return $this->zendValidator($reflection->newInstanceArgs($params));
        } catch (Throwable $exception) {
            throw new ComponentException(sprintf('Could not create "%s"', $validator), 0, $exception);
        }
    }
}
validation/library/Rules/Decimal.php000064400000002754147361033760013525 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_numeric;
use function is_string;
use function number_format;
use function preg_replace;
use function var_export;

/**
 * Validates the decimal
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Decimal extends AbstractRule
{
    /**
     * @var int
     */
    private $decimals;

    public function __construct(int $decimals)
    {
        $this->decimals = $decimals;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        return $this->toFormattedString($input) === $this->toRawString($input);
    }

    /**
     * @param mixed $input
     */
    private function toRawString($input): string
    {
        if (is_string($input)) {
            return $input;
        }

        return var_export($input, true);
    }

    /**
     * @param mixed $input
     */
    private function toFormattedString($input): string
    {
        $formatted = number_format((float) $input, $this->decimals, '.', '');
        if (is_string($input)) {
            return $formatted;
        }

        return preg_replace('/^(\d.\d)0*/', '$1', $formatted);
    }
}
validation/library/Rules/KeySet.php000064400000005640147361033760013370 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Validatable;

use function array_key_exists;
use function array_map;
use function count;
use function current;
use function is_array;

/**
 * Validates a keys in a defined structure.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class KeySet extends AbstractWrapper
{
    /**
     * @var mixed[]
     */
    private $keys;

    /**
     * @var Key[]
     */
    private $keyRules;

    /**
     * Initializes the rule.
     *
     * @param Validatable[] ...$validatables
     */
    public function __construct(Validatable ...$validatables)
    {
        $this->keyRules = array_map([$this, 'getKeyRule'], $validatables);
        $this->keys = array_map([$this, 'getKeyReference'], $this->keyRules);

        parent::__construct(new AllOf(...$this->keyRules));
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if (!$this->hasValidStructure($input)) {
            throw $this->reportError($input);
        }

        parent::assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        if (!$this->hasValidStructure($input)) {
            throw $this->reportError($input);
        }

        parent::check($input);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!$this->hasValidStructure($input)) {
            return false;
        }

        return parent::validate($input);
    }

    /**
     * @throws ComponentException
     */
    private function getKeyRule(Validatable $validatable): Key
    {
        if ($validatable instanceof Key) {
            return $validatable;
        }

        if (!$validatable instanceof AllOf || count($validatable->getRules()) !== 1) {
            throw new ComponentException('KeySet rule accepts only Key rules');
        }

        return $this->getKeyRule(current($validatable->getRules()));
    }

    /**
     * @return mixed
     */
    private function getKeyReference(Key $rule)
    {
        return $rule->getReference();
    }

    /**
     * @param mixed $input
     */
    private function hasValidStructure($input): bool
    {
        if (!is_array($input)) {
            return false;
        }

        foreach ($this->keyRules as $keyRule) {
            if (!array_key_exists($keyRule->getReference(), $input) && $keyRule->isMandatory()) {
                return false;
            }

            unset($input[$keyRule->getReference()]);
        }

        return count($input) == 0;
    }
}
validation/library/Rules/PolishIdCard.php000064400000002750147361033760014470 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ord;
use function preg_match;

/**
 * Validates whether the input is a Polish identity card (Dowód Osobisty).
 *
 * @see https://en.wikipedia.org/wiki/Polish_identity_card
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PolishIdCard extends AbstractRule
{
    private const ASCII_CODE_0 = 48;
    private const ASCII_CODE_7 = 55;
    private const ASCII_CODE_9 = 57;
    private const ASCII_CODE_A = 65;

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!preg_match('/^[A-Z0-9]{9}$/', $input)) {
            return false;
        }

        $weights = [7, 3, 1, 0, 7, 3, 1, 7, 3];
        $weightedSum = 0;
        for ($i = 0; $i < 9; ++$i) {
            $code = ord($input[$i]);
            if ($i < 3 && $code <= self::ASCII_CODE_9) {
                return false;
            }

            if ($i > 2 && $code >= self::ASCII_CODE_A) {
                return false;
            }

            $difference = $code <= self::ASCII_CODE_9 ? self::ASCII_CODE_0 : self::ASCII_CODE_7;
            $weightedSum += ($code - $difference) * $weights[$i];
        }

        return $weightedSum % 10 == $input[3];
    }
}
validation/library/Rules/OneOf.php000064400000004011147361033760013161 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\OneOfException;
use Respect\Validation\Exceptions\ValidationException;

use function array_shift;
use function count;

/**
 * @author Bradyn Poulsen <bradyn@bradynpoulsen.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class OneOf extends AbstractComposite
{
    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $validators = $this->getRules();
        $exceptions = $this->getAllThrownExceptions($input);
        $numRules = count($validators);
        $numExceptions = count($exceptions);
        if ($numExceptions !== $numRules - 1) {
            /** @var OneOfException $oneOfException */
            $oneOfException = $this->reportError($input);
            $oneOfException->addChildren($exceptions);

            throw $oneOfException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $rulesPassedCount = 0;
        foreach ($this->getRules() as $rule) {
            if (!$rule->validate($input)) {
                continue;
            }

            ++$rulesPassedCount;
        }

        return $rulesPassedCount === 1;
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $exceptions = [];
        $rulesPassedCount = 0;
        foreach ($this->getRules() as $rule) {
            try {
                $rule->check($input);

                ++$rulesPassedCount;
            } catch (ValidationException $exception) {
                $exceptions[] = $exception;
            }
        }

        if ($rulesPassedCount === 1) {
            return;
        }

        throw array_shift($exceptions) ?: $this->reportError($input);
    }
}
validation/library/Rules/Url.php000064400000001351147361033760012721 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use const FILTER_VALIDATE_URL;

/**
 * Validates whether the input is a URL.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Url extends AbstractEnvelope
{
    /**
     * Initializes the rule.
     *
     * @throws ComponentException
     */
    public function __construct()
    {
        parent::__construct(new FilterVar(FILTER_VALIDATE_URL));
    }
}
validation/library/Rules/AbstractComparison.php000064400000002605147361033760015760 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanCompareValues;

/**
 * Abstract class to help on creating rules that compare value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
abstract class AbstractComparison extends AbstractRule
{
    use CanCompareValues;

    /**
     * @var mixed
     */
    private $compareTo;

    /**
     * Compare both values and return whether the comparison is valid or not.
     *
     * @param mixed $left
     * @param mixed $right
     */
    abstract protected function compare($left, $right): bool;

    /**
     * Initializes the rule by setting the value to be compared to the input.
     *
     * @param mixed $maxValue
     */
    public function __construct($maxValue)
    {
        $this->compareTo = $maxValue;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $left = $this->toComparable($input);
        $right = $this->toComparable($this->compareTo);

        if (!$this->isAbleToCompareValues($left, $right)) {
            return false;
        }

        return $this->compare($left, $right);
    }
}
validation/library/Rules/Finite.php000064400000001322147361033760013373 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_finite;
use function is_numeric;

/**
 * Validates if the input is a finite number.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Finite extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_numeric($input) && is_finite((float) $input);
    }
}
validation/library/Rules/Tld.php000064400000042037147361033760012710 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function in_array;
use function is_scalar;
use function mb_strtoupper;

/**
 * Validates whether the input is a top-level domain.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Bogus <g.predl@edis.at>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Tld extends AbstractRule
{
    /**
     * List extracted from https://data.iana.org/TLD/tlds-alpha-by-domain.txt
     * Version 2021031301, Last Updated Sat Mar 13 07:07:01 2021 UTC
     */
    private const TLD_LIST = [
        'AAA', 'AARP', 'ABARTH', 'ABB', 'ABBOTT', 'ABBVIE', 'ABC', 'ABLE',
        'ABOGADO', 'ABUDHABI', 'AC', 'ACADEMY', 'ACCENTURE', 'ACCOUNTANT',
        'ACCOUNTANTS', 'ACO', 'ACTOR', 'AD', 'ADAC', 'ADS', 'ADULT', 'AE',
        'AEG', 'AERO', 'AETNA', 'AF', 'AFAMILYCOMPANY', 'AFL', 'AFRICA', 'AG',
        'AGAKHAN', 'AGENCY', 'AI', 'AIG', 'AIRBUS', 'AIRFORCE', 'AIRTEL',
        'AKDN', 'AL', 'ALFAROMEO', 'ALIBABA', 'ALIPAY', 'ALLFINANZ',
        'ALLSTATE', 'ALLY', 'ALSACE', 'ALSTOM', 'AM', 'AMAZON',
        'AMERICANEXPRESS', 'AMERICANFAMILY', 'AMEX', 'AMFAM', 'AMICA',
        'AMSTERDAM', 'ANALYTICS', 'ANDROID', 'ANQUAN', 'ANZ', 'AO', 'AOL',
        'APARTMENTS', 'APP', 'APPLE', 'AQ', 'AQUARELLE', 'AR', 'ARAB',
        'ARAMCO', 'ARCHI', 'ARMY', 'ARPA', 'ART', 'ARTE', 'AS', 'ASDA', 'ASIA',
        'ASSOCIATES', 'AT', 'ATHLETA', 'ATTORNEY', 'AU', 'AUCTION', 'AUDI',
        'AUDIBLE', 'AUDIO', 'AUSPOST', 'AUTHOR', 'AUTO', 'AUTOS', 'AVIANCA',
        'AW', 'AWS', 'AX', 'AXA', 'AZ', 'AZURE', 'BA', 'BABY', 'BAIDU',
        'BANAMEX', 'BANANAREPUBLIC', 'BAND', 'BANK', 'BAR', 'BARCELONA',
        'BARCLAYCARD', 'BARCLAYS', 'BAREFOOT', 'BARGAINS', 'BASEBALL',
        'BASKETBALL', 'BAUHAUS', 'BAYERN', 'BB', 'BBC', 'BBT', 'BBVA', 'BCG',
        'BCN', 'BD', 'BE', 'BEATS', 'BEAUTY', 'BEER', 'BENTLEY', 'BERLIN',
        'BEST', 'BESTBUY', 'BET', 'BF', 'BG', 'BH', 'BHARTI', 'BI', 'BIBLE',
        'BID', 'BIKE', 'BING', 'BINGO', 'BIO', 'BIZ', 'BJ', 'BLACK',
        'BLACKFRIDAY', 'BLOCKBUSTER', 'BLOG', 'BLOOMBERG', 'BLUE', 'BM', 'BMS',
        'BMW', 'BN', 'BNPPARIBAS', 'BO', 'BOATS', 'BOEHRINGER', 'BOFA', 'BOM',
        'BOND', 'BOO', 'BOOK', 'BOOKING', 'BOSCH', 'BOSTIK', 'BOSTON', 'BOT',
        'BOUTIQUE', 'BOX', 'BR', 'BRADESCO', 'BRIDGESTONE', 'BROADWAY',
        'BROKER', 'BROTHER', 'BRUSSELS', 'BS', 'BT', 'BUDAPEST', 'BUGATTI',
        'BUILD', 'BUILDERS', 'BUSINESS', 'BUY', 'BUZZ', 'BV', 'BW', 'BY', 'BZ',
        'BZH', 'CA', 'CAB', 'CAFE', 'CAL', 'CALL', 'CALVINKLEIN', 'CAM',
        'CAMERA', 'CAMP', 'CANCERRESEARCH', 'CANON', 'CAPETOWN', 'CAPITAL',
        'CAPITALONE', 'CAR', 'CARAVAN', 'CARDS', 'CARE', 'CAREER', 'CAREERS',
        'CARS', 'CASA', 'CASE', 'CASH', 'CASINO', 'CAT', 'CATERING',
        'CATHOLIC', 'CBA', 'CBN', 'CBRE', 'CBS', 'CC', 'CD', 'CENTER', 'CEO',
        'CERN', 'CF', 'CFA', 'CFD', 'CG', 'CH', 'CHANEL', 'CHANNEL', 'CHARITY',
        'CHASE', 'CHAT', 'CHEAP', 'CHINTAI', 'CHRISTMAS', 'CHROME', 'CHURCH',
        'CI', 'CIPRIANI', 'CIRCLE', 'CISCO', 'CITADEL', 'CITI', 'CITIC',
        'CITY', 'CITYEATS', 'CK', 'CL', 'CLAIMS', 'CLEANING', 'CLICK',
        'CLINIC', 'CLINIQUE', 'CLOTHING', 'CLOUD', 'CLUB', 'CLUBMED', 'CM',
        'CN', 'CO', 'COACH', 'CODES', 'COFFEE', 'COLLEGE', 'COLOGNE', 'COM',
        'COMCAST', 'COMMBANK', 'COMMUNITY', 'COMPANY', 'COMPARE', 'COMPUTER',
        'COMSEC', 'CONDOS', 'CONSTRUCTION', 'CONSULTING', 'CONTACT',
        'CONTRACTORS', 'COOKING', 'COOKINGCHANNEL', 'COOL', 'COOP', 'CORSICA',
        'COUNTRY', 'COUPON', 'COUPONS', 'COURSES', 'CPA', 'CR', 'CREDIT',
        'CREDITCARD', 'CREDITUNION', 'CRICKET', 'CROWN', 'CRS', 'CRUISE',
        'CRUISES', 'CSC', 'CU', 'CUISINELLA', 'CV', 'CW', 'CX', 'CY', 'CYMRU',
        'CYOU', 'CZ', 'DABUR', 'DAD', 'DANCE', 'DATA', 'DATE', 'DATING',
        'DATSUN', 'DAY', 'DCLK', 'DDS', 'DE', 'DEAL', 'DEALER', 'DEALS',
        'DEGREE', 'DELIVERY', 'DELL', 'DELOITTE', 'DELTA', 'DEMOCRAT',
        'DENTAL', 'DENTIST', 'DESI', 'DESIGN', 'DEV', 'DHL', 'DIAMONDS',
        'DIET', 'DIGITAL', 'DIRECT', 'DIRECTORY', 'DISCOUNT', 'DISCOVER',
        'DISH', 'DIY', 'DJ', 'DK', 'DM', 'DNP', 'DO', 'DOCS', 'DOCTOR', 'DOG',
        'DOMAINS', 'DOT', 'DOWNLOAD', 'DRIVE', 'DTV', 'DUBAI', 'DUCK',
        'DUNLOP', 'DUPONT', 'DURBAN', 'DVAG', 'DVR', 'DZ', 'EARTH', 'EAT',
        'EC', 'ECO', 'EDEKA', 'EDU', 'EDUCATION', 'EE', 'EG', 'EMAIL',
        'EMERCK', 'ENERGY', 'ENGINEER', 'ENGINEERING', 'ENTERPRISES', 'EPSON',
        'EQUIPMENT', 'ER', 'ERICSSON', 'ERNI', 'ES', 'ESQ', 'ESTATE', 'ET',
        'ETISALAT', 'EU', 'EUROVISION', 'EUS', 'EVENTS', 'EXCHANGE', 'EXPERT',
        'EXPOSED', 'EXPRESS', 'EXTRASPACE', 'FAGE', 'FAIL', 'FAIRWINDS',
        'FAITH', 'FAMILY', 'FAN', 'FANS', 'FARM', 'FARMERS', 'FASHION', 'FAST',
        'FEDEX', 'FEEDBACK', 'FERRARI', 'FERRERO', 'FI', 'FIAT', 'FIDELITY',
        'FIDO', 'FILM', 'FINAL', 'FINANCE', 'FINANCIAL', 'FIRE', 'FIRESTONE',
        'FIRMDALE', 'FISH', 'FISHING', 'FIT', 'FITNESS', 'FJ', 'FK', 'FLICKR',
        'FLIGHTS', 'FLIR', 'FLORIST', 'FLOWERS', 'FLY', 'FM', 'FO', 'FOO',
        'FOOD', 'FOODNETWORK', 'FOOTBALL', 'FORD', 'FOREX', 'FORSALE', 'FORUM',
        'FOUNDATION', 'FOX', 'FR', 'FREE', 'FRESENIUS', 'FRL', 'FROGANS',
        'FRONTDOOR', 'FRONTIER', 'FTR', 'FUJITSU', 'FUJIXEROX', 'FUN', 'FUND',
        'FURNITURE', 'FUTBOL', 'FYI', 'GA', 'GAL', 'GALLERY', 'GALLO',
        'GALLUP', 'GAME', 'GAMES', 'GAP', 'GARDEN', 'GAY', 'GB', 'GBIZ', 'GD',
        'GDN', 'GE', 'GEA', 'GENT', 'GENTING', 'GEORGE', 'GF', 'GG', 'GGEE',
        'GH', 'GI', 'GIFT', 'GIFTS', 'GIVES', 'GIVING', 'GL', 'GLADE', 'GLASS',
        'GLE', 'GLOBAL', 'GLOBO', 'GM', 'GMAIL', 'GMBH', 'GMO', 'GMX', 'GN',
        'GODADDY', 'GOLD', 'GOLDPOINT', 'GOLF', 'GOO', 'GOODYEAR', 'GOOG',
        'GOOGLE', 'GOP', 'GOT', 'GOV', 'GP', 'GQ', 'GR', 'GRAINGER',
        'GRAPHICS', 'GRATIS', 'GREEN', 'GRIPE', 'GROCERY', 'GROUP', 'GS', 'GT',
        'GU', 'GUARDIAN', 'GUCCI', 'GUGE', 'GUIDE', 'GUITARS', 'GURU', 'GW',
        'GY', 'HAIR', 'HAMBURG', 'HANGOUT', 'HAUS', 'HBO', 'HDFC', 'HDFCBANK',
        'HEALTH', 'HEALTHCARE', 'HELP', 'HELSINKI', 'HERE', 'HERMES', 'HGTV',
        'HIPHOP', 'HISAMITSU', 'HITACHI', 'HIV', 'HK', 'HKT', 'HM', 'HN',
        'HOCKEY', 'HOLDINGS', 'HOLIDAY', 'HOMEDEPOT', 'HOMEGOODS', 'HOMES',
        'HOMESENSE', 'HONDA', 'HORSE', 'HOSPITAL', 'HOST', 'HOSTING', 'HOT',
        'HOTELES', 'HOTELS', 'HOTMAIL', 'HOUSE', 'HOW', 'HR', 'HSBC', 'HT',
        'HU', 'HUGHES', 'HYATT', 'HYUNDAI', 'IBM', 'ICBC', 'ICE', 'ICU', 'ID',
        'IE', 'IEEE', 'IFM', 'IKANO', 'IL', 'IM', 'IMAMAT', 'IMDB', 'IMMO',
        'IMMOBILIEN', 'IN', 'INC', 'INDUSTRIES', 'INFINITI', 'INFO', 'ING',
        'INK', 'INSTITUTE', 'INSURANCE', 'INSURE', 'INT', 'INTERNATIONAL',
        'INTUIT', 'INVESTMENTS', 'IO', 'IPIRANGA', 'IQ', 'IR', 'IRISH', 'IS',
        'ISMAILI', 'IST', 'ISTANBUL', 'IT', 'ITAU', 'ITV', 'IVECO', 'JAGUAR',
        'JAVA', 'JCB', 'JE', 'JEEP', 'JETZT', 'JEWELRY', 'JIO', 'JLL', 'JM',
        'JMP', 'JNJ', 'JO', 'JOBS', 'JOBURG', 'JOT', 'JOY', 'JP', 'JPMORGAN',
        'JPRS', 'JUEGOS', 'JUNIPER', 'KAUFEN', 'KDDI', 'KE', 'KERRYHOTELS',
        'KERRYLOGISTICS', 'KERRYPROPERTIES', 'KFH', 'KG', 'KH', 'KI', 'KIA',
        'KIM', 'KINDER', 'KINDLE', 'KITCHEN', 'KIWI', 'KM', 'KN', 'KOELN',
        'KOMATSU', 'KOSHER', 'KP', 'KPMG', 'KPN', 'KR', 'KRD', 'KRED',
        'KUOKGROUP', 'KW', 'KY', 'KYOTO', 'KZ', 'LA', 'LACAIXA', 'LAMBORGHINI',
        'LAMER', 'LANCASTER', 'LANCIA', 'LAND', 'LANDROVER', 'LANXESS',
        'LASALLE', 'LAT', 'LATINO', 'LATROBE', 'LAW', 'LAWYER', 'LB', 'LC',
        'LDS', 'LEASE', 'LECLERC', 'LEFRAK', 'LEGAL', 'LEGO', 'LEXUS', 'LGBT',
        'LI', 'LIDL', 'LIFE', 'LIFEINSURANCE', 'LIFESTYLE', 'LIGHTING', 'LIKE',
        'LILLY', 'LIMITED', 'LIMO', 'LINCOLN', 'LINDE', 'LINK', 'LIPSY',
        'LIVE', 'LIVING', 'LIXIL', 'LK', 'LLC', 'LLP', 'LOAN', 'LOANS',
        'LOCKER', 'LOCUS', 'LOFT', 'LOL', 'LONDON', 'LOTTE', 'LOTTO', 'LOVE',
        'LPL', 'LPLFINANCIAL', 'LR', 'LS', 'LT', 'LTD', 'LTDA', 'LU',
        'LUNDBECK', 'LUXE', 'LUXURY', 'LV', 'LY', 'MA', 'MACYS', 'MADRID',
        'MAIF', 'MAISON', 'MAKEUP', 'MAN', 'MANAGEMENT', 'MANGO', 'MAP',
        'MARKET', 'MARKETING', 'MARKETS', 'MARRIOTT', 'MARSHALLS', 'MASERATI',
        'MATTEL', 'MBA', 'MC', 'MCKINSEY', 'MD', 'ME', 'MED', 'MEDIA', 'MEET',
        'MELBOURNE', 'MEME', 'MEMORIAL', 'MEN', 'MENU', 'MERCKMSD', 'MG', 'MH',
        'MIAMI', 'MICROSOFT', 'MIL', 'MINI', 'MINT', 'MIT', 'MITSUBISHI', 'MK',
        'ML', 'MLB', 'MLS', 'MM', 'MMA', 'MN', 'MO', 'MOBI', 'MOBILE', 'MODA',
        'MOE', 'MOI', 'MOM', 'MONASH', 'MONEY', 'MONSTER', 'MORMON',
        'MORTGAGE', 'MOSCOW', 'MOTO', 'MOTORCYCLES', 'MOV', 'MOVIE', 'MP',
        'MQ', 'MR', 'MS', 'MSD', 'MT', 'MTN', 'MTR', 'MU', 'MUSEUM', 'MUTUAL',
        'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NAB', 'NAGOYA', 'NAME',
        'NATIONWIDE', 'NATURA', 'NAVY', 'NBA', 'NC', 'NE', 'NEC', 'NET',
        'NETBANK', 'NETFLIX', 'NETWORK', 'NEUSTAR', 'NEW', 'NEWS', 'NEXT',
        'NEXTDIRECT', 'NEXUS', 'NF', 'NFL', 'NG', 'NGO', 'NHK', 'NI', 'NICO',
        'NIKE', 'NIKON', 'NINJA', 'NISSAN', 'NISSAY', 'NL', 'NO', 'NOKIA',
        'NORTHWESTERNMUTUAL', 'NORTON', 'NOW', 'NOWRUZ', 'NOWTV', 'NP', 'NR',
        'NRA', 'NRW', 'NTT', 'NU', 'NYC', 'NZ', 'OBI', 'OBSERVER', 'OFF',
        'OFFICE', 'OKINAWA', 'OLAYAN', 'OLAYANGROUP', 'OLDNAVY', 'OLLO', 'OM',
        'OMEGA', 'ONE', 'ONG', 'ONL', 'ONLINE', 'ONYOURSIDE', 'OOO', 'OPEN',
        'ORACLE', 'ORANGE', 'ORG', 'ORGANIC', 'ORIGINS', 'OSAKA', 'OTSUKA',
        'OTT', 'OVH', 'PA', 'PAGE', 'PANASONIC', 'PARIS', 'PARS', 'PARTNERS',
        'PARTS', 'PARTY', 'PASSAGENS', 'PAY', 'PCCW', 'PE', 'PET', 'PF',
        'PFIZER', 'PG', 'PH', 'PHARMACY', 'PHD', 'PHILIPS', 'PHONE', 'PHOTO',
        'PHOTOGRAPHY', 'PHOTOS', 'PHYSIO', 'PICS', 'PICTET', 'PICTURES', 'PID',
        'PIN', 'PING', 'PINK', 'PIONEER', 'PIZZA', 'PK', 'PL', 'PLACE', 'PLAY',
        'PLAYSTATION', 'PLUMBING', 'PLUS', 'PM', 'PN', 'PNC', 'POHL', 'POKER',
        'POLITIE', 'PORN', 'POST', 'PR', 'PRAMERICA', 'PRAXI', 'PRESS',
        'PRIME', 'PRO', 'PROD', 'PRODUCTIONS', 'PROF', 'PROGRESSIVE', 'PROMO',
        'PROPERTIES', 'PROPERTY', 'PROTECTION', 'PRU', 'PRUDENTIAL', 'PS',
        'PT', 'PUB', 'PW', 'PWC', 'PY', 'QA', 'QPON', 'QUEBEC', 'QUEST', 'QVC',
        'RACING', 'RADIO', 'RAID', 'RE', 'READ', 'REALESTATE', 'REALTOR',
        'REALTY', 'RECIPES', 'RED', 'REDSTONE', 'REDUMBRELLA', 'REHAB',
        'REISE', 'REISEN', 'REIT', 'RELIANCE', 'REN', 'RENT', 'RENTALS',
        'REPAIR', 'REPORT', 'REPUBLICAN', 'REST', 'RESTAURANT', 'REVIEW',
        'REVIEWS', 'REXROTH', 'RICH', 'RICHARDLI', 'RICOH', 'RIL', 'RIO',
        'RIP', 'RMIT', 'RO', 'ROCHER', 'ROCKS', 'RODEO', 'ROGERS', 'ROOM',
        'RS', 'RSVP', 'RU', 'RUGBY', 'RUHR', 'RUN', 'RW', 'RWE', 'RYUKYU',
        'SA', 'SAARLAND', 'SAFE', 'SAFETY', 'SAKURA', 'SALE', 'SALON',
        'SAMSCLUB', 'SAMSUNG', 'SANDVIK', 'SANDVIKCOROMANT', 'SANOFI', 'SAP',
        'SARL', 'SAS', 'SAVE', 'SAXO', 'SB', 'SBI', 'SBS', 'SC', 'SCA', 'SCB',
        'SCHAEFFLER', 'SCHMIDT', 'SCHOLARSHIPS', 'SCHOOL', 'SCHULE', 'SCHWARZ',
        'SCIENCE', 'SCJOHNSON', 'SCOT', 'SD', 'SE', 'SEARCH', 'SEAT', 'SECURE',
        'SECURITY', 'SEEK', 'SELECT', 'SENER', 'SERVICES', 'SES', 'SEVEN',
        'SEW', 'SEX', 'SEXY', 'SFR', 'SG', 'SH', 'SHANGRILA', 'SHARP', 'SHAW',
        'SHELL', 'SHIA', 'SHIKSHA', 'SHOES', 'SHOP', 'SHOPPING', 'SHOUJI',
        'SHOW', 'SHOWTIME', 'SI', 'SILK', 'SINA', 'SINGLES', 'SITE', 'SJ',
        'SK', 'SKI', 'SKIN', 'SKY', 'SKYPE', 'SL', 'SLING', 'SM', 'SMART',
        'SMILE', 'SN', 'SNCF', 'SO', 'SOCCER', 'SOCIAL', 'SOFTBANK',
        'SOFTWARE', 'SOHU', 'SOLAR', 'SOLUTIONS', 'SONG', 'SONY', 'SOY', 'SPA',
        'SPACE', 'SPORT', 'SPOT', 'SPREADBETTING', 'SR', 'SRL', 'SS', 'ST',
        'STADA', 'STAPLES', 'STAR', 'STATEBANK', 'STATEFARM', 'STC',
        'STCGROUP', 'STOCKHOLM', 'STORAGE', 'STORE', 'STREAM', 'STUDIO',
        'STUDY', 'STYLE', 'SU', 'SUCKS', 'SUPPLIES', 'SUPPLY', 'SUPPORT',
        'SURF', 'SURGERY', 'SUZUKI', 'SV', 'SWATCH', 'SWIFTCOVER', 'SWISS',
        'SX', 'SY', 'SYDNEY', 'SYSTEMS', 'SZ', 'TAB', 'TAIPEI', 'TALK',
        'TAOBAO', 'TARGET', 'TATAMOTORS', 'TATAR', 'TATTOO', 'TAX', 'TAXI',
        'TC', 'TCI', 'TD', 'TDK', 'TEAM', 'TECH', 'TECHNOLOGY', 'TEL',
        'TEMASEK', 'TENNIS', 'TEVA', 'TF', 'TG', 'TH', 'THD', 'THEATER',
        'THEATRE', 'TIAA', 'TICKETS', 'TIENDA', 'TIFFANY', 'TIPS', 'TIRES',
        'TIROL', 'TJ', 'TJMAXX', 'TJX', 'TK', 'TKMAXX', 'TL', 'TM', 'TMALL',
        'TN', 'TO', 'TODAY', 'TOKYO', 'TOOLS', 'TOP', 'TORAY', 'TOSHIBA',
        'TOTAL', 'TOURS', 'TOWN', 'TOYOTA', 'TOYS', 'TR', 'TRADE', 'TRADING',
        'TRAINING', 'TRAVEL', 'TRAVELCHANNEL', 'TRAVELERS',
        'TRAVELERSINSURANCE', 'TRUST', 'TRV', 'TT', 'TUBE', 'TUI', 'TUNES',
        'TUSHU', 'TV', 'TVS', 'TW', 'TZ', 'UA', 'UBANK', 'UBS', 'UG', 'UK',
        'UNICOM', 'UNIVERSITY', 'UNO', 'UOL', 'UPS', 'US', 'UY', 'UZ', 'VA',
        'VACATIONS', 'VANA', 'VANGUARD', 'VC', 'VE', 'VEGAS', 'VENTURES',
        'VERISIGN', 'VERSICHERUNG', 'VET', 'VG', 'VI', 'VIAJES', 'VIDEO',
        'VIG', 'VIKING', 'VILLAS', 'VIN', 'VIP', 'VIRGIN', 'VISA', 'VISION',
        'VIVA', 'VIVO', 'VLAANDEREN', 'VN', 'VODKA', 'VOLKSWAGEN', 'VOLVO',
        'VOTE', 'VOTING', 'VOTO', 'VOYAGE', 'VU', 'VUELOS', 'WALES', 'WALMART',
        'WALTER', 'WANG', 'WANGGOU', 'WATCH', 'WATCHES', 'WEATHER',
        'WEATHERCHANNEL', 'WEBCAM', 'WEBER', 'WEBSITE', 'WED', 'WEDDING',
        'WEIBO', 'WEIR', 'WF', 'WHOSWHO', 'WIEN', 'WIKI', 'WILLIAMHILL', 'WIN',
        'WINDOWS', 'WINE', 'WINNERS', 'WME', 'WOLTERSKLUWER', 'WOODSIDE',
        'WORK', 'WORKS', 'WORLD', 'WOW', 'WS', 'WTC', 'WTF', 'XBOX', 'XEROX',
        'XFINITY', 'XIHUAN', 'XIN', 'XN--11B4C3D', 'XN--1CK2E1B',
        'XN--1QQW23A', 'XN--2SCRJ9C', 'XN--30RR7Y', 'XN--3BST00M',
        'XN--3DS443G', 'XN--3E0B707E', 'XN--3HCRJ9C', 'XN--3OQ18VL8PN36A',
        'XN--3PXU8K', 'XN--42C2D9A', 'XN--45BR5CYL', 'XN--45BRJ9C',
        'XN--45Q11C', 'XN--4DBRK0CE', 'XN--4GBRIM', 'XN--54B7FTA0CC',
        'XN--55QW42G', 'XN--55QX5D', 'XN--5SU34J936BGSG', 'XN--5TZM5G',
        'XN--6FRZ82G', 'XN--6QQ986B3XL', 'XN--80ADXHKS', 'XN--80AO21A',
        'XN--80AQECDR1A', 'XN--80ASEHDB', 'XN--80ASWG', 'XN--8Y0A063A',
        'XN--90A3AC', 'XN--90AE', 'XN--90AIS', 'XN--9DBQ2A', 'XN--9ET52U',
        'XN--9KRT00A', 'XN--B4W605FERD', 'XN--BCK1B9A5DRE4C', 'XN--C1AVG',
        'XN--C2BR7G', 'XN--CCK2B3B', 'XN--CCKWCXETD', 'XN--CG4BKI',
        'XN--CLCHC0EA0B2G2A9GCD', 'XN--CZR694B', 'XN--CZRS0T', 'XN--CZRU2D',
        'XN--D1ACJ3B', 'XN--D1ALF', 'XN--E1A4C', 'XN--ECKVDTC9D',
        'XN--EFVY88H', 'XN--FCT429K', 'XN--FHBEI', 'XN--FIQ228C5HS',
        'XN--FIQ64B', 'XN--FIQS8S', 'XN--FIQZ9S', 'XN--FJQ720A', 'XN--FLW351E',
        'XN--FPCRJ9C3D', 'XN--FZC2C9E2C', 'XN--FZYS8D69UVGM', 'XN--G2XX48C',
        'XN--GCKR3F0F', 'XN--GECRJ9C', 'XN--GK3AT1E', 'XN--H2BREG3EVE',
        'XN--H2BRJ9C', 'XN--H2BRJ9C8C', 'XN--HXT814E', 'XN--I1B6B1A6A2E',
        'XN--IMR513N', 'XN--IO0A7I', 'XN--J1AEF', 'XN--J1AMH', 'XN--J6W193G',
        'XN--JLQ480N2RG', 'XN--JLQ61U9W7B', 'XN--JVR189M', 'XN--KCRX77D1X4A',
        'XN--KPRW13D', 'XN--KPRY57D', 'XN--KPUT3I', 'XN--L1ACC',
        'XN--LGBBAT1AD8J', 'XN--MGB9AWBF', 'XN--MGBA3A3EJT', 'XN--MGBA3A4F16A',
        'XN--MGBA7C0BBN0A', 'XN--MGBAAKC7DVF', 'XN--MGBAAM7A8H',
        'XN--MGBAB2BD', 'XN--MGBAH1A3HJKRD', 'XN--MGBAI9AZGQP6J',
        'XN--MGBAYH7GPA', 'XN--MGBBH1A', 'XN--MGBBH1A71E', 'XN--MGBC0A9AZCG',
        'XN--MGBCA7DZDO', 'XN--MGBCPQ6GPA1A', 'XN--MGBERP4A5D4AR',
        'XN--MGBGU82A', 'XN--MGBI4ECEXP', 'XN--MGBPL2FH', 'XN--MGBT3DHD',
        'XN--MGBTX2B', 'XN--MGBX4CD0AB', 'XN--MIX891F', 'XN--MK1BU44C',
        'XN--MXTQ1M', 'XN--NGBC5AZD', 'XN--NGBE9E0A', 'XN--NGBRX', 'XN--NODE',
        'XN--NQV7F', 'XN--NQV7FS00EMA', 'XN--NYQY26A', 'XN--O3CW4H',
        'XN--OGBPF8FL', 'XN--OTU796D', 'XN--P1ACF', 'XN--P1AI', 'XN--PGBS0DH',
        'XN--PSSY2U', 'XN--Q7CE6A', 'XN--Q9JYB4C', 'XN--QCKA1PMC', 'XN--QXA6A',
        'XN--QXAM', 'XN--RHQV96G', 'XN--ROVU88B', 'XN--RVC1E0AM3E',
        'XN--S9BRJ9C', 'XN--SES554G', 'XN--T60B56A', 'XN--TCKWE',
        'XN--TIQ49XQYJ', 'XN--UNUP4Y', 'XN--VERMGENSBERATER-CTB',
        'XN--VERMGENSBERATUNG-PWB', 'XN--VHQUV', 'XN--VUQ861B',
        'XN--W4R85EL8FHU5DNRA', 'XN--W4RS40L', 'XN--WGBH1C', 'XN--WGBL6A',
        'XN--XHQ521B', 'XN--XKC2AL3HYE2A', 'XN--XKC2DL3A5EE0H', 'XN--Y9A3AQ',
        'XN--YFRO4I67O', 'XN--YGBI2AMMX', 'XN--ZFR164B', 'XXX', 'XYZ',
        'YACHTS', 'YAHOO', 'YAMAXUN', 'YANDEX', 'YE', 'YODOBASHI', 'YOGA',
        'YOKOHAMA', 'YOU', 'YOUTUBE', 'YT', 'YUN', 'ZA', 'ZAPPOS', 'ZARA',
        'ZERO', 'ZIP', 'ZM', 'ZONE', 'ZUERICH', 'ZW',
    ];

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        return in_array(mb_strtoupper((string) $input), self::TLD_LIST);
    }
}
validation/library/Rules/HexRgbColor.php000064400000001220147361033760014330 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates weather the input is a hex RGB color or not.
 *
 * @author Davide Pastore <pasdavide@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class HexRgbColor extends AbstractEnvelope
{
    public function __construct()
    {
        parent::__construct(new Regex('/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i'));
    }
}
validation/library/Rules/Lowercase.php000064400000001623147361033760014105 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function mb_strtolower;

/**
 * Validates whether the characters in the input are lowercase.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class Lowercase extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return $input === mb_strtolower($input);
    }
}
validation/library/Rules/LeapYear.php000064400000002302147361033760013656 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use DateTimeInterface;

use function date;
use function is_numeric;
use function is_scalar;
use function sprintf;
use function strtotime;

/**
 * Validates if a year is leap.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jayson Reis <santosdosreis@gmail.com>
 */
final class LeapYear extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_numeric($input)) {
            $date = strtotime(sprintf('%d-02-29', (int) $input));

            return (bool) date('L', (int) $date);
        }

        if (is_scalar($input)) {
            return $this->validate((int) date('Y', (int) strtotime((string) $input)));
        }

        if ($input instanceof DateTimeInterface) {
            return $this->validate($input->format('Y'));
        }

        return false;
    }
}
validation/library/Rules/Instance.php000064400000001764147361033760013733 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates if the input is an instance of the given class or interface.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Instance extends AbstractRule
{
    /**
     * @var string
     */
    private $instanceName;

    /**
     * Initializes the rule with the expected instance name.
     */
    public function __construct(string $instanceName)
    {
        $this->instanceName = $instanceName;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $input instanceof $this->instanceName;
    }
}
validation/library/Rules/NullType.php000064400000001235147361033760013734 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_null;

/**
 * Validates whether the input is null.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NullType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_null($input);
    }
}
validation/library/Rules/Nip.php000064400000002570147361033760012711 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_map;
use function is_scalar;
use function preg_match;
use function str_split;

/**
 * Validates whether the input is a Polish VAT identification number (NIP).
 *
 * @see https://en.wikipedia.org/wiki/VAT_identification_number
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Tomasz Regdos <tomek@regdos.com>
 */
final class Nip extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        if (!preg_match('/^\d{10}$/', (string) $input)) {
            return false;
        }

        $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
        $digits = array_map('intval', str_split((string) $input));

        $targetControlNumber = $digits[9];
        $calculateControlNumber = 0;

        for ($i = 0; $i < 9; ++$i) {
            $calculateControlNumber += $digits[$i] * $weights[$i];
        }

        $calculateControlNumber = $calculateControlNumber % 11;

        return $targetControlNumber == $calculateControlNumber;
    }
}
validation/library/Rules/StringVal.php000064400000001432147361033760014070 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_object;
use function is_scalar;
use function method_exists;

/**
 * Validates whether the input can be used as a string.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StringVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_scalar($input) || (is_object($input) && method_exists($input, '__toString'));
    }
}
validation/library/Rules/Not.php000064400000005170147361033760012722 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;

use function array_shift;
use function count;
use function current;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Caio César Tavares <caiotava@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Not extends AbstractRule
{
    /**
     * @var Validatable
     */
    private $rule;

    public function __construct(Validatable $rule)
    {
        $this->rule = $this->extractNegatedRule($rule);
    }

    public function getNegatedRule(): Validatable
    {
        return $this->rule;
    }

    public function setName(string $name): Validatable
    {
        $this->rule->setName($name);

        return parent::setName($name);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $this->rule->validate($input) === false;
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if ($this->validate($input)) {
            return;
        }

        $rule = $this->rule;
        if ($rule instanceof AllOf) {
            $rule = $this->absorbAllOf($rule, $input);
        }

        $exception = $rule->reportError($input);
        $exception->updateMode(ValidationException::MODE_NEGATIVE);

        throw $exception;
    }

    /**
     * @param mixed $input
     */
    private function absorbAllOf(AllOf $rule, $input): Validatable
    {
        $rules = $rule->getRules();
        while (($current = array_shift($rules))) {
            $rule = $current;
            if (!$rule instanceof AllOf) {
                continue;
            }

            if (!$rule->validate($input)) {
                continue;
            }

            $rules = $rule->getRules();
        }

        return $rule;
    }

    private function extractNegatedRule(Validatable $rule): Validatable
    {
        if ($rule instanceof self && $rule->getNegatedRule() instanceof self) {
            return $this->extractNegatedRule($rule->getNegatedRule()->getNegatedRule());
        }

        if (!$rule instanceof AllOf) {
            return $rule;
        }

        $rules = $rule->getRules();
        if (count($rules) === 1) {
            return $this->extractNegatedRule(current($rules));
        }

        return $rule;
    }
}
validation/library/Rules/Imei.php000064400000002265147361033760013047 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function mb_strlen;
use function preg_replace;

/**
 * Validates is the input is a valid IMEI.
 *
 * @author Alexander Gorshkov <mazanax@yandex.ru>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Diego Oliveira <contato@diegoholiveira.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Imei extends AbstractRule
{
    private const IMEI_SIZE = 15;

    /**
     * @see https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
     *
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        $numbers = (string) preg_replace('/\D/', '', (string) $input);
        if (mb_strlen($numbers) != self::IMEI_SIZE) {
            return false;
        }

        return (new Luhn())->validate($numbers);
    }
}
validation/library/Rules/Bsn.php000064400000002106147361033760012700 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_digit;
use function mb_strlen;

/**
 * Validates a Dutch citizen service number (BSN).
 *
 * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ronald Drenth <ronalddrenth@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Bsn extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!ctype_digit($input)) {
            return false;
        }

        if (mb_strlen($input) !== 9) {
            return false;
        }

        $sum = -1 * $input[8];
        for ($i = 9; $i > 1; --$i) {
            $sum += $i * $input[9 - $i];
        }

        return $sum !== 0 && $sum % 11 === 0;
    }
}
validation/library/Rules/Infinite.php000064400000001341147361033760013723 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_infinite;
use function is_numeric;

/**
 * Validates if the input is an infinite number
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Infinite extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_numeric($input) && is_infinite((float) $input);
    }
}
validation/library/Rules/AlwaysValid.php000064400000001261147361033760014377 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates any input as valid.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class AlwaysValid extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return true;
    }
}
validation/library/Rules/CreditCard.php000064400000005050147361033760014163 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_keys;
use function implode;
use function is_scalar;
use function preg_match;
use function preg_replace;
use function sprintf;

/**
 * Validates whether the input is a credit card number.
 *
 * @author Alexander Gorshkov <mazanax@yandex.ru>
 * @author Andy Snell <andysnell@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CreditCard extends AbstractRule
{
    public const ANY = 'Any';

    public const AMERICAN_EXPRESS = 'American Express';

    public const DINERS_CLUB = 'Diners Club';

    public const DISCOVER = 'Discover';

    public const JCB = 'JCB';

    public const MASTERCARD = 'MasterCard';

    public const VISA = 'Visa';

    private const BRAND_REGEX_LIST = [
        self::ANY => '/^[0-9]+$/',
        self::AMERICAN_EXPRESS => '/^3[47]\d{13}$/',
        self::DINERS_CLUB => '/^3(?:0[0-5]|[68]\d)\d{11}$/',
        self::DISCOVER => '/^6(?:011|5\d{2})\d{12}$/',
        self::JCB => '/^(?:2131|1800|35\d{3})\d{11}$/',
        self::MASTERCARD => '/(5[1-5]|2[2-7])\d{14}$/',
        self::VISA => '/^4\d{12}(?:\d{3})?$/',
    ];

    /**
     * @var string
     */
    private $brand;

    /**
     * Initializes the rule.
     *
     * @throws ComponentException
     */
    public function __construct(string $brand = self::ANY)
    {
        if (!isset(self::BRAND_REGEX_LIST[$brand])) {
            throw new ComponentException(
                sprintf(
                    '"%s" is not a valid credit card brand (Available: %s)',
                    $brand,
                    implode(', ', array_keys(self::BRAND_REGEX_LIST))
                )
            );
        }

        $this->brand = $brand;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        $input = (string) preg_replace('/[ .-]/', '', (string) $input);
        if (!(new Luhn())->validate($input)) {
            return false;
        }

        return preg_match(self::BRAND_REGEX_LIST[$this->brand], $input) > 0;
    }
}
validation/library/Rules/Alpha.php000064400000001412147361033760013202 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_alpha;

/**
 * Validates whether the input contains only alphabetic characters.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Alpha extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_alpha($input);
    }
}
validation/library/Rules/PrimeNumber.php000064400000002260147361033760014404 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ceil;
use function is_numeric;
use function sqrt;

/**
 * Validates whether the input is a prime number.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Camilo Teixeira de Melo <kmilotxm@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 */
final class PrimeNumber extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input) || $input <= 1) {
            return false;
        }

        if ($input != 2 && ($input % 2) == 0) {
            return false;
        }

        for ($i = 3; $i <= ceil(sqrt((float) $input)); $i += 2) {
            if ($input % $i == 0) {
                return false;
            }
        }

        return true;
    }
}
validation/library/Rules/AbstractFilterRule.php000064400000002745147361033760015730 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function implode;
use function is_scalar;
use function str_replace;
use function str_split;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
abstract class AbstractFilterRule extends AbstractRule
{
    /**
     * @var string
     */
    private $additionalChars;

    abstract protected function validateFilteredInput(string $input): bool;

    /**
     * Initializes the rule with a list of characters to be ignored by the validation.
     */
    public function __construct(string ...$additionalChars)
    {
        $this->additionalChars = implode($additionalChars);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        $stringInput = (string) $input;
        if ($stringInput === '') {
            return false;
        }

        $filteredInput = $this->filter($stringInput);

        return $filteredInput === '' || $this->validateFilteredInput($filteredInput);
    }

    private function filter(string $input): string
    {
        return str_replace(str_split($this->additionalChars), '', $input);
    }
}
validation/library/Rules/KeyNested.php000064400000007334147361033760014061 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use ArrayAccess;
use Respect\Validation\Exceptions\ComponentException;

use function array_key_exists;
use function array_shift;
use function explode;
use function is_array;
use function is_null;
use function is_object;
use function is_scalar;
use function property_exists;
use function rtrim;
use function sprintf;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ivan Zinovyev <vanyazin@gmail.com>
 */
final class KeyNested extends AbstractRelated
{
    /**
     * {@inheritDoc}
     */
    public function hasReference($input): bool
    {
        try {
            $this->getReferenceValue($input);
        } catch (ComponentException $cex) {
            return false;
        }

        return true;
    }

    /**
     * {@inheritDoc}
     */
    public function getReferenceValue($input)
    {
        if (is_scalar($input)) {
            $message = sprintf('Cannot select the %s in the given data', $this->getReference());
            throw new ComponentException($message);
        }

        $keys = $this->getReferencePieces();
        $value = $input;
        while (!is_null($key = array_shift($keys))) {
            $value = $this->getValue($value, $key);
        }

        return $value;
    }

    /**
     * @return string[]
     */
    private function getReferencePieces(): array
    {
        return explode('.', rtrim((string) $this->getReference(), '.'));
    }

    /**
     * @param mixed[] $array
     * @param mixed $key
     *
     * @return mixed
     */
    private function getValueFromArray(array $array, $key)
    {
        if (!array_key_exists($key, $array)) {
            $message = sprintf('Cannot select the key %s from the given array', $this->getReference());
            throw new ComponentException($message);
        }

        return $array[$key];
    }

    /**
     * @param mixed $key
     *
     * @return mixed
     */
    private function getValueFromArrayAccess(ArrayAccess $array, $key)
    {
        if (!$array->offsetExists($key)) {
            $message = sprintf('Cannot select the key %s from the given array', $this->getReference());
            throw new ComponentException($message);
        }

        return $array->offsetGet($key);
    }

    /**
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
     *
     *
     * @return mixed
     */
    private function getValueFromObject(object $object, string $property)
    {
        if (empty($property) || !property_exists($object, $property)) {
            $message = sprintf('Cannot select the property %s from the given object', $this->getReference());
            throw new ComponentException($message);
        }

        return $object->{$property};
    }

    /**
     * @param mixed $value
     * @param mixed $key
     *
     * @return mixed
     */
    private function getValue($value, $key)
    {
        if (is_array($value)) {
            return $this->getValueFromArray($value, $key);
        }

        if ($value instanceof ArrayAccess) {
            return $this->getValueFromArrayAccess($value, $key);
        }

        if (is_object($value)) {
            return $this->getValueFromObject($value, $key);
        }

        $message = sprintf('Cannot select the property %s from the given data', $this->getReference());
        throw new ComponentException($message);
    }
}
validation/library/Rules/In.php000064400000004203147361033760012524 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function in_array;
use function is_array;
use function mb_stripos;
use function mb_strpos;

/**
 * Validates if the input can be found in a defined array or string.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class In extends AbstractRule
{
    /**
     * @var mixed[]|mixed
     */
    private $haystack;

    /**
     * @var bool
     */
    private $compareIdentical;

    /**
     * Initializes the rule with the haystack and optionally compareIdentical flag.
     *
     * @param mixed[]|mixed $haystack
     */
    public function __construct($haystack, bool $compareIdentical = false)
    {
        $this->haystack = $haystack;
        $this->compareIdentical = $compareIdentical;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->compareIdentical) {
            return $this->validateIdentical($input);
        }

        return $this->validateEquals($input);
    }

    /**
     * @param mixed $input
     */
    private function validateEquals($input): bool
    {
        if (is_array($this->haystack)) {
            return in_array($input, $this->haystack);
        }

        if ($input === null || $input === '') {
            return $input == $this->haystack;
        }

        return mb_stripos($this->haystack, (string) $input) !== false;
    }

    /**
     * @param mixed $input
     */
    private function validateIdentical($input): bool
    {
        if (is_array($this->haystack)) {
            return in_array($input, $this->haystack, true);
        }

        if ($input === null || $input === '') {
            return $input === $this->haystack;
        }

        return mb_strpos($this->haystack, (string) $input) !== false;
    }
}
validation/library/Rules/NotBlank.php000064400000002241147361033760013666 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use stdClass;

use function array_filter;
use function is_array;
use function is_numeric;
use function is_string;
use function trim;

/**
 * Validates if the given input is not a blank value (null, zeros, empty strings or empty arrays, recursively).
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotBlank extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_numeric($input)) {
            return $input != 0;
        }

        if (is_string($input)) {
            $input = trim($input);
        }

        if ($input instanceof stdClass) {
            $input = (array) $input;
        }

        if (is_array($input)) {
            $input = array_filter($input, __METHOD__);
        }

        return !empty($input);
    }
}
validation/library/Rules/Number.php000064400000001436147361033760013413 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_nan;
use function is_numeric;

/**
 * Validates if the input is a number.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 * @author Vitaliy <reboot.m@gmail.com>
 */
final class Number extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        return !is_nan((float) $input);
    }
}
validation/library/Rules/NotOptional.php000064400000001456147361033760014433 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanValidateUndefined;

/**
 * Validates if the given input is not optional.
 *
 * By optional we consider null or an empty string ('').
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotOptional extends AbstractRule
{
    use CanValidateUndefined;

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return $this->isUndefined($input) === false;
    }
}
validation/library/Rules/Exists.php000064400000001430147361033760013434 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use SplFileInfo;

use function file_exists;
use function is_string;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Exists extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            $input = $input->getPathname();
        }

        return is_string($input) && file_exists($input);
    }
}
validation/library/Rules/Email.php000064400000003332147361033760013207 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;

use function class_exists;
use function filter_var;
use function is_string;

use const FILTER_VALIDATE_EMAIL;

/**
 * Validates an email address.
 *
 * @author Andrey Kolyshkin <a.kolyshkin@semrush.com>
 * @author Eduardo Gulias Davis <me@egulias.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class Email extends AbstractRule
{
    /**
     * @var EmailValidator|null
     */
    private $validator;

    /**
     * Initializes the rule assigning the EmailValidator instance.
     *
     * If the EmailValidator instance is not defined, tries to create one.
     */
    public function __construct(?EmailValidator $validator = null)
    {
        $this->validator = $validator ?: $this->createEmailValidator();
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        if ($this->validator !== null) {
            return $this->validator->isValid($input, new RFCValidation());
        }

        return (bool) filter_var($input, FILTER_VALIDATE_EMAIL);
    }

    private function createEmailValidator(): ?EmailValidator
    {
        if (class_exists(EmailValidator::class)) {
            return new EmailValidator();
        }

        return null;
    }
}
validation/library/Rules/Consonant.php000064400000001445147361033760014125 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function preg_match;

/**
 *  Validates if the input contains only consonants.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Consonant extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return preg_match('/^(\s|[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z])*$/', $input) > 0;
    }
}
validation/library/Rules/Sf.php000064400000005106147361033760012531 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\SfException;
use Respect\Validation\Exceptions\ValidationException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;

use function trim;

/**
 * Validate the input with a Symfony Validator (>=4.0 or >=3.0) Constraint.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Augusto Pascutti <augusto@phpsp.org.br>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Hugo Hamon <hugo.hamon@sensiolabs.com>
 */
final class Sf extends AbstractRule
{
    /**
     * @var Constraint
     */
    private $constraint;

    /**
     * @var ValidatorInterface
     */
    private $validator;

    /**
     * Initializes the rule with the Constraint and the Validator.
     *
     * In the the Validator is not defined, tries to create one.
     */
    public function __construct(Constraint $constraint, ?ValidatorInterface $validator = null)
    {
        $this->constraint = $constraint;
        $this->validator = $validator ?: Validation::createValidator();
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        /** @var ConstraintViolationList $violations */
        $violations = $this->validator->validate($input, $this->constraint);
        if ($violations->count() === 0) {
            return;
        }

        if ($violations->count() === 1) {
            throw $this->reportError($input, ['violations' => $violations[0]->getMessage()]);
        }

        throw $this->reportError($input, ['violations' => trim($violations->__toString())]);
    }

    /**
     * {@inheritDoc}
     */
    public function reportError($input, array $extraParams = []): ValidationException
    {
        $exception = parent::reportError($input, $extraParams);
        if (isset($extraParams['violations'])) {
            $exception->updateTemplate($extraParams['violations']);
        }

        return $exception;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        try {
            $this->assert($input);
        } catch (SfException $exception) {
            return false;
        }

        return true;
    }
}
validation/library/Rules/AbstractAge.php000064400000004360147361033760014342 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanValidateDateTime;

use function date;
use function date_parse_from_format;
use function is_scalar;
use function strtotime;
use function vsprintf;

/**
 * Abstract class to validate ages.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
abstract class AbstractAge extends AbstractRule
{
    use CanValidateDateTime;

    /**
     * @var int
     */
    private $age;

    /**
     * @var string|null
     */
    private $format;

    /**
     * @var int
     */
    private $baseDate;

    /**
     * Should compare the current base date with the given one.
     *
     * The dates are represented as integers in the format "Ymd".
     */
    abstract protected function compare(int $baseDate, int $givenDate): bool;

    /**
     * Initializes the rule.
     */
    public function __construct(int $age, ?string $format = null)
    {
        $this->age = $age;
        $this->format = $format;
        $this->baseDate = (int) date('Ymd') - $this->age * 10000;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        if ($this->format === null) {
            return $this->isValidWithoutFormat((string) $input);
        }

        return $this->isValidWithFormat($this->format, (string) $input);
    }

    private function isValidWithoutFormat(string $dateTime): bool
    {
        $timestamp = strtotime($dateTime);
        if ($timestamp === false) {
            return false;
        }

        return $this->compare($this->baseDate, (int) date('Ymd', $timestamp));
    }

    private function isValidWithFormat(string $format, string $dateTime): bool
    {
        if (!$this->isDateTime($format, $dateTime)) {
            return false;
        }

        return $this->compare(
            $this->baseDate,
            (int) vsprintf('%d%02d%02d', date_parse_from_format($format, $dateTime))
        );
    }
}
validation/library/Rules/CallableType.php000064400000001203147361033760014514 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_callable;

/**
 * Validates whether the pseudo-type of the input is callable.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class CallableType extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_callable($input);
    }
}
validation/library/Rules/Readable.php000064400000001737147361033760013666 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Psr\Http\Message\StreamInterface;
use SplFileInfo;

use function is_readable;
use function is_string;

/**
 * Validates if the given data is a file exists and is readable.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Readable extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isReadable();
        }

        if ($input instanceof StreamInterface) {
            return $input->isReadable();
        }

        return is_string($input) && is_readable($input);
    }
}
validation/library/Rules/Cnh.php000064400000003076147361033760012675 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function mb_strlen;
use function preg_replace;

/**
 * Validates a Brazilian driver's license.
 *
 * @author Gabriel Pedro <gpedro@users.noreply.github.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kinn Coelho Julião <kinncj@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Cnh extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        // Canonicalize input
        $input = (string) preg_replace('{\D}', '', (string) $input);

        // Validate length and invalid numbers
        if (mb_strlen($input) != 11 || ((int) $input === 0)) {
            return false;
        }

        // Validate check digits using a modulus 11 algorithm
        for ($c = $s1 = $s2 = 0, $p = 9; $c < 9; $c++, $p--) {
            $s1 += (int) $input[$c] * $p;
            $s2 += (int) $input[$c] * (10 - $p);
        }

        $dv1 = $s1 % 11;
        if ($input[9] != ($dv1 > 9) ? 0 : $dv1) {
            return false;
        }

        $dv2 = $s2 % 11 - ($dv1 > 9 ? 2 : 0);
        $check = $dv2 < 0 ? $dv2 + 11 : ($dv2 > 9 ? 0 : $dv2);

        return $input[10] == $check;
    }
}
validation/library/Rules/Domain.php000064400000011152147361033760013366 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\DomainException;
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;

use function array_merge;
use function array_pop;
use function count;
use function explode;
use function iterator_to_array;
use function mb_substr_count;

/**
 * Validates whether the input is a valid domain name or not.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Mehmet Tolga Avcioglu <mehmet@activecom.net>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author Róbert Nagy <vrnagy@gmail.com>
 */
final class Domain extends AbstractRule
{
    /**
     * @var Validatable
     */
    private $genericRule;

    /**
     * @var Validatable
     */
    private $tldRule;

    /**
     * @var Validatable
     */
    private $partsRule;

    public function __construct(bool $tldCheck = true)
    {
        $this->genericRule = $this->createGenericRule();
        $this->tldRule = $this->createTldRule($tldCheck);
        $this->partsRule = $this->createPartsRule();
    }

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $exceptions = [];

        $this->collectAssertException($exceptions, $this->genericRule, $input);
        $this->throwExceptions($exceptions, $input);

        $parts = explode('.', (string) $input);
        if (count($parts) >= 2) {
            $this->collectAssertException($exceptions, $this->tldRule, array_pop($parts));
        }

        foreach ($parts as $part) {
            $this->collectAssertException($exceptions, $this->partsRule, $part);
        }

        $this->throwExceptions($exceptions, $input);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        try {
            $this->assert($input);
        } catch (ValidationException $exception) {
            return false;
        }

        return true;
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        try {
            $this->assert($input);
        } catch (NestedValidationException $exception) {
            /** @var ValidationException $childException */
            foreach ($exception as $childException) {
                throw $childException;
            }

            throw $exception;
        }
    }

    /**
     * @param ValidationException[] $exceptions
     * @param mixed $input
     */
    private function collectAssertException(array &$exceptions, Validatable $validator, $input): void
    {
        try {
            $validator->assert($input);
        } catch (NestedValidationException $nestedValidationException) {
            $exceptions = array_merge(
                $exceptions,
                iterator_to_array($nestedValidationException)
            );
        } catch (ValidationException $validationException) {
            $exceptions[] = $validationException;
        }
    }

    private function createGenericRule(): Validatable
    {
        return new AllOf(
            new StringType(),
            new NoWhitespace(),
            new Contains('.'),
            new Length(3)
        );
    }

    private function createTldRule(bool $realTldCheck): Validatable
    {
        if ($realTldCheck) {
            return new Tld();
        }

        return new AllOf(
            new Not(new StartsWith('-')),
            new NoWhitespace(),
            new Length(2)
        );
    }

    private function createPartsRule(): Validatable
    {
        return new AllOf(
            new Alnum('-'),
            new Not(new StartsWith('-')),
            new AnyOf(
                new Not(new Contains('--')),
                new Callback(static function ($str) {
                    return mb_substr_count($str, '--') == 1;
                })
            ),
            new Not(new EndsWith('-'))
        );
    }

    /**
     * @param ValidationException[] $exceptions
     * @param mixed $input
     */
    private function throwExceptions(array $exceptions, $input): void
    {
        if (count($exceptions)) {
            /** @var DomainException $domainException */
            $domainException = $this->reportError($input);
            $domainException->addChildren($exceptions);

            throw $domainException;
        }
    }
}
validation/library/Rules/Ip.php000064400000012710147361033760012530 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function bccomp;
use function explode;
use function filter_var;
use function ip2long;
use function is_string;
use function long2ip;
use function mb_strpos;
use function mb_substr_count;
use function sprintf;
use function str_repeat;
use function str_replace;
use function strtr;

use const FILTER_VALIDATE_IP;

/**
 * Validates whether the input is a valid IP address.
 *
 * This validator uses the native filter_var() PHP function.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
 */
final class Ip extends AbstractRule
{
    /**
     * @var string|null
     */
    private $range;

    /**
     * @var int|null
     */
    private $options;

    /**
     * @var string|null
     */
    private $startAddress;

    /**
     * @var string|null
     */
    private $endAddress;

    /**
     * @var string|null
     */
    private $mask;

    /**
     * Initializes the rule defining the range and some options for filter_var().
     *
     * @throws ComponentException In case the range is invalid
     */
    public function __construct(string $range = '*', ?int $options = null)
    {
        $this->parseRange($range);
        $this->range = $this->createRange();
        $this->options = $options;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        if (!$this->verifyAddress($input)) {
            return false;
        }

        if ($this->mask) {
            return $this->belongsToSubnet($input);
        }

        if ($this->startAddress && $this->endAddress) {
            return $this->verifyNetwork($input);
        }

        return true;
    }

    private function createRange(): ?string
    {
        if ($this->endAddress && $this->endAddress) {
            return $this->startAddress . '-' . $this->endAddress;
        }

        if ($this->startAddress && $this->mask) {
            return $this->startAddress . '/' . long2ip((int) $this->mask);
        }

        return null;
    }

    private function parseRange(string $input): void
    {
        if ($input == '*' || $input == '*.*.*.*' || $input == '0.0.0.0-255.255.255.255') {
            return;
        }

        if (mb_strpos($input, '-') !== false) {
            [$this->startAddress, $this->endAddress] = explode('-', $input);

            if ($this->startAddress !== null && !$this->verifyAddress($this->startAddress)) {
                throw new ComponentException('Invalid network range');
            }

            if ($this->endAddress !== null && !$this->verifyAddress($this->endAddress)) {
                throw new ComponentException('Invalid network range');
            }

            return;
        }

        if (mb_strpos($input, '*') !== false) {
            $this->parseRangeUsingWildcards($input);

            return;
        }

        if (mb_strpos($input, '/') !== false) {
            $this->parseRangeUsingCidr($input);

            return;
        }

        throw new ComponentException('Invalid network range');
    }

    private function fillAddress(string $address, string $fill = '*'): string
    {
        return $address . str_repeat('.' . $fill, 3 - mb_substr_count($address, '.'));
    }

    private function parseRangeUsingWildcards(string $input): void
    {
        $address = $this->fillAddress($input);

        $this->startAddress = strtr($address, '*', '0');
        $this->endAddress = str_replace('*', '255', $address);
    }

    private function parseRangeUsingCidr(string $input): void
    {
        $parts = explode('/', $input);

        $this->startAddress = $this->fillAddress($parts[0], '0');
        $isAddressMask = mb_strpos($parts[1], '.') !== false;

        if ($isAddressMask && $this->verifyAddress($parts[1])) {
            $this->mask = sprintf('%032b', ip2long($parts[1]));

            return;
        }

        if ($isAddressMask || $parts[1] < 8 || $parts[1] > 30) {
            throw new ComponentException('Invalid network mask');
        }

        $this->mask = sprintf('%032b', ip2long((string) long2ip(~(2 ** (32 - (int) $parts[1]) - 1))));
    }

    private function verifyAddress(string $address): bool
    {
        return filter_var($address, FILTER_VALIDATE_IP, ['flags' => $this->options]) !== false;
    }

    private function verifyNetwork(string $input): bool
    {
        $input = sprintf('%u', ip2long($input));

        return $this->startAddress !== null
            && $this->endAddress !== null
            && bccomp($input, sprintf('%u', ip2long($this->startAddress))) >= 0
            && bccomp($input, sprintf('%u', ip2long($this->endAddress))) <= 0;
    }

    private function belongsToSubnet(string $input): bool
    {
        if ($this->mask === null || $this->startAddress === null) {
            return false;
        }

        $min = sprintf('%032b', ip2long($this->startAddress));
        $input = sprintf('%032b', ip2long($input));

        return ($input & $this->mask) === ($min & $this->mask);
    }
}
validation/library/Rules/Pesel.php000064400000002463147361033760013234 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_scalar;
use function preg_match;

/**
 * Validates PESEL (Polish human identification number).
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Tomasz Regdos <tomek@regdos.com>
 */
final class Pesel extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_scalar($input)) {
            return false;
        }

        $stringInput = (string) $input;
        if (!preg_match('/^\d{11}$/', (string) $stringInput)) {
            return false;
        }

        $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];

        $targetControlNumber = $stringInput[10];
        $calculateControlNumber = 0;

        for ($i = 0; $i < 10; ++$i) {
            $calculateControlNumber += (int) $stringInput[$i] * $weights[$i];
        }

        $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10;

        return $targetControlNumber == $calculateControlNumber;
    }
}
validation/library/Rules/Nif.php000064400000005337147361033760012703 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_pop;
use function array_sum;
use function is_numeric;
use function is_string;
use function mb_substr;
use function preg_match;
use function str_split;

/**
 * Validates Spain's fiscal identification number (NIF).
 *
 *
 * @see https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Julián Gutiérrez <juliangut@gmail.com>
 * @author Senén <senen@instasent.com>
 */
final class Nif extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        if (preg_match('/^(\d{8})([A-Z])$/', $input, $matches)) {
            return $this->validateDni((int) $matches[1], $matches[2]);
        }

        if (preg_match('/^([KLMXYZ])(\d{7})([A-Z])$/', $input, $matches)) {
            return $this->validateNie($matches[1], $matches[2], $matches[3]);
        }

        if (preg_match('/^([A-HJNP-SUVW])(\d{7})([0-9A-Z])$/', $input, $matches)) {
            return $this->validateCif($matches[2], $matches[3]);
        }

        return false;
    }

    private function validateDni(int $number, string $control): bool
    {
        return mb_substr('TRWAGMYFPDXBNJZSQVHLCKE', $number % 23, 1) === $control;
    }

    private function validateNie(string $prefix, string $number, string $control): bool
    {
        if ($prefix === 'Y') {
            return $this->validateDni((int) ('1' . $number), $control);
        }

        if ($prefix === 'Z') {
            return $this->validateDni((int) ('2' . $number), $control);
        }

        return $this->validateDni((int) $number, $control);
    }

    private function validateCif(string $number, string $control): bool
    {
        $code = 0;
        $position = 1;
        /** @var int $digit */
        foreach (str_split($number) as $digit) {
            $increaser = $digit;
            if ($position % 2 !== 0) {
                $increaser = array_sum(str_split((string) ($digit * 2)));
            }

            $code += $increaser;
            ++$position;
        }

        $digits = str_split((string) $code);
        $lastDigit = (int) array_pop($digits);
        $key = $lastDigit === 0 ? 0 : 10 - $lastDigit;

        if (is_numeric($control)) {
            return (int) $key === (int) $control;
        }

        return mb_substr('JABCDEFGHI', $key % 10, 1) === $control;
    }
}
validation/library/Rules/Xdigit.php000064400000001215147361033760013406 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_xdigit;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Xdigit extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_xdigit($input);
    }
}
validation/library/Rules/Writable.php000064400000001720147361033760013730 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Psr\Http\Message\StreamInterface;
use SplFileInfo;

use function is_string;
use function is_writable;

/**
 * Validates if the given input is writable file.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Writable extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isWritable();
        }

        if ($input instanceof StreamInterface) {
            return $input->isWritable();
        }

        return is_string($input) && is_writable($input);
    }
}
validation/library/Rules/Optional.php000064400000002123147361033760013742 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanValidateUndefined;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Optional extends AbstractWrapper
{
    use CanValidateUndefined;

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if ($this->isUndefined($input)) {
            return;
        }

        parent::assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        if ($this->isUndefined($input)) {
            return;
        }

        parent::check($input);
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($this->isUndefined($input)) {
            return true;
        }

        return parent::validate($input);
    }
}
validation/library/Rules/TrueVal.php000064400000001437147361033760013546 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;

use const FILTER_NULL_ON_FAILURE;
use const FILTER_VALIDATE_BOOLEAN;

/**
 * Validates if a value is considered as true.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class TrueVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true;
    }
}
validation/library/Rules/Json.php000064400000001704147361033760013072 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function json_decode;
use function json_last_error;

use const JSON_ERROR_NONE;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Json extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input) || $input === '') {
            return false;
        }

        json_decode($input);

        return json_last_error() === JSON_ERROR_NONE;
    }
}
validation/library/Rules/AbstractSearcher.php000064400000001713147361033760015401 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Helpers\CanValidateUndefined;

use function in_array;

/**
 * Abstract class for searches into arrays.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
abstract class AbstractSearcher extends AbstractRule
{
    use CanValidateUndefined;

    /**
     * @return mixed[]
     */
    abstract protected function getDataSource(): array;

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        $dataSource = $this->getDataSource();
        if ($this->isUndefined($input) && empty($dataSource)) {
            return true;
        }

        return in_array($input, $dataSource, true);
    }
}
validation/library/Rules/Uuid.php000064400000004124147361033760013066 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function is_string;
use function preg_match;
use function sprintf;

/**
 * Validates whether the input is a valid UUID.
 *
 * It also supports validation of specific versions 1, 3, 4 and 5.
 *
 * @author Dick van der Heiden <d.vanderheiden@inthere.nl>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Michael Weimann <mail@michael-weimann.eu>
 */
final class Uuid extends AbstractRule
{
    /**
     * Placeholder in "sprintf()" format used to create the REGEX that validates inputs.
     */
    private const PATTERN_FORMAT = '/^[0-9a-f]{8}-[0-9a-f]{4}-%s[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';

    /**
     * The UUID version to validate for.
     *
     * @var int|null
     */
    private $version;

    /**
     * Initializes the rule with the desired version.
     *
     * @throws ComponentException when the version is not valid
     */
    public function __construct(?int $version = null)
    {
        if ($version !== null && !$this->isSupportedVersion($version)) {
            throw new ComponentException(sprintf('Only versions 1, 3, 4, and 5 are supported: %d given', $version));
        }

        $this->version = $version;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return preg_match($this->getPattern(), $input) > 0;
    }

    private function isSupportedVersion(int $version): bool
    {
        return $version >= 1 && $version <= 5 && $version !== 2;
    }

    private function getPattern(): string
    {
        if ($this->version !== null) {
            return sprintf(self::PATTERN_FORMAT, $this->version);
        }

        return sprintf(self::PATTERN_FORMAT, '[13-5]');
    }
}
validation/library/Rules/FloatVal.php000064400000001556147361033760013676 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;
use function is_float;

use const FILTER_VALIDATE_FLOAT;

/**
 * Validate whether the input value is float.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jayson Reis <santosdosreis@gmail.com>
 */
final class FloatVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_float(filter_var($input, FILTER_VALIDATE_FLOAT));
    }
}
validation/library/Rules/LessThan.php000064400000001144147361033760013700 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates whether the input is less than a value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LessThan extends AbstractComparison
{
    /**
     * {@inheritDoc}
     */
    protected function compare($left, $right): bool
    {
        return $left < $right;
    }
}
validation/library/Rules/NotEmpty.php000064400000001475147361033760013745 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function trim;

/**
 * Validates whether the input is not empty
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Bram Van der Sype <bram.vandersype@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotEmpty extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (is_string($input)) {
            $input = trim($input);
        }

        return !empty($input);
    }
}
validation/library/Rules/NotEmoji.php000064400000012467147361033760013715 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function implode;
use function is_string;
use function preg_match;

/**
 * Validates if the input does not contain an emoji.
 *
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class NotEmoji extends AbstractRule
{
    private const RANGES = [
        '\x{0023}\x{FE0F}\x{20E3}',
        '\x{0023}\x{20E3}',
        '\x{002A}\x{FE0F}\x{20E3}',
        '\x{002A}\x{20E3}',
        '\x{0030}\x{FE0F}\x{20E3}',
        '\x{0030}\x{20E3}',
        '\x{0031}\x{FE0F}\x{20E3}',
        '\x{0031}\x{20E3}',
        '\x{0032}\x{FE0F}\x{20E3}',
        '\x{0032}\x{20E3}',
        '\x{0033}\x{FE0F}\x{20E3}',
        '\x{0033}\x{20E3}',
        '\x{0034}\x{FE0F}\x{20E3}',
        '\x{0034}\x{20E3}',
        '\x{0035}\x{FE0F}\x{20E3}',
        '\x{0035}\x{20E3}',
        '\x{0036}\x{FE0F}\x{20E3}',
        '\x{0036}\x{20E3}',
        '\x{0037}\x{FE0F}\x{20E3}',
        '\x{0037}\x{20E3}',
        '\x{0038}\x{FE0F}\x{20E3}',
        '\x{0038}\x{20E3}',
        '\x{0039}\x{FE0F}\x{20E3}',
        '\x{0039}\x{20E3}',
        '\x{1F004}',
        '\x{1F0CF}',
        '[\x{1F170}-\x{1F171}]',
        '[\x{1F17E}-\x{1F17F}]',
        '\x{1F18E}',
        '[\x{1F191}-\x{1F19A}]',
        '[\x{1F1E6}-\x{1F1FF}]',
        '[\x{1F201}-\x{1F202}]',
        '\x{1F21A}',
        '\x{1F22F}',
        '[\x{1F232}-\x{1F23A}]',
        '[\x{1F250}-\x{1F251}]',
        '[\x{1F300}-\x{1F321}]',
        '[\x{1F324}-\x{1F393}]',
        '[\x{1F396}-\x{1F397}]',
        '[\x{1F399}-\x{1F39B}]',
        '[\x{1F39E}-\x{1F3F0}]',
        '[\x{1F3F3}-\x{1F3F5}]',
        '[\x{1F3F7}-\x{1F4FD}]',
        '[\x{1F4FF}-\x{1F53D}]',
        '[\x{1F549}-\x{1F54E}]',
        '[\x{1F550}-\x{1F567}]',
        '[\x{1F56F}-\x{1F570}]',
        '[\x{1F573}-\x{1F57A}]',
        '\x{1F587}',
        '[\x{1F58A}-\x{1F58D}]',
        '\x{1F590}',
        '[\x{1F595}-\x{1F596}]',
        '[\x{1F5A4}-\x{1F5A5}]',
        '\x{1F5A8}',
        '[\x{1F5B1}-\x{1F5B2}]',
        '\x{1F5BC}',
        '[\x{1F5C2}-\x{1F5C4}]',
        '[\x{1F5D1}-\x{1F5D3}]',
        '[\x{1F5DC}-\x{1F5DE}]',
        '\x{1F5E1}',
        '\x{1F5E3}',
        '\x{1F5E8}',
        '\x{1F5EF}',
        '\x{1F5F3}',
        '[\x{1F5FA}-\x{1F64F}]',
        '[\x{1F680}-\x{1F6C5}]',
        '[\x{1F6CB}-\x{1F6D2}]',
        '[\x{1F6E0}-\x{1F6E5}]',
        '\x{1F6E9}',
        '[\x{1F6EB}-\x{1F6EC}]',
        '\x{1F6F0}',
        '[\x{1F6F3}-\x{1F6F9}]',
        '[\x{1F910}-\x{1F93A}]',
        '[\x{1F93C}-\x{1F93E}]',
        '[\x{1F940}-\x{1F945}]',
        '[\x{1F947}-\x{1F970}]',
        '[\x{1F973}-\x{1F976}]',
        '\x{1F97A}',
        '[\x{1F97C}-\x{1F9A2}]',
        '[\x{1F9B0}-\x{1F9B9}]',
        '[\x{1F9C0}-\x{1F9C2}]',
        '[\x{1F9D0}-\x{1F9FF}]',
        '\x{00A9}',
        '\x{00AE}',
        '\x{203C}',
        '\x{2049}',
        '\x{2122}',
        '\x{2139}',
        '[\x{2194}-\x{2199}]',
        '[\x{21A9}-\x{21AA}]',
        '[\x{231A}-\x{231B}]',
        '\x{2328}',
        '\x{23CF}',
        '[\x{23E9}-\x{23F3}]',
        '[\x{23F8}-\x{23FA}]',
        '\x{24C2}',
        '[\x{25AA}-\x{25AB}]',
        '\x{25B6}',
        '\x{25C0}',
        '[\x{25FB}-\x{25FE}]',
        '[\x{2600}-\x{2604}]',
        '\x{260E}',
        '\x{2611}',
        '[\x{2614}-\x{2615}]',
        '\x{2618}',
        '\x{261D}',
        '\x{2620}',
        '[\x{2622}-\x{2623}]',
        '\x{2626}',
        '\x{262A}',
        '[\x{262E}-\x{262F}]',
        '[\x{2638}-\x{263A}]',
        '\x{2640}',
        '\x{2642}',
        '[\x{2648}-\x{2653}]',
        '[\x{265F}-\x{2660}]',
        '\x{2663}',
        '[\x{2665}-\x{2666}]',
        '\x{2668}',
        '\x{267B}',
        '[\x{267E}-\x{267F}]',
        '[\x{2692}-\x{2697}]',
        '\x{2699}',
        '[\x{269B}-\x{269C}]',
        '[\x{26A0}-\x{26A1}]',
        '[\x{26AA}-\x{26AB}]',
        '[\x{26B0}-\x{26B1}]',
        '[\x{26BD}-\x{26BE}]',
        '[\x{26C4}-\x{26C5}]',
        '\x{26C8}',
        '[\x{26CE}-\x{26CF}]',
        '\x{26D1}',
        '[\x{26D3}-\x{26D4}]',
        '\x{26EA}',
        '[\x{26F0}-\x{26F5}]',
        '[\x{26F7}-\x{26FA}]',
        '\x{26FD}',
        '\x{2702}',
        '\x{2705}',
        '[\x{2708}-\x{270D}]',
        '\x{270F}',
        '\x{2712}',
        '\x{2714}',
        '\x{2716}',
        '\x{271D}',
        '\x{2721}',
        '\x{2728}',
        '[\x{2733}-\x{2734}]',
        '\x{2744}',
        '\x{2747}',
        '\x{26E9}',
        '\x{274C}',
        '\x{274E}',
        '[\x{2753}-\x{2755}]',
        '\x{2757}',
        '[\x{2763}-\x{2764}]',
        '[\x{2795}-\x{2797}]',
        '\x{27A1}',
        '\x{27B0}',
        '\x{27BF}',
        '[\x{2934}-\x{2935}]',
        '[\x{2B05}-\x{2B07}]',
        '[\x{2B1B}-\x{2B1C}]',
        '\x{2B50}',
        '\x{2B55}',
        '\x{3030}',
        '\x{303D}',
        '\x{3297}',
        '\x{3299}',
    ];

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        return preg_match('/' . implode('|', self::RANGES) . '/mu', $input) === 0;
    }
}
validation/library/Rules/Punct.php000064400000001467147361033760013260 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_punct;

/**
 * Validates whether the input composed by only punctuation characters.
 *
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Punct extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_punct($input);
    }
}
validation/library/Rules/Space.php000064400000001464147361033760013217 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function ctype_space;

/**
 * Validates whether the input contains only whitespaces characters.
 *
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Space extends AbstractFilterRule
{
    /**
     * {@inheritDoc}
     */
    protected function validateFilteredInput(string $input): bool
    {
        return ctype_space($input);
    }
}
validation/library/Rules/Odd.php000064400000001672147361033760012673 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;
use function is_numeric;

use const FILTER_VALIDATE_INT;

/**
 * Validates whether the input is an odd number or not.
 *
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class Odd extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_numeric($input)) {
            return false;
        }

        if (!filter_var($input, FILTER_VALIDATE_INT)) {
            return false;
        }

        return (int) $input % 2 !== 0;
    }
}
validation/library/Rules/BoolVal.php000064400000001575147361033760013525 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function filter_var;
use function is_bool;

use const FILTER_NULL_ON_FAILURE;
use const FILTER_VALIDATE_BOOLEAN;

/**
 * Validates if the input results in a boolean value.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class BoolVal extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return is_bool(filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
    }
}
validation/library/Rules/Callback.php000064400000002775147361033760013666 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_merge;
use function call_user_func_array;
use function count;

/**
 * Validates the input using the return of a given callable.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Callback extends AbstractRule
{
    /**
     * @var callable
     */
    private $callback;

    /**
     * @var mixed[]
     */
    private $arguments;

    /**
     * Initializes the rule.
     *
     * @param mixed ...$arguments
     */
    public function __construct(callable $callback, ...$arguments)
    {
        $this->callback = $callback;
        $this->arguments = $arguments;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        return (bool) call_user_func_array($this->callback, $this->getArguments($input));
    }

    /**
     * @param mixed $input
     * @return mixed[]
     */
    private function getArguments($input): array
    {
        $arguments = [$input];
        if (count($this->arguments) === 0) {
            return $arguments;
        }

        return array_merge($arguments, $this->arguments);
    }
}
validation/library/Rules/AllOf.php000064400000003157147361033760013162 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\AllOfException;

use function count;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class AllOf extends AbstractComposite
{
    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        $exceptions = $this->getAllThrownExceptions($input);
        $numRules = count($this->getRules());
        $numExceptions = count($exceptions);
        $summary = [
            'total' => $numRules,
            'failed' => $numExceptions,
            'passed' => $numRules - $numExceptions,
        ];
        if (!empty($exceptions)) {
            /** @var AllOfException $allOfException */
            $allOfException = $this->reportError($input, $summary);
            $allOfException->addChildren($exceptions);

            throw $allOfException;
        }
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        foreach ($this->getRules() as $rule) {
            $rule->check($input);
        }
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        foreach ($this->getRules() as $rule) {
            if (!$rule->validate($input)) {
                return false;
            }
        }

        return true;
    }
}
validation/library/Rules/Max.php000064400000001251147361033760012703 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
 * Validates whether the input is less than or equal to a value.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Max extends AbstractComparison
{
    /**
     * {@inheritDoc}
     */
    protected function compare($left, $right): bool
    {
        return $left <= $right;
    }
}
validation/library/Rules/Subset.php000064400000002021147361033760013417 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function array_diff;
use function is_array;

/**
 * Validates whether the input is a subset of a given value.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Singwai Chan <singwai.chan@live.com>
 */
final class Subset extends AbstractRule
{
    /**
     * @var mixed[]
     */
    private $superset;

    /**
     * Initializes the rule.
     *
     * @param mixed[] $superset
     */
    public function __construct(array $superset)
    {
        $this->superset = $superset;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_array($input)) {
            return false;
        }

        return array_diff($input, $this->superset) === [];
    }
}
validation/library/Rules/Mimetype.php000064400000002713147361033760013753 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use finfo;
use SplFileInfo;

use function is_file;
use function is_string;

use const FILEINFO_MIME_TYPE;

/**
 * Validates if the input is a file and if its MIME type matches the expected one.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Mimetype extends AbstractRule
{
    /**
     * @var string
     */
    private $mimetype;

    /**
     * @var finfo
     */
    private $fileInfo;

    /**
     * Initializes the rule by defining the expected mimetype from the input.
     */
    public function __construct(string $mimetype, ?finfo $fileInfo = null)
    {
        $this->mimetype = $mimetype;
        $this->fileInfo = $fileInfo ?: new finfo();
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $this->validate($input->getPathname());
        }

        if (!is_string($input)) {
            return false;
        }

        if (!is_file($input)) {
            return false;
        }

        return $this->mimetype === $this->fileInfo->file($input, FILEINFO_MIME_TYPE);
    }
}
validation/library/Rules/DateTime.php000064400000002731147361033760013656 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use DateTimeInterface;
use Respect\Validation\Helpers\CanValidateDateTime;

use function date;
use function is_scalar;
use function strtotime;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DateTime extends AbstractRule
{
    use CanValidateDateTime;

    /**
     * @var string|null
     */
    private $format;

    /**
     * @var string
     */
    private $sample;

    /**
     * Initializes the rule.
     */
    public function __construct(?string $format = null)
    {
        $this->format = $format;
        $this->sample = date($format ?: 'c', strtotime('2005-12-30 01:02:03'));
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof DateTimeInterface) {
            return $this->format === null;
        }

        if (!is_scalar($input)) {
            return false;
        }

        if ($this->format === null) {
            return strtotime((string) $input) !== false;
        }

        return $this->isDateTime($this->format, (string) $input);
    }
}
validation/library/Rules/Slug.php000064400000002001147361033760013062 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use function is_string;
use function mb_strstr;
use function preg_match;

/**
 * Validates whether the input is a valid slug.
 *
 * @author Carlos André Ferrari <caferrari@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 */
final class Slug extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input) || mb_strstr($input, '--')) {
            return false;
        }

        if (!preg_match('@^[0-9a-z\-]+$@', $input)) {
            return false;
        }

        return preg_match('@^-|-$@', $input) === 0;
    }
}
validation/library/Rules/AbstractRule.php000064400000003663147361033760014562 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Factory;
use Respect\Validation\Validatable;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author Vicente Mendoza <vicentemmor@yahoo.com.mx>
 */
abstract class AbstractRule implements Validatable
{
    /**
     * @var string|null
     */
    protected $name;

    /**
     * @var string|null
     */
    protected $template;

    /**
     * {@inheritDoc}
     */
    public function assert($input): void
    {
        if ($this->validate($input)) {
            return;
        }

        throw $this->reportError($input);
    }

    /**
     * {@inheritDoc}
     */
    public function check($input): void
    {
        $this->assert($input);
    }

    /**
     * {@inheritDoc}
     */
    public function getName(): ?string
    {
        return $this->name;
    }

    /**
     * {@inheritDoc}
     */
    public function reportError($input, array $extraParams = []): ValidationException
    {
        return Factory::getDefaultInstance()->exception($this, $input, $extraParams);
    }

    /**
     * {@inheritDoc}
     */
    public function setName(string $name): Validatable
    {
        $this->name = $name;

        return $this;
    }

    /**
     * {@inheritDoc}
     */
    public function setTemplate(string $template): Validatable
    {
        $this->template = $template;

        return $this;
    }

    /**
     * @param mixed$input
     */
    public function __invoke($input): bool
    {
        return $this->validate($input);
    }
}
validation/library/Rules/File.php000064400000001475147361033760013045 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use SplFileInfo;

use function is_file;
use function is_string;

/**
 * Validates whether file input is as a regular filename.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class File extends AbstractRule
{
    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if ($input instanceof SplFileInfo) {
            return $input->isFile();
        }

        return is_string($input) && is_file($input);
    }
}
validation/library/Rules/VideoUrl.php000064400000005045147361033760013714 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;

use function array_keys;
use function is_string;
use function mb_strtolower;
use function preg_match;
use function sprintf;

/**
 * Validates if the input is a video URL value.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ricardo Gobbo <ricardo@clicknow.com.br>
 */
final class VideoUrl extends AbstractRule
{
    private const SERVICES = [
        // phpcs:disable Generic.Files.LineLength.TooLong
        'youtube' => '@^https?://(www\.)?(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^\"&?/]{11})@i',
        'vimeo' => '@^https?://(www\.)?(player\.)?(vimeo\.com/)((channels/[A-z]+/)|(groups/[A-z]+/videos/)|(video/))?([0-9]+)@i',
        'twitch' => '@^https?://(((www\.)?twitch\.tv/videos/[0-9]+)|clips\.twitch\.tv/[a-zA-Z]+)$@i',
        // phpcs:enable Generic.Files.LineLength.TooLong
    ];

    /**
     * @var string|null
     */
    private $service;

    /**
     * Create a new instance VideoUrl.
     *
     * @throws ComponentException when the given service is not supported
     */
    public function __construct(?string $service = null)
    {
        if ($service !== null && !$this->isSupportedService($service)) {
            throw new ComponentException(sprintf('"%s" is not a recognized video service.', $service));
        }

        $this->service = $service;
    }

    /**
     * {@inheritDoc}
     */
    public function validate($input): bool
    {
        if (!is_string($input)) {
            return false;
        }

        if ($this->service !== null) {
            return $this->isValid($this->service, $input);
        }

        foreach (array_keys(self::SERVICES) as $service) {
            if (!$this->isValid($service, $input)) {
                continue;
            }

            return true;
        }

        return false;
    }

    private function isSupportedService(string $service): bool
    {
        return isset(self::SERVICES[mb_strtolower($service)]);
    }

    private function isValid(string $service, string $input): bool
    {
        return preg_match(self::SERVICES[mb_strtolower($service)], $input) > 0;
    }
}
validation/library/ChainedValidator.php000064400000025551147361033760014276 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation;

use finfo;
use Respect\Validation\Rules\Key;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidator;
use Zend\Validator\ValidatorInterface as ZendValidator;

interface ChainedValidator extends Validatable
{
    public function allOf(Validatable ...$rule): ChainedValidator;

    public function alnum(string ...$additionalChars): ChainedValidator;

    public function alpha(string ...$additionalChars): ChainedValidator;

    public function alwaysInvalid(): ChainedValidator;

    public function alwaysValid(): ChainedValidator;

    public function anyOf(Validatable ...$rule): ChainedValidator;

    public function arrayType(): ChainedValidator;

    public function arrayVal(): ChainedValidator;

    public function attribute(
        string $reference,
        ?Validatable $validator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public function base(int $base, ?string $chars = null): ChainedValidator;

    public function base64(): ChainedValidator;

    /**
     * @param mixed $minimum
     * @param mixed $maximum
     */
    public function between($minimum, $maximum): ChainedValidator;

    public function bic(string $countryCode): ChainedValidator;

    public function boolType(): ChainedValidator;

    public function boolVal(): ChainedValidator;

    public function bsn(): ChainedValidator;

    public function call(callable $callable, Validatable $rule): ChainedValidator;

    public function callableType(): ChainedValidator;

    public function callback(callable $callback): ChainedValidator;

    public function charset(string ...$charset): ChainedValidator;

    public function cnh(): ChainedValidator;

    public function cnpj(): ChainedValidator;

    public function control(string ...$additionalChars): ChainedValidator;

    public function consonant(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $containsValue
     */
    public function contains($containsValue, bool $identical = false): ChainedValidator;

    /**
     * @param mixed[] $needles
     */
    public function containsAny(array $needles, bool $strictCompareArray = false): ChainedValidator;

    public function countable(): ChainedValidator;

    public function countryCode(?string $set = null): ChainedValidator;

    public function currencyCode(): ChainedValidator;

    public function cpf(): ChainedValidator;

    public function creditCard(?string $brand = null): ChainedValidator;

    public function date(string $format = 'Y-m-d'): ChainedValidator;

    public function dateTime(?string $format = null): ChainedValidator;

    public function decimal(int $decimals): ChainedValidator;

    public function digit(string ...$additionalChars): ChainedValidator;

    public function directory(): ChainedValidator;

    public function domain(bool $tldCheck = true): ChainedValidator;

    public function each(Validatable $rule): ChainedValidator;

    public function email(): ChainedValidator;

    /**
     * @param mixed $endValue
     */
    public function endsWith($endValue, bool $identical = false): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function equals($compareTo): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function equivalent($compareTo): ChainedValidator;

    public function even(): ChainedValidator;

    public function executable(): ChainedValidator;

    public function exists(): ChainedValidator;

    public function extension(string $extension): ChainedValidator;

    public function factor(int $dividend): ChainedValidator;

    public function falseVal(): ChainedValidator;

    public function fibonacci(): ChainedValidator;

    public function file(): ChainedValidator;

    /**
     * @param mixed[]|int $options
     */
    public function filterVar(int $filter, $options = null): ChainedValidator;

    public function finite(): ChainedValidator;

    public function floatVal(): ChainedValidator;

    public function floatType(): ChainedValidator;

    public function graph(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function greaterThan($compareTo): ChainedValidator;

    public function hexRgbColor(): ChainedValidator;

    public function iban(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function identical($compareTo): ChainedValidator;

    public function image(?finfo $fileInfo = null): ChainedValidator;

    public function imei(): ChainedValidator;

    /**
     * @param mixed[]|mixed $haystack
     */
    public function in($haystack, bool $compareIdentical = false): ChainedValidator;

    public function infinite(): ChainedValidator;

    public function instance(string $instanceName): ChainedValidator;

    public function intVal(): ChainedValidator;

    public function intType(): ChainedValidator;

    public function ip(string $range = '*', ?int $options = null): ChainedValidator;

    public function isbn(): ChainedValidator;

    public function iterableType(): ChainedValidator;

    public function json(): ChainedValidator;

    public function key(
        string $reference,
        ?Validatable $referenceValidator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public function keyNested(
        string $reference,
        ?Validatable $referenceValidator = null,
        bool $mandatory = true
    ): ChainedValidator;

    public function keySet(Key ...$rule): ChainedValidator;

    public function keyValue(string $comparedKey, string $ruleName, string $baseKey): ChainedValidator;

    public function languageCode(?string $set = null): ChainedValidator;

    public function leapDate(string $format): ChainedValidator;

    public function leapYear(): ChainedValidator;

    public function length(?int $min = null, ?int $max = null, bool $inclusive = true): ChainedValidator;

    public function lowercase(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function lessThan($compareTo): ChainedValidator;

    public function luhn(): ChainedValidator;

    public function macAddress(): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function max($compareTo): ChainedValidator;

    public function maxAge(int $age, ?string $format = null): ChainedValidator;

    public function mimetype(string $mimetype): ChainedValidator;

    /**
     * @param mixed $compareTo
     */
    public function min($compareTo): ChainedValidator;

    public function minAge(int $age, ?string $format = null): ChainedValidator;

    public function multiple(int $multipleOf): ChainedValidator;

    public function negative(): ChainedValidator;

    public function nfeAccessKey(): ChainedValidator;

    public function nif(): ChainedValidator;

    public function nip(): ChainedValidator;

    public function no(bool $useLocale = false): ChainedValidator;

    public function noneOf(Validatable ...$rule): ChainedValidator;

    public function not(Validatable $rule): ChainedValidator;

    public function notBlank(): ChainedValidator;

    public function notEmoji(): ChainedValidator;

    public function notEmpty(): ChainedValidator;

    public function notOptional(): ChainedValidator;

    public function noWhitespace(): ChainedValidator;

    public function nullable(Validatable $rule): ChainedValidator;

    public function nullType(): ChainedValidator;

    public function number(): ChainedValidator;

    public function numericVal(): ChainedValidator;

    public function objectType(): ChainedValidator;

    public function odd(): ChainedValidator;

    public function oneOf(Validatable ...$rule): ChainedValidator;

    public function optional(Validatable $rule): ChainedValidator;

    public function perfectSquare(): ChainedValidator;

    public function pesel(): ChainedValidator;

    public function phone(): ChainedValidator;

    public function phpLabel(): ChainedValidator;

    public function pis(): ChainedValidator;

    public function polishIdCard(): ChainedValidator;

    public function positive(): ChainedValidator;

    public function postalCode(string $countryCode): ChainedValidator;

    public function primeNumber(): ChainedValidator;

    public function printable(string ...$additionalChars): ChainedValidator;

    public function punct(string ...$additionalChars): ChainedValidator;

    public function readable(): ChainedValidator;

    public function regex(string $regex): ChainedValidator;

    public function resourceType(): ChainedValidator;

    public function roman(): ChainedValidator;

    public function scalarVal(): ChainedValidator;

    public function sf(Constraint $constraint, ?SymfonyValidator $validator = null): ChainedValidator;

    public function size(?string $minSize = null, ?string $maxSize = null): ChainedValidator;

    public function slug(): ChainedValidator;

    public function sorted(string $direction): ChainedValidator;

    public function space(string ...$additionalChars): ChainedValidator;

    /**
     * @param mixed $startValue
     */
    public function startsWith($startValue, bool $identical = false): ChainedValidator;

    public function stringType(): ChainedValidator;

    public function stringVal(): ChainedValidator;

    public function subdivisionCode(string $countryCode): ChainedValidator;

    /**
     * @param mixed[] $superset
     */
    public function subset(array $superset): ChainedValidator;

    public function symbolicLink(): ChainedValidator;

    public function time(string $format = 'H:i:s'): ChainedValidator;

    public function tld(): ChainedValidator;

    public function trueVal(): ChainedValidator;

    public function type(string $type): ChainedValidator;

    public function unique(): ChainedValidator;

    public function uploaded(): ChainedValidator;

    public function uppercase(): ChainedValidator;

    public function url(): ChainedValidator;

    public function uuid(?int $version = null): ChainedValidator;

    public function version(): ChainedValidator;

    public function videoUrl(?string $service = null): ChainedValidator;

    public function vowel(string ...$additionalChars): ChainedValidator;

    public function when(Validatable $if, Validatable $then, ?Validatable $else = null): ChainedValidator;

    public function writable(): ChainedValidator;

    public function xdigit(string ...$additionalChars): ChainedValidator;

    public function yes(bool $useLocale = false): ChainedValidator;

    /**
     * @param string|ZendValidator $validator
     * @param mixed[] $params
     */
    public function zend($validator, ?array $params = null): ChainedValidator;
}
validation/library/Helpers/CanCompareValues.php000064400000003117147361033760015661 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Helpers;

use Countable;
use DateTimeImmutable;
use DateTimeInterface;
use Throwable;

use function is_numeric;
use function is_scalar;
use function is_string;
use function mb_strlen;

/**
 * Helps to deal with comparable values.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
trait CanCompareValues
{
    /**
     * Tries to convert a value into something that can be compared with PHP operators.
     *
     * @param mixed $value
     *
     * @return mixed
     */
    private function toComparable($value)
    {
        if ($value instanceof Countable) {
            return $value->count();
        }

        if ($value instanceof DateTimeInterface || !is_string($value) || is_numeric($value) || empty($value)) {
            return $value;
        }

        if (mb_strlen($value) === 1) {
            return $value;
        }

        try {
            return new DateTimeImmutable($value);
        } catch (Throwable $e) {
            return $value;
        }
    }

    /**
     * Returns whether the values can be compared or not.
     *
     * @param mixed $left
     * @param mixed $right
     */
    private function isAbleToCompareValues($left, $right): bool
    {
        return is_scalar($left) === is_scalar($right);
    }
}
validation/library/Helpers/Subdivisions.php000064400000002242147361033760015150 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Helpers;

use Respect\Validation\Exceptions\ComponentException;

use function file_exists;
use function file_get_contents;
use function json_decode;
use function sprintf;

final class Subdivisions
{
    /**
     * @var mixed[]
     */
    private $data;

    public function __construct(string $countryCode)
    {
        $filename = __DIR__ . '/../../data/iso_3166-2/' . $countryCode . '.json';
        if (!file_exists($filename)) {
            throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode));
        }

        $this->data = (array) json_decode((string) file_get_contents($filename), true);
    }

    public function getCountry(): string
    {
        return $this->data['country'];
    }

    /**
     * @return string[]
     */
    public function getSubdivisions(): array
    {
        return $this->data['subdivisions'];
    }
}
validation/library/Helpers/CanValidateUndefined.php000064400000001312147361033760016461 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Helpers;

use function in_array;

/**
 * Helper to identify values that Validation consider as "undefined".
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
trait CanValidateUndefined
{
    /**
     * Finds whether the value is undefined or not.
     *
     * @param mixed $value
     */
    private function isUndefined($value): bool
    {
        return in_array($value, [null, ''], true);
    }
}
validation/library/Helpers/CanValidateDateTime.php000064400000003337147361033760016265 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Helpers;

use function checkdate;
use function date_parse_from_format;
use function preg_match;

/**
 * Helper to handle date/time.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
trait CanValidateDateTime
{
    /**
     * Finds whether a value is a valid date/time in a specific format.
     */
    private function isDateTime(string $format, string $value): bool
    {
        $exceptionalFormats = [
            'c' => 'Y-m-d\TH:i:sP',
            'r' => 'D, d M Y H:i:s O',
        ];

        $info = date_parse_from_format($exceptionalFormats[$format] ?? $format, $value);

        if (!$this->isDateTimeParsable($info)) {
            return false;
        }

        if ($this->isDateFormat($format)) {
            return $this->isDateInformation($info);
        }

        return true;
    }

    /**
     * @param int[] $info
     */
    private function isDateTimeParsable(array $info): bool
    {
        return $info['error_count'] === 0 && $info['warning_count'] === 0;
    }

    private function isDateFormat(string $format): bool
    {
        return preg_match('/[djSFmMnYy]/', $format) > 0;
    }

    /**
     * @param mixed[] $info
     */
    private function isDateInformation(array $info): bool
    {
        if ($info['day']) {
            return checkdate((int) $info['month'], $info['day'], (int) $info['year']);
        }

        return checkdate($info['month'] ?: 1, $info['day'] ?: 1, $info['year'] ?: 1);
    }
}
validation/library/Helpers/CanValidateIterable.php000064400000001364147361033760016316 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Helpers;

use stdClass;
use Traversable;

use function is_array;

/**
 * Helper to handle iterable values.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
trait CanValidateIterable
{
    /**
     * Returns whether the value is iterable or not.
     *
     * @param mixed $value
     */
    public function isIterable($value): bool
    {
        return is_array($value) || $value instanceof stdClass || $value instanceof Traversable;
    }
}
validation/library/Factory.php000064400000016645147361033760012510 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation;

use ReflectionClass;
use ReflectionException;
use ReflectionObject;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidClassException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\ParameterStringifier;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;

use function array_merge;
use function lcfirst;
use function sprintf;
use function str_replace;
use function trim;
use function ucfirst;

/**
 * Factory of objects.
 *
 * @author Augusto Pascutti <augusto@phpsp.org.br>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class Factory
{
    /**
     * @var string[]
     */
    private $rulesNamespaces = ['Respect\\Validation\\Rules'];

    /**
     * @var string[]
     */
    private $exceptionsNamespaces = ['Respect\\Validation\\Exceptions'];

    /**
     * @var callable
     */
    private $translator = 'strval';

    /**
     * @var ParameterStringifier
     */
    private $parameterStringifier;

    /**
     * Default instance of the Factory.
     *
     * @var Factory
     */
    private static $defaultInstance;

    public function __construct()
    {
        $this->parameterStringifier = new KeepOriginalStringName();
    }

    /**
     * Returns the default instance of the Factory.
     */
    public static function getDefaultInstance(): self
    {
        if (self::$defaultInstance === null) {
            self::$defaultInstance = new self();
        }

        return self::$defaultInstance;
    }

    public function withRuleNamespace(string $rulesNamespace): self
    {
        $clone = clone $this;
        $clone->rulesNamespaces[] = trim($rulesNamespace, '\\');

        return $clone;
    }

    public function withExceptionNamespace(string $exceptionsNamespace): self
    {
        $clone = clone $this;
        $clone->exceptionsNamespaces[] = trim($exceptionsNamespace, '\\');

        return $clone;
    }

    public function withTranslator(callable $translator): self
    {
        $clone = clone $this;
        $clone->translator = $translator;

        return $clone;
    }

    public function withParameterStringifier(ParameterStringifier $parameterStringifier): self
    {
        $clone = clone $this;
        $clone->parameterStringifier = $parameterStringifier;

        return $clone;
    }

    /**
     * Creates a rule.
     *
     * @param mixed[] $arguments
     *
     * @throws ComponentException
     */
    public function rule(string $ruleName, array $arguments = []): Validatable
    {
        foreach ($this->rulesNamespaces as $namespace) {
            try {
                /** @var class-string<Validatable> $name */
                $name = $namespace . '\\' . ucfirst($ruleName);
                /** @var Validatable $rule */
                $rule = $this
                    ->createReflectionClass($name, Validatable::class)
                    ->newInstanceArgs($arguments);

                return $rule;
            } catch (ReflectionException $exception) {
                continue;
            }
        }

        throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
    }

    /**
     * Creates an exception.
     *
     * @param mixed $input
     * @param mixed[] $extraParams
     *
     * @throws ComponentException
     */
    public function exception(Validatable $validatable, $input, array $extraParams = []): ValidationException
    {
        $formatter = new Formatter($this->translator, $this->parameterStringifier);
        $reflection = new ReflectionObject($validatable);
        $ruleName = $reflection->getShortName();
        $params = ['input' => $input] + $extraParams + $this->extractPropertiesValues($validatable, $reflection);
        $id = lcfirst($ruleName);
        if ($validatable->getName() !== null) {
            $id = $params['name'] = $validatable->getName();
        }
        $exceptionNamespace = str_replace('\\Rules', '\\Exceptions', $reflection->getNamespaceName());
        foreach (array_merge([$exceptionNamespace], $this->exceptionsNamespaces) as $namespace) {
            try {
                /** @var class-string<ValidationException> $exceptionName */
                $exceptionName = $namespace . '\\' . $ruleName . 'Exception';

                return $this->createValidationException(
                    $exceptionName,
                    $id,
                    $input,
                    $params,
                    $formatter
                );
            } catch (ReflectionException $exception) {
                continue;
            }
        }

        return new ValidationException($input, $id, $params, $formatter);
    }

    /**
     * Define the default instance of the Factory.
     */
    public static function setDefaultInstance(self $defaultInstance): void
    {
        self::$defaultInstance = $defaultInstance;
    }

    /**
     * Creates a reflection based on class name.
     *
     * @param class-string $name
     * @param class-string $parentName
     *
     * @throws InvalidClassException
     * @throws ReflectionException
     */
    private function createReflectionClass(string $name, string $parentName): ReflectionClass
    {
        $reflection = new ReflectionClass($name);
        if (!$reflection->isSubclassOf($parentName) && $parentName !== $name) {
            throw new InvalidClassException(sprintf('"%s" must be an instance of "%s"', $name, $parentName));
        }

        if (!$reflection->isInstantiable()) {
            throw new InvalidClassException(sprintf('"%s" must be instantiable', $name));
        }

        return $reflection;
    }

    /**
     * Creates a Validation exception.
     *
     * @param class-string<ValidationException> $exceptionName
     *
     * @param mixed $input
     * @param mixed[] $params
     *
     * @throws InvalidClassException
     * @throws ReflectionException
     */
    private function createValidationException(
        string $exceptionName,
        string $id,
        $input,
        array $params,
        Formatter $formatter
    ): ValidationException {
        /** @var ValidationException $exception */
        $exception = $this
            ->createReflectionClass($exceptionName, ValidationException::class)
            ->newInstance($input, $id, $params, $formatter);
        if (isset($params['template'])) {
            $exception->updateTemplate($params['template']);
        }

        return $exception;
    }

    /**
     * @return mixed[]
     */
    private function extractPropertiesValues(Validatable $validatable, ReflectionClass $reflection): array
    {
        $values = [];
        foreach ($reflection->getProperties() as $property) {
            $property->setAccessible(true);

            $propertyValue = $property->getValue($validatable);
            if ($propertyValue === null) {
                continue;
            }

            $values[$property->getName()] = $propertyValue;
        }

        $parentReflection = $reflection->getParentClass();
        if ($parentReflection !== false) {
            return $values + $this->extractPropertiesValues($validatable, $parentReflection);
        }

        return $values;
    }
}
validation/library/Exceptions/SlugException.php000064400000001506147361033760016001 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Carlos André Ferrari <caferrari@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class SlugException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid slug',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid slug',
        ],
    ];
}
validation/library/Exceptions/ContainsAnyException.php000064400000001422147361033760017312 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Kirill Dlussky <kirill@dlussky.ru>
 */
final class ContainsAnyException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain at least one of the values {{needles}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain any of the values {{needles}}',
        ],
    ];
}
validation/library/Exceptions/FilteredValidationException.php000064400000001221147361033760020632 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class FilteredValidationException extends ValidationException
{
    public const EXTRA = 'extra';

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('additionalChars') ? self::EXTRA : self::STANDARD;
    }
}
validation/library/Exceptions/NonOmissibleException.php000064400000000727147361033760017474 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andy Wendt <andy@awendt.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
interface NonOmissibleException extends Exception
{
}
validation/library/Exceptions/EqualsException.php000064400000001517147361033760016323 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ian Nisbet <ian@glutenite.co.uk>
 */
final class EqualsException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must equal {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not equal {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/BoolTypeException.php000064400000001477147361033760016633 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for BoolType rule.
 *
 * @author Devin Torres <devin@devintorres.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class BoolTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type boolean',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type boolean',
        ],
    ];
}
validation/library/Exceptions/AllOfException.php000064400000001663147361033760016070 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class AllOfException extends GroupedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NONE => 'All of the required rules must pass for {{name}}',
            self::SOME => 'These rules must pass for {{name}}',
        ],
        self::MODE_NEGATIVE => [
            self::NONE => 'None of these rules must pass for {{name}}',
            self::SOME => 'These rules must not pass for {{name}}',
        ],
    ];
}
validation/library/Exceptions/OptionalException.php000064400000001765147361033760016663 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class OptionalException extends ValidationException
{
    public const NAMED = 'named';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'The value must be optional',
            self::NAMED => '{{name}} must be optional',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'The value must not be optional',
            self::NAMED => '{{name}} must not be optional',
        ],
    ];

    protected function chooseTemplate(): string
    {
        return $this->getParam('name') ? self::NAMED : self::STANDARD;
    }
}
validation/library/Exceptions/MaxException.php000064400000001562147361033760015616 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Andrew Peters <amp343@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MaxException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be less than or equal to {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be less than or equal to {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/TimeException.php000064400000001416147361033760015765 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class TimeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid time in the format {{sample}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid time in the format {{sample}}',
        ],
    ];
}
validation/library/Exceptions/LessThanException.php000064400000001366147361033760016614 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LessThanException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be less than {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be less than {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/InfiniteException.php000064400000001446147361033760016637 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class InfiniteException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an infinite number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an infinite number',
        ],
    ];
}
validation/library/Exceptions/DigitException.php000064400000001754147361033760016134 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DigitException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only digits (0-9)',
            self::EXTRA => '{{name}} must contain only digits (0-9) and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain digits (0-9)',
            self::EXTRA => '{{name}} must not contain digits (0-9) and {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/UuidException.php000064400000002363147361033760015777 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Dick van der Heiden <d.vanderheiden@inthere.nl>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Michael Weimann <mail@michael-weimann.eu>
 */
final class UuidException extends ValidationException
{
    public const VERSION = 'version';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid UUID',
            self::VERSION => '{{name}} must be a valid UUID version {{version}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid UUID',
            self::VERSION => '{{name}} must not be a valid UUID version {{version}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('version')) {
            return self::VERSION;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/AlnumException.php000064400000002054147361033760016142 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class AlnumException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only letters (a-z) and digits (0-9)',
            self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain letters (a-z) or digits (0-9)',
            self::EXTRA => '{{name}} must not contain letters (a-z), digits (0-9) or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/KeyException.php000064400000002447147361033760015624 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions to be thrown by the Attribute Rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class KeyException extends NestedValidationException implements NonOmissibleException
{
    public const NOT_PRESENT = 'not_present';
    public const INVALID = 'invalid';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NOT_PRESENT => '{{name}} must be present',
            self::INVALID => '{{name}} must be valid',
        ],
        self::MODE_NEGATIVE => [
            self::NOT_PRESENT => '{{name}} must not be present',
            self::INVALID => '{{name}} must not be valid',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
    }
}
validation/library/Exceptions/TldException.php000064400000001701147361033760015607 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by Tld Rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Nick Lombard <github@jigsoft.co.za>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class TldException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid top-level domain name',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid top-level domain name',
        ],
    ];
}
validation/library/Exceptions/NotBlankException.php000064400000002207147361033760016576 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotBlankException extends ValidationException
{
    public const NAMED = 'named';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'The value must not be blank',
            self::NAMED => '{{name}} must not be blank',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'The value must be blank',
            self::NAMED => '{{name}} must be blank',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('input') || $this->getParam('name')) {
            return self::NAMED;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/EachException.php000064400000001545147361033760015732 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class EachException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'Each item in {{name}} must be valid',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'Each item in {{name}} must not validate',
        ],
    ];
}
validation/library/Exceptions/GroupedValidationException.php000064400000002433147361033760020507 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use function count;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class GroupedValidationException extends NestedValidationException
{
    public const NONE = 'none';
    public const SOME = 'some';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NONE => 'All of the required rules must pass for {{name}}',
            self::SOME => 'These rules must pass for {{name}}',
        ],
        self::MODE_NEGATIVE => [
            self::NONE => 'None of there rules must pass for {{name}}',
            self::SOME => 'These rules must not pass for {{name}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        $numRules = $this->getParam('passed');
        $numFailed = count($this->getChildren());

        return $numRules === $numFailed ? self::NONE : self::SOME;
    }
}
validation/library/Exceptions/FibonacciException.php000064400000001550147361033770016744 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
 */
final class FibonacciException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Fibonacci number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Fibonacci number',
        ],
    ];
}
validation/library/Exceptions/MinException.php000064400000001567147361033770015622 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MinException extends ValidationException
{
    public const INCLUSIVE = 'inclusive';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be greater than or equal to {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be greater than or equal to {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/BaseException.php000064400000001557147361033770015750 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Carlos André Ferrari <caferrari@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class BaseException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a number in the base {{base}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a number in the base {{base}}',
        ],
    ];
}
validation/library/Exceptions/CallableTypeException.php000064400000001411147361033770017424 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for CallableType rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class CallableTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be callable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be callable',
        ],
    ];
}
validation/library/Exceptions/NumericValException.php000064400000001510147361033770017130 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NumericValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be numeric',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be numeric',
        ],
    ];
}
validation/library/Exceptions/NfeAccessKeyException.php000064400000001542147361033770017373 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andrey Knupp Vital <andreykvital@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NfeAccessKeyException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid NFe access key',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid NFe access key',
        ],
    ];
}
validation/library/Exceptions/ComponentException.php000064400000001031147361033770017023 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use Exception;
use Throwable;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class ComponentException extends Exception implements Throwable
{
}
validation/library/Exceptions/ExecutableException.php000064400000001450147361033770017147 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class ExecutableException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an executable file',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an executable file',
        ],
    ];
}
validation/library/Exceptions/StringTypeException.php000064400000001443147361033770017200 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StringTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type string',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type string',
        ],
    ];
}
validation/library/Exceptions/EmailException.php000064400000001726147361033770016123 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by email rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Andrey Kolyshkin <a.kolyshkin@semrush.com>
 * @author Eduardo Gulias Davis <me@egulias.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class EmailException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be valid email',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an email',
        ],
    ];
}
validation/library/Exceptions/CallException.php000064400000001523147361033770015742 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class CallException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{input}} must be valid when executed with {{callable}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{input}} must not be valid when executed with {{callable}}',
        ],
    ];
}
validation/library/Exceptions/IdenticalException.php000064400000001375147361033770016770 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IdenticalException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be identical as {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be identical as {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/NoneOfException.php000064400000001466147361033770016261 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NoneOfException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'None of these rules must pass for {{name}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'All of these rules must pass for {{name}}',
        ],
    ];
}
validation/library/Exceptions/FileException.php000064400000001403147361033770015743 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FileException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a file',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a file',
        ],
    ];
}
validation/library/Exceptions/MaxAgeException.php000064400000001452147361033770016232 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MaxAgeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be {{age}} years or less',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be {{age}} years or less',
        ],
    ];
}
validation/library/Exceptions/MacAddressException.php000064400000001535147361033770017100 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Fábio da Silva Ribeiro <fabiorphp@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MacAddressException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid MAC address',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid MAC address',
        ],
    ];
}
validation/library/Exceptions/ControlException.php000064400000002056147361033770016511 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ControlException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only control characters',
            self::EXTRA => '{{name}} must contain only control characters and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain control characters',
            self::EXTRA => '{{name}} must not contain control characters or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/PostalCodeException.php000064400000001426147361033770017126 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PostalCodeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid postal code on {{countryCode}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid postal code on {{countryCode}}',
        ],
    ];
}
validation/library/Exceptions/StartsWithException.php000064400000001463147361033770017206 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StartsWithException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must start with {{startValue}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not start with {{startValue}}',
        ],
    ];
}
validation/library/Exceptions/FloatTypeException.php000064400000001474147361033770017003 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for FloatType rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Reginaldo Junior <76regi@gmail.com>
 */
final class FloatTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type float',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type float',
        ],
    ];
}
validation/library/Exceptions/VowelException.php000064400000001714147361033770016165 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 */
final class VowelException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only vowels',
            self::EXTRA => '{{name}} must contain only vowels and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain vowels',
            self::EXTRA => '{{name}} must not contain vowels or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/JsonException.php000064400000001541147361033770016000 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class JsonException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid JSON string',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid JSON string',
        ],
    ];
}
validation/library/Exceptions/KeySetException.php000064400000002501147361033770016270 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use function count;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class KeySetException extends GroupedValidationException implements NonOmissibleException
{
    public const STRUCTURE = 'structure';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NONE => 'All of the required rules must pass for {{name}}',
            self::SOME => 'These rules must pass for {{name}}',
            self::STRUCTURE => 'Must have keys {{keys}}',
        ],
        self::MODE_NEGATIVE => [
            self::NONE => 'None of these rules must pass for {{name}}',
            self::SOME => 'These rules must not pass for {{name}}',
            self::STRUCTURE => 'Must not have keys {{keys}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if (count($this->getChildren()) === 0) {
            return self::STRUCTURE;
        }

        return parent::chooseTemplate();
    }
}
validation/library/Exceptions/InstanceException.php000064400000001575147361033770016642 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class InstanceException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an instance of {{instanceName}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an instance of {{instanceName}}',
        ],
    ];
}
validation/library/Exceptions/SfException.php000064400000001457147361033770015445 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class SfException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be valid for {{constraint}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be valid for {{constraint}}',
        ],
    ];
}
validation/library/Exceptions/ZendException.php000064400000001051147361033770015763 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ZendException extends NestedValidationException
{
}
validation/library/Exceptions/ValidationException.php000064400000006453147361033770017170 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use InvalidArgumentException;
use Respect\Validation\Message\Formatter;

use function key;

/**
 * Default exception class for rule validations.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class ValidationException extends InvalidArgumentException implements Exception
{
    public const MODE_DEFAULT = 'default';
    public const MODE_NEGATIVE = 'negative';
    public const STANDARD = 'standard';

    /**
     * Contains the default templates for exception message.
     *
     * @var string[][]
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be valid',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be valid',
        ],
    ];

    /**
     * @var mixed
     */
    private $input;

    /**
     * @var string
     */
    private $id;

    /**
     * @var string
     */
    private $mode = self::MODE_DEFAULT;

    /**
     * @var mixed[]
     */
    private $params = [];

    /**
     * @var Formatter
     */
    private $formatter;

    /**
     * @var string
     */
    private $template;

    /**
     * @param mixed $input
     * @param mixed[] $params
     */
    public function __construct($input, string $id, array $params, Formatter $formatter)
    {
        $this->input = $input;
        $this->id = $id;
        $this->params = $params;
        $this->formatter = $formatter;
        $this->template = $this->chooseTemplate();

        parent::__construct($this->createMessage());
    }

    public function getId(): string
    {
        return $this->id;
    }

    /**
     * @return mixed[]
     */
    public function getParams(): array
    {
        return $this->params;
    }

    /**
     * @return mixed|null
     */
    public function getParam(string $name)
    {
        return $this->params[$name] ?? null;
    }

    public function updateMode(string $mode): void
    {
        $this->mode = $mode;
        $this->message = $this->createMessage();
    }

    public function updateTemplate(string $template): void
    {
        $this->template = $template;
        $this->message = $this->createMessage();
    }

    /**
     * @param mixed[] $params
     */
    public function updateParams(array $params): void
    {
        $this->params = $params;
        $this->message = $this->createMessage();
    }

    public function hasCustomTemplate(): bool
    {
        return isset($this->defaultTemplates[$this->mode][$this->template]) === false;
    }

    protected function chooseTemplate(): string
    {
        return (string) key($this->defaultTemplates[$this->mode]);
    }

    private function createMessage(): string
    {
        return $this->formatter->format(
            $this->defaultTemplates[$this->mode][$this->template] ?? $this->template,
            $this->input,
            $this->params
        );
    }

    public function __toString(): string
    {
        return $this->getMessage();
    }
}
validation/library/Exceptions/InException.php000064400000001527147361033770015441 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class InException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be in {{haystack}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be in {{haystack}}',
        ],
    ];
}
validation/library/Exceptions/Exception.php000064400000000733147361033770015150 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use Throwable;

/**
 * @author Andy Wendt <andy@awendt.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
interface Exception extends Throwable
{
}
validation/library/Exceptions/NotOptionalException.php000064400000002226147361033770017336 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotOptionalException extends ValidationException
{
    public const NAMED = 'named';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'The value must not be optional',
            self::NAMED => '{{name}} must not be optional',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'The value must be optional',
            self::NAMED => '{{name}} must be optional',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('input') || $this->getParam('name')) {
            return self::NAMED;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/KeyNestedException.php000064400000002527147361033770016767 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions to be thrown by the Attribute Rule.
 *
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ivan Zinovyev <vanyazin@gmail.com>
 */
final class KeyNestedException extends NestedValidationException implements NonOmissibleException
{
    public const NOT_PRESENT = 'not_present';
    public const INVALID = 'invalid';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NOT_PRESENT => 'No items were found for key chain {{name}}',
            self::INVALID => 'Key chain {{name}} is not valid',
        ],
        self::MODE_NEGATIVE => [
            self::NOT_PRESENT => 'Items for key chain {{name}} must not be present',
            self::INVALID => 'Key chain {{name}} must not be valid',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
    }
}
validation/library/Exceptions/NumberException.php000064400000001457147361033770016325 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 * @author Vitaliy <reboot.m@gmail.com>
 */
final class NumberException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a number',
        ],
    ];
}
validation/library/Exceptions/PhoneException.php000064400000001541147361033770016140 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Michael Firsikov <michael.firsikov@gmail.com>
 */
final class PhoneException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid telephone number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid telephone number',
        ],
    ];
}
validation/library/Exceptions/StringValException.php000064400000001412147361033770016775 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class StringValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a string',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be string',
        ],
    ];
}
validation/library/Exceptions/ArrayValException.php000064400000001533147361033770016611 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ArrayValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an array value',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an array value',
        ],
    ];
}
validation/library/Exceptions/WritableException.php000064400000001413147361033770016636 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class WritableException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be writable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be writable',
        ],
    ];
}
validation/library/Exceptions/IntTypeException.php000064400000001415147361033770016463 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for IntType rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IntTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type integer',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type integer',
        ],
    ];
}
validation/library/Exceptions/MultipleException.php000064400000001543147361033770016664 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class MultipleException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be multiple of {{multipleOf}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be multiple of {{multipleOf}}',
        ],
    ];
}
validation/library/Exceptions/NipException.php000064400000001477147361033770015625 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Tomasz Regdos <tomek@regdos.com>
 */
final class NipException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Polish VAT identification number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Polish VAT identification number',
        ],
    ];
}
validation/library/Exceptions/OneOfException.php000064400000001472147361033770016100 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Bradyn Poulsen <bradyn@bradynpoulsen.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class OneOfException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'Only one of these rules must pass for {{name}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'Only one of these rules must not pass for {{name}}',
        ],
    ];
}
validation/library/Exceptions/NegativeException.php000064400000001506147361033770016632 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 */
final class NegativeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be negative',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be negative',
        ],
    ];
}
validation/library/Exceptions/EndsWithException.php000064400000001543147361033770016616 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class EndsWithException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must end with {{endValue}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not end with {{endValue}}',
        ],
    ];
}
validation/library/Exceptions/ExtensionException.php000064400000001530147361033770017041 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for Extension rule.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ExtensionException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must have {{extension}} extension',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not have {{extension}} extension',
        ],
    ];
}
validation/library/Exceptions/NotException.php000064400000000766147361033770015637 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotException extends GroupedValidationException
{
}
validation/library/Exceptions/LowercaseException.php000064400000001502147361033770017010 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class LowercaseException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be lowercase',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be lowercase',
        ],
    ];
}
validation/library/Exceptions/UniqueException.php000064400000001563147361033770016341 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by Unique rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Krzysztof Śmiałek <admin@avensome.net>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class UniqueException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must not contain duplicates',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must contain duplicates',
        ],
    ];
}
validation/library/Exceptions/TypeException.php000064400000001455147361033770016014 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by Type rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class TypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be {{type}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be {{type}}',
        ],
    ];
}
validation/library/Exceptions/LeapDateException.php000064400000001424147361033770016546 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LeapDateException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be leap date',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be leap date',
        ],
    ];
}
validation/library/Exceptions/PrimeNumberException.php000064400000001532147361033770017314 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 */
final class PrimeNumberException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid prime number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid prime number',
        ],
    ];
}
validation/library/Exceptions/HexRgbColorException.php000064400000001431147361033770017243 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Davide Pastore <pasdavide@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class HexRgbColorException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a hex RGB color',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a hex RGB color',
        ],
    ];
}
validation/library/Exceptions/SubsetException.php000064400000001442147361033770016334 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Singwai Chan <singwai.chan@live.com>
 */
final class SubsetException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be subset of {{superset}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be subset of {{superset}}',
        ],
    ];
}
validation/library/Exceptions/NotEmptyException.php000064400000002312147361033770016643 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Bram Van der Sype <bram.vandersype@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NotEmptyException extends ValidationException
{
    public const NAMED = 'named';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'The value must not be empty',
            self::NAMED => '{{name}} must not be empty',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'The value must be empty',
            self::NAMED => '{{name}} must be empty',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('input') || $this->getParam('name')) {
            return self::NAMED;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/AlwaysInvalidException.php000064400000001733147361033770017641 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class AlwaysInvalidException extends ValidationException
{
    public const SIMPLE = 'simple';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is always invalid',
            self::SIMPLE => '{{name}} is not valid',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is always valid',
            self::SIMPLE => '{{name}} is valid',
        ],
    ];
}
validation/library/Exceptions/SortedException.php000064400000002424147361033770016330 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use Respect\Validation\Rules\Sorted;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Mikhail Vyrtsev <reeywhaar@gmail.com>
 */
final class SortedException extends ValidationException
{
    public const ASCENDING = 'ascending';
    public const DESCENDING = 'descending';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::ASCENDING => '{{name}} must be sorted in ascending order',
            self::DESCENDING => '{{name}} must be sorted in descending order',
        ],
        self::MODE_NEGATIVE => [
            self::ASCENDING => '{{name}} must not be sorted in ascending order',
            self::DESCENDING => '{{name}} must not be sorted in descending order',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('direction') === Sorted::ASCENDING ? self::ASCENDING : self::DESCENDING;
    }
}
validation/library/Exceptions/GreaterThanException.php000064400000001377147361033770017302 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class GreaterThanException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be greater than {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be greater than {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/RecursiveExceptionIterator.php000064400000003505147361033770020552 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use ArrayIterator;
use Countable;
use RecursiveIterator;
use UnexpectedValueException;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class RecursiveExceptionIterator implements RecursiveIterator, Countable
{
    /**
     * @var ArrayIterator<int, ValidationException>
     */
    private $exceptions;

    public function __construct(NestedValidationException $parent)
    {
        $this->exceptions = new ArrayIterator($parent->getChildren());
    }

    public function count(): int
    {
        return $this->exceptions->count();
    }

    public function hasChildren(): bool
    {
        if (!$this->valid()) {
            return false;
        }

        return $this->current() instanceof NestedValidationException;
    }

    public function getChildren(): self
    {
        $exception = $this->current();
        if (!$exception instanceof NestedValidationException) {
            throw new UnexpectedValueException();
        }

        return new static($exception);
    }

    /**
     * @return ValidationException|NestedValidationException
     */
    public function current(): ValidationException
    {
        return $this->exceptions->current();
    }

    public function key(): int
    {
        return (int) $this->exceptions->key();
    }

    public function next(): void
    {
        $this->exceptions->next();
    }

    public function rewind(): void
    {
        $this->exceptions->rewind();
    }

    public function valid(): bool
    {
        return $this->exceptions->valid();
    }
}
validation/library/Exceptions/FloatValException.php000064400000001533147361033770016600 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FloatValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a float number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a float number',
        ],
    ];
}
validation/library/Exceptions/DomainException.php000064400000001445147361033770016301 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DomainException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid domain',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid domain',
        ],
    ];
}
validation/library/Exceptions/PositiveException.php000064400000001506147361033770016672 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ismael Elias <ismael.esq@hotmail.com>
 */
final class PositiveException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be positive',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be positive',
        ],
    ];
}
validation/library/Exceptions/UppercaseException.php000064400000001502147361033770017013 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class UppercaseException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be uppercase',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be uppercase',
        ],
    ];
}
validation/library/Exceptions/ContainsException.php000064400000001577147361033770016656 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class ContainsException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain the value {{containsValue}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain the value {{containsValue}}',
        ],
    ];
}
validation/library/Exceptions/IntValException.php000064400000001537147361033770016271 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IntValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an integer number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an integer number',
        ],
    ];
}
validation/library/Exceptions/BsnException.php000064400000001471147361033770015613 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ronald Drenth <ronalddrenth@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class BsnException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a BSN',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a BSN',
        ],
    ];
}
validation/library/Exceptions/ImeiException.php000064400000001515147361033770015753 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Diego Oliveira <contato@diegoholiveira.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ImeiException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid IMEI',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid IMEI',
        ],
    ];
}
validation/library/Exceptions/SpaceException.php000064400000001761147361033770016126 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class SpaceException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only space characters',
            self::EXTRA => '{{name}} must contain only space characters and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain space characters',
            self::EXTRA => '{{name}} must not contain space characters or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/ExistsException.php000064400000001406147361033770016346 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class ExistsException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must exists',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not exists',
        ],
    ];
}
validation/library/Exceptions/BetweenException.php000064400000001524147361033770016461 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class BetweenException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be between {{minValue}} and {{maxValue}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be between {{minValue}} and {{maxValue}}',
        ],
    ];
}
validation/library/Exceptions/NoWhitespaceException.php000064400000001541147361033770017460 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NoWhitespaceException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must not contain whitespace',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must contain whitespace',
        ],
    ];
}
validation/library/Exceptions/VideoUrlException.php000064400000002361147361033770016621 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Ricardo Gobbo <ricardo@clicknow.com.br>
 */
final class VideoUrlException extends ValidationException
{
    public const SERVICE = 'service';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid video URL',
            self::SERVICE => '{{name}} must be a valid {{service}} video URL',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid video URL',
            self::SERVICE => '{{name}} must not be a valid {{service}} video URL',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('service')) {
            return self::SERVICE;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/Base64Exception.php000064400000001513147361033770016112 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jens Segers <segers.jens@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class Base64Exception extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be Base64-encoded',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be Base64-encoded',
        ],
    ];
}
validation/library/Exceptions/NotEmojiException.php000064400000001341147361033770016611 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class NotEmojiException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must not contain an Emoji',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must contain an Emoji',
        ],
    ];
}
validation/library/Exceptions/FactorException.php000064400000001536147361033770016311 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author David Meister <thedavidmeister@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FactorException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a factor of {{dividend}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a factor of {{dividend}}',
        ],
    ];
}
validation/library/Exceptions/CurrencyCodeException.php000064400000001530147361033770017452 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Justin Hook <justinhook88@yahoo.co.uk>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CurrencyCodeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid currency',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid currency',
        ],
    ];
}
validation/library/Exceptions/CharsetException.php000064400000001562147361033770016463 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CharsetException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be in the {{charset}} charset',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be in the {{charset}} charset',
        ],
    ];
}
validation/library/Exceptions/CpfException.php000064400000001524147361033770015600 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jair Henrique <jair.henrique@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CpfException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid CPF number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid CPF number',
        ],
    ];
}
validation/library/Exceptions/AttributeException.php000064400000002525147361033770017035 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions to be thrown by the Attribute Rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class AttributeException extends NestedValidationException implements NonOmissibleException
{
    public const NOT_PRESENT = 'not_present';
    public const INVALID = 'invalid';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::NOT_PRESENT => 'Attribute {{name}} must be present',
            self::INVALID => 'Attribute {{name}} must be valid',
        ],
        self::MODE_NEGATIVE => [
            self::NOT_PRESENT => 'Attribute {{name}} must not be present',
            self::INVALID => 'Attribute {{name}} must not validate',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
    }
}
validation/library/Exceptions/InvalidClassException.php000064400000000762147361033770017447 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception for invalid classes.
 *
 * @since 2.0.0
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class InvalidClassException extends ComponentException
{
}
validation/library/Exceptions/EquivalentException.php000064400000001400147361033770017176 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class EquivalentException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be equivalent to {{compareTo}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be equivalent to {{compareTo}}',
        ],
    ];
}
validation/library/Exceptions/UploadedException.php000064400000001570147361033770016626 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by Uploaded rule.
 *
 * @author Fajar Khairil <fajar.khairil@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class UploadedException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an uploaded file',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an uploaded file',
        ],
    ];
}
validation/library/Exceptions/FiniteException.php000064400000001427147361033770016310 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FiniteException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a finite number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a finite number',
        ],
    ];
}
validation/library/Exceptions/NestedValidationException.php000064400000015626147361033770020335 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use IteratorAggregate;
use RecursiveIteratorIterator;
use SplObjectStorage;

use function array_shift;
use function count;
use function current;
use function implode;
use function is_array;
use function is_string;
use function spl_object_hash;
use function sprintf;
use function str_repeat;

use const PHP_EOL;

/**
 * Exception for nested validations.
 *
 * This exception allows to have exceptions inside itself and providers methods
 * to handle them and to retrieve nested messages based on itself and its
 * children.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jonathan Stewmon <jstewmon@rmn.com>
 * @author Wojciech Frącz <fraczwojciech@gmail.com>
 *
 * @implements IteratorAggregate<ValidationException>
 */
class NestedValidationException extends ValidationException implements IteratorAggregate
{
    /**
     * @var ValidationException[]
     */
    private $exceptions = [];

    /**
     * Returns the exceptions that are children of the exception.
     *
     * @return ValidationException[]
     */
    public function getChildren(): array
    {
        return $this->exceptions;
    }

    /**
     * Adds a child to the exception.
     */
    public function addChild(ValidationException $exception): self
    {
        $this->exceptions[spl_object_hash($exception)] = $exception;

        return $this;
    }

    /**
     * Adds children to the exception.
     *
     * @param ValidationException[] $exceptions
     */
    public function addChildren(array $exceptions): self
    {
        foreach ($exceptions as $exception) {
            $this->addChild($exception);
        }

        return $this;
    }

    public function getIterator(): SplObjectStorage
    {
        $childrenExceptions = new SplObjectStorage();
        $recursiveIteratorIterator = $this->getRecursiveIterator();

        $lastDepth = 0;
        $lastDepthOriginal = 0;
        $knownDepths = [];
        foreach ($recursiveIteratorIterator as $childException) {
            if ($this->isOmissible($childException)) {
                continue;
            }

            $currentDepth = $lastDepth;
            $currentDepthOriginal = $recursiveIteratorIterator->getDepth() + 1;

            if (isset($knownDepths[$currentDepthOriginal])) {
                $currentDepth = $knownDepths[$currentDepthOriginal];
            } elseif ($currentDepthOriginal > $lastDepthOriginal) {
                ++$currentDepth;
            }

            if (!isset($knownDepths[$currentDepthOriginal])) {
                $knownDepths[$currentDepthOriginal] = $currentDepth;
            }

            $lastDepth = $currentDepth;
            $lastDepthOriginal = $currentDepthOriginal;

            $childrenExceptions->attach($childException, $currentDepth);
        }

        return $childrenExceptions;
    }

    /**
     * Returns a key->value array with all the messages of the exception.
     *
     * In this array the "keys" are the ids of the exceptions (defined name or
     * name of the rule) and the values are the message.
     *
     * Once templates are passed it overwrites the templates of the given
     * messages.
     *
     * @param string[]|string[][] $templates
     *
     * @return string[]
     */
    public function getMessages(array $templates = []): array
    {
        $messages = [$this->getId() => $this->renderMessage($this, $templates)];
        foreach ($this->getChildren() as $exception) {
            $id = $exception->getId();
            if (!$exception instanceof self) {
                $messages[$id] = $this->renderMessage(
                    $exception,
                    $this->findTemplates($templates, $this->getId())
                );
                continue;
            }

            $messages[$id] = $exception->getMessages($this->findTemplates($templates, $id, $this->getId()));
            if (count($messages[$id]) > 1) {
                continue;
            }

            $messages[$id] = current($messages[$exception->getId()]);
        }

        if (count($messages) > 1) {
            unset($messages[$this->getId()]);
        }

        return $messages;
    }

    /**
     * Returns a string with all the messages of the exception.
     */
    public function getFullMessage(): string
    {
        $messages = [];
        $leveler = 1;

        if (!$this->isOmissible($this)) {
            $leveler = 0;
            $messages[] = sprintf('- %s', $this->getMessage());
        }

        $exceptions = $this->getIterator();
        /** @var ValidationException $exception */
        foreach ($exceptions as $exception) {
            $messages[] = sprintf(
                '%s- %s',
                str_repeat(' ', (int) ($exceptions[$exception] - $leveler) * 2),
                $exception->getMessage()
            );
        }

        return implode(PHP_EOL, $messages);
    }

    private function getRecursiveIterator(): RecursiveIteratorIterator
    {
        return new RecursiveIteratorIterator(
            new RecursiveExceptionIterator($this),
            RecursiveIteratorIterator::SELF_FIRST
        );
    }

    private function isOmissible(Exception $exception): bool
    {
        if (!$exception instanceof self) {
            return false;
        }

        if (count($exception->getChildren()) !== 1) {
            return false;
        }

        /** @var ValidationException $childException */
        $childException = current($exception->getChildren());
        if ($childException->getMessage() === $exception->getMessage()) {
            return true;
        }

        if ($exception->hasCustomTemplate()) {
            return $childException->hasCustomTemplate();
        }

        return !$childException instanceof NonOmissibleException;
    }

    /**
     * @param string[]|string[][] $templates
     */
    private function renderMessage(ValidationException $exception, array $templates): string
    {
        if (isset($templates[$exception->getId()]) && is_string($templates[$exception->getId()])) {
            $exception->updateTemplate($templates[$exception->getId()]);
        }

        return $exception->getMessage();
    }

    /**
     * @param string[]|string[][] $templates
     * @param mixed ...$ids
     *
     * @return string[]|string[][]
     */
    private function findTemplates(array $templates, ...$ids): array
    {
        while (count($ids) > 0) {
            $id = array_shift($ids);
            if (!isset($templates[$id])) {
                continue;
            }

            if (!is_array($templates[$id])) {
                continue;
            }

            $templates = $templates[$id];
        }

        return $templates;
    }
}
validation/library/Exceptions/ObjectTypeException.php000064400000001516147361033770017141 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for ObjectType rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ObjectTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type object',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type object',
        ],
    ];
}
validation/library/Exceptions/CountableException.php000064400000001504147361033770017002 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author João Torquato <joao.otl@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CountableException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be countable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be countable',
        ],
    ];
}
validation/library/Exceptions/OddException.php000064400000001504147361033770015574 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class OddException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an odd number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an odd number',
        ],
    ];
}
validation/library/Exceptions/CnpjException.php000064400000001522147361033770015760 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Leonn Leite <leonnleite@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CnpjException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid CNPJ number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid CNPJ number',
        ],
    ];
}
validation/library/Exceptions/MinAgeException.php000064400000001527147361033770016233 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class MinAgeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be {{age}} years or more',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be {{age}} years or more',
        ],
    ];
}
validation/library/Exceptions/RegexException.php000064400000001543147361033770016143 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class RegexException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must validate against {{regex}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not validate against {{regex}}',
        ],
    ];
}
validation/library/Exceptions/DirectoryException.php000064400000001431147361033770017031 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class DirectoryException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a directory',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a directory',
        ],
    ];
}
validation/library/Exceptions/FilterVarException.php000064400000000670147361033770016767 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FilterVarException extends ValidationException
{
}
validation/library/Exceptions/CallbackException.php000064400000001064147361033770016563 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CallbackException extends NestedValidationException
{
}
validation/library/Exceptions/LengthException.php000064400000005226147361033770016314 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class LengthException extends ValidationException
{
    public const BOTH = 'both';
    public const LOWER = 'lower';
    public const LOWER_INCLUSIVE = 'lower_inclusive';
    public const GREATER = 'greater';
    public const GREATER_INCLUSIVE = 'greater_inclusive';
    public const EXACT = 'exact';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
            self::LOWER => '{{name}} must have a length greater than {{minValue}}',
            self::LOWER_INCLUSIVE => '{{name}} must have a length greater than or equal to {{minValue}}',
            self::GREATER => '{{name}} must have a length lower than {{maxValue}}',
            self::GREATER_INCLUSIVE => '{{name}} must have a length lower than or equal to {{maxValue}}',
            self::EXACT => '{{name}} must have a length of {{maxValue}}',
        ],
        self::MODE_NEGATIVE => [
            self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}',
            self::LOWER => '{{name}} must not have a length greater than {{minValue}}',
            self::LOWER_INCLUSIVE => '{{name}} must not have a length greater than or equal to {{minValue}}',
            self::GREATER => '{{name}} must not have a length lower than {{maxValue}}',
            self::GREATER_INCLUSIVE => '{{name}} must not have a length lower than or equal to {{maxValue}}',
            self::EXACT => '{{name}} must not have a length of {{maxValue}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        $isInclusive = $this->getParam('inclusive');

        if (!$this->getParam('minValue')) {
            return $isInclusive === true ? self::GREATER_INCLUSIVE : self::GREATER;
        }

        if (!$this->getParam('maxValue')) {
            return $isInclusive === true ? self::LOWER_INCLUSIVE : self::LOWER;
        }

        if ($this->getParam('minValue') == $this->getParam('maxValue')) {
            return self::EXACT;
        }

        return self::BOTH;
    }
}
validation/library/Exceptions/LanguageCodeException.php000064400000001612147361033770017404 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LanguageCodeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid ISO 639 {{set}} language code',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid ISO 639 {{set}} language code',
        ],
    ];
}
validation/library/Exceptions/DateException.php000064400000001505147361033770015744 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Bruno Luiz da Silva <contato@brunoluiz.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DateException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid date in the format {{sample}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid date in the format {{sample}}',
        ],
    ];
}
validation/library/Exceptions/IterableTypeException.php000064400000001334147361033770017460 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class IterableTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be iterable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be iterable',
        ],
    ];
}
validation/library/Exceptions/RomanException.php000064400000001434147361033770016144 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 */
final class RomanException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Roman numeral',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Roman numeral',
        ],
    ];
}
validation/library/Exceptions/PhpLabelException.php000064400000001527147361033770016562 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PhpLabelException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid PHP label',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid PHP label',
        ],
    ];
}
validation/library/Exceptions/CountryCodeException.php000064400000001540147361033770017324 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CountryCodeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid country',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid country',
        ],
    ];
}
validation/library/Exceptions/IsbnException.php000064400000001403147361033770015757 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Moritz Fromm <moritzgitfromm@gmail.com>
 */
final class IsbnException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a ISBN',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a ISBN',
        ],
    ];
}
validation/library/Exceptions/ReadableException.php000064400000001413147361033770016564 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ReadableException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be readable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be readable',
        ],
    ];
}
validation/library/Exceptions/YesException.php000064400000001410147361033770015622 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Cameron Hall <me@chall.id.au>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class YesException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is not considered as "Yes"',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is considered as "Yes"',
        ],
    ];
}
validation/library/Exceptions/SubdivisionCodeException.php000064400000001423147361033770020157 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
class SubdivisionCodeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a subdivision code of {{countryName}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a subdivision code of {{countryName}}',
        ],
    ];
}
validation/library/Exceptions/NoException.php000064400000001334147361033770015443 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NoException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is not considered as "No"',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is considered as "No"',
        ],
    ];
}
validation/library/Exceptions/MimetypeException.php000064400000001524147361033770016661 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for Mimetype rule.
 *
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class MimetypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must have {{mimetype}} MIME type',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not have {{mimetype}} MIME type',
        ],
    ];
}
validation/library/Exceptions/DateTimeException.php000064400000002262147361033770016564 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DateTimeException extends ValidationException
{
    public const FORMAT = 'format';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid date/time',
            self::FORMAT => '{{name}} must be a valid date/time in the format {{sample}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid date/time',
            self::FORMAT => '{{name}} must not be a valid date/time in the format {{sample}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        return $this->getParam('format') ? self::FORMAT : self::STANDARD;
    }
}
validation/library/Exceptions/PerfectSquareException.php000064400000001551147361033770017641 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 */
final class PerfectSquareException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid perfect square',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid perfect square',
        ],
    ];
}
validation/library/Exceptions/UrlException.php000064400000001315147361033770015630 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class UrlException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a URL',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a URL',
        ],
    ];
}
validation/library/Exceptions/PrintableException.php000064400000002265147361033770017013 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions to be thrown by the Printable Rule.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PrintableException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only printable characters',
            self::EXTRA => '{{name}} must contain only printable characters and "{{additionalChars}}"',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain printable characters',
            self::EXTRA => '{{name}} must not contain printable characters or "{{additionalChars}}"',
        ],
    ];
}
validation/library/Exceptions/ValidatorException.php000064400000000663147361033770017020 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ValidatorException extends AllOfException
{
}
validation/library/Exceptions/NifException.php000064400000001401147361033770015576 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Julián Gutiérrez <juliangut@gmail.com>
 */
final class NifException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a NIF',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a NIF',
        ],
    ];
}
validation/library/Exceptions/SizeException.php000064400000002753147361033770016007 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for Size rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class SizeException extends NestedValidationException
{
    public const BOTH = 'both';
    public const LOWER = 'lower';
    public const GREATER = 'greater';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::BOTH => '{{name}} must be between {{minSize}} and {{maxSize}}',
            self::LOWER => '{{name}} must be greater than {{minSize}}',
            self::GREATER => '{{name}} must be lower than {{maxSize}}',
        ],
        self::MODE_NEGATIVE => [
            self::BOTH => '{{name}} must not be between {{minSize}} and {{maxSize}}',
            self::LOWER => '{{name}} must not be greater than {{minSize}}',
            self::GREATER => '{{name}} must not be lower than {{maxSize}}',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if (!$this->getParam('minValue')) {
            return self::GREATER;
        }

        if (!$this->getParam('maxValue')) {
            return self::LOWER;
        }

        return self::BOTH;
    }
}
validation/library/Exceptions/IpException.php000064400000002537147361033770015445 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
 */
final class IpException extends ValidationException
{
    public const NETWORK_RANGE = 'network_range';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an IP address',
            self::NETWORK_RANGE => '{{name}} must be an IP address in the {{range}} range',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an IP address',
            self::NETWORK_RANGE => '{{name}} must not be an IP address in the {{range}} range',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if (!$this->getParam('range')) {
            return self::STANDARD;
        }

        return self::NETWORK_RANGE;
    }
}
validation/library/Exceptions/AlphaException.php000064400000001757147361033770016125 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class AlphaException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only letters (a-z)',
            self::EXTRA => '{{name}} must contain only letters (a-z) and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain letters (a-z)',
            self::EXTRA => '{{name}} must not contain letters (a-z) or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/PunctException.php000064400000002074147361033770016162 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PunctException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only punctuation characters',
            self::EXTRA => '{{name}} must contain only punctuation characters and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain punctuation characters',
            self::EXTRA => '{{name}} must not contain punctuation characters or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/ConsonantException.php000064400000002023147361033770017025 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Kleber Hamada Sato <kleberhs007@yahoo.com>
 */
final class ConsonantException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only consonants',
            self::EXTRA => '{{name}} must contain only consonants and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain consonants',
            self::EXTRA => '{{name}} must not contain consonants or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/TrueValException.php000064400000001501147361033770016445 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions thrown by TrueVal rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class TrueValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is not considered as "True"',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is considered as "True"',
        ],
    ];
}
validation/library/Exceptions/ResourceTypeException.php000064400000001410147361033770017513 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for ResourceType.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ResourceTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a resource',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a resource',
        ],
    ];
}
validation/library/Exceptions/NullableException.php000064400000002207147361033770016625 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jens Segers <segers.jens@gmail.com>
 */
final class NullableException extends ValidationException
{
    public const NAMED = 'named';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'The value must be nullable',
            self::NAMED => '{{name}} must be nullable',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'The value must not be null',
            self::NAMED => '{{name}} must not be null',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('input') || $this->getParam('name')) {
            return self::NAMED;
        }

        return self::STANDARD;
    }
}
validation/library/Exceptions/PolishIdCardException.php000064400000001422147361033770017372 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PolishIdCardException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Polish Identity Card number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Polish Identity Card number',
        ],
    ];
}
validation/library/Exceptions/AnyOfException.php000064400000001512147361033770016101 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class AnyOfException extends NestedValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'At least one of these rules must pass for {{name}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'At least one of these rules must not pass for {{name}}',
        ],
    ];
}
validation/library/Exceptions/FalseValException.php000064400000001433147361033770016564 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class FalseValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is not considered as "False"',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is considered as "False"',
        ],
    ];
}
validation/library/Exceptions/SymbolicLinkException.php000064400000001437147361033770017472 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Gus Antoniassi <gus.antoniassi@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class SymbolicLinkException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a symbolic link',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a symbolic link',
        ],
    ];
}
validation/library/Exceptions/ArrayTypeException.php000064400000001611147361033770017005 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author João Torquato <joao.otl@gmail.com>
 */
final class ArrayTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be of type array',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be of type array',
        ],
    ];
}
validation/library/Exceptions/LuhnException.php000064400000001517147361033770016000 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexander Gorshkov <mazanax@yandex.ru>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LuhnException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Luhn number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Luhn number',
        ],
    ];
}
validation/library/Exceptions/XdigitException.php000064400000001760147361033770016322 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class XdigitException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} contain only hexadecimal digits',
            self::EXTRA => '{{name}} contain only hexadecimal digits and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain hexadecimal digits',
            self::EXTRA => '{{name}} must not contain hexadecimal digits or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/CreditCardException.php000064400000002520147361033770017071 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

use Respect\Validation\Rules\CreditCard;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CreditCardException extends ValidationException
{
    public const BRANDED = 'branded';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid Credit Card number',
            self::BRANDED => '{{name}} must be a valid {{brand}} Credit Card number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid Credit Card number',
            self::BRANDED => '{{name}} must not be a valid {{brand}} Credit Card number',
        ],
    ];

    /**
     * {@inheritDoc}
     */
    protected function chooseTemplate(): string
    {
        if ($this->getParam('brand') === CreditCard::ANY) {
            return self::STANDARD;
        }

        return self::BRANDED;
    }
}
validation/library/Exceptions/ScalarValException.php000064400000001345147361033770016741 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ScalarValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a scalar value',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a scalar value',
        ],
    ];
}
validation/library/Exceptions/IbanException.php000064400000001333147361033770015737 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Mazen Touati <mazen_touati@hotmail.com>
 */
final class IbanException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid IBAN',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid IBAN',
        ],
    ];
}
validation/library/Exceptions/CnhException.php000064400000001523147361033770015577 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Kinn Coelho Julião <kinncj@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class CnhException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid CNH number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid CNH number',
        ],
    ];
}
validation/library/Exceptions/KeyValueException.php000064400000002112147361033770016607 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class KeyValueException extends ValidationException
{
    public const COMPONENT = 'component';

    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => 'Key {{name}} must be present',
            self::COMPONENT => '{{baseKey}} must be valid to validate {{comparedKey}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => 'Key {{name}} must not be present',
            self::COMPONENT => '{{baseKey}} must not be valid to validate {{comparedKey}}',
        ],
    ];

    protected function chooseTemplate(): string
    {
        return $this->getParam('component') ? self::COMPONENT : self::STANDARD;
    }
}
validation/library/Exceptions/GraphException.php000064400000002064147361033770016131 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Andre Ramaciotti <andre@ramaciotti.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class GraphException extends FilteredValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must contain only graphical characters',
            self::EXTRA => '{{name}} must contain only graphical characters and {{additionalChars}}',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not contain graphical characters',
            self::EXTRA => '{{name}} must not contain graphical characters or {{additionalChars}}',
        ],
    ];
}
validation/library/Exceptions/EvenException.php000064400000001560147361033770015765 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exceptions to be thrown by the Even Rule.
 *
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Jean Pimentel <jeanfap@gmail.com>
 * @author Paul Karikari <paulkarikari1@gmail.com>
 */
final class EvenException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be an even number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be an even number',
        ],
    ];
}
validation/library/Exceptions/WhenException.php000064400000001037147361033770015770 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Antonio Spinelli <tonicospinelli85@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class WhenException extends ValidationException
{
}
validation/library/Exceptions/NullTypeException.php000064400000001461147361033770016644 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * Exception class for NullType.
 *
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class NullTypeException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be null',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be null',
        ],
    ];
}
validation/library/Exceptions/VersionException.php000064400000001414147361033770016513 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class VersionException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a version',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a version',
        ],
    ];
}
validation/library/Exceptions/ImageException.php000064400000001515147361033770016112 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Benevides <danilobenevides01@gmail.com>
 * @author Guilherme Siani <guilherme@siani.com.br>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class ImageException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid image',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid image',
        ],
    ];
}
validation/library/Exceptions/DecimalException.php000064400000001365147361033770016431 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class DecimalException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must have {{decimals}} decimals',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not have {{decimals}} decimals',
        ],
    ];
}
validation/library/Exceptions/LeapYearException.php000064400000001421147361033770016566 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class LeapYearException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a leap year',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a leap year',
        ],
    ];
}
validation/library/Exceptions/BoolValException.php000064400000001531147361033770016424 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class BoolValException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a boolean value',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a boolean value',
        ],
    ];
}
validation/library/Exceptions/AlwaysValidException.php000064400000001516147361033770017311 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author William Espindola <oi@williamespindola.com.br>
 */
final class AlwaysValidException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} is always valid',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} is always invalid',
        ],
    ];
}
validation/library/Exceptions/PisException.php000064400000001511147361033770015617 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Bruno Koga <brunokoga187@gmail.com>
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
final class PisException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid PIS number',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid PIS number',
        ],
    ];
}
validation/library/Exceptions/PeselException.php000064400000001476147361033770016146 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
 * @author Danilo Correa <danilosilva87@gmail.com>
 * @author Henrique Moody <henriquemoody@gmail.com>
 * @author Tomasz Regdos <tomek@regdos.com>
 */
final class PeselException extends ValidationException
{
    /**
     * {@inheritDoc}
     */
    protected $defaultTemplates = [
        self::MODE_DEFAULT => [
            self::STANDARD => '{{name}} must be a valid PESEL',
        ],
        self::MODE_NEGATIVE => [
            self::STANDARD => '{{name}} must not be a valid PESEL',
        ],
    ];
}
validation/library/Validatable.php000064400000002166147361033770013303 0ustar00<?php

/*
 * This file is part of Respect/Validation.
 *
 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 */

declare(strict_types=1);

namespace Respect\Validation;

use Respect\Validation\Exceptions\ValidationException;

/** Interface for validation rules */
/**
 * @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
 * @author Henrique Moody <henriquemoody@gmail.com>
 */
interface Validatable
{
    /**
     * @param mixed $input
     */
    public function assert($input): void;

    /**
     * @param mixed $input
     */
    public function check($input): void;

    public function getName(): ?string;

    /**
     * @param mixed $input
     * @param mixed[] $extraParameters
     */
    public function reportError($input, array $extraParameters = []): ValidationException;

    public function setName(string $name): Validatable;

    public function setTemplate(string $template): Validatable;

    /**
     * @param mixed $input
     */
    public function validate($input): bool;
}