From 00b41e1fc5e06863f1788ce974beff9609a760e4 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 21 Sep 2015 13:27:42 -0300 Subject: [PATCH] Create "SeSubdivisionCode" rule --- .../SeSubdivisionCodeException.php | 31 ++++++++++++ .../SubdivisionCode/SeSubdivisionCode.php | 50 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 library/Exceptions/SubdivisionCode/SeSubdivisionCodeException.php create mode 100644 library/Rules/SubdivisionCode/SeSubdivisionCode.php diff --git a/library/Exceptions/SubdivisionCode/SeSubdivisionCodeException.php b/library/Exceptions/SubdivisionCode/SeSubdivisionCodeException.php new file mode 100644 index 00000000..f07ad870 --- /dev/null +++ b/library/Exceptions/SubdivisionCode/SeSubdivisionCodeException.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Exceptions\SubdivisionCode; + +use Respect\Validation\Exceptions\SubdivisionCodeException; + +/** + * Exception class for Sweden subdivision code. + * + * ISO 3166-1 alpha-2: SE + */ +class SeSubdivisionCodeException extends SubdivisionCodeException +{ + public static $defaultTemplates = array( + self::MODE_DEFAULT => array( + self::STANDARD => '{{name}} must be a subdivision code of Sweden', + ), + self::MODE_NEGATIVE => array( + self::STANDARD => '{{name}} must not be a subdivision code of Sweden', + ), + ); +} diff --git a/library/Rules/SubdivisionCode/SeSubdivisionCode.php b/library/Rules/SubdivisionCode/SeSubdivisionCode.php new file mode 100644 index 00000000..a8383f50 --- /dev/null +++ b/library/Rules/SubdivisionCode/SeSubdivisionCode.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Rules\SubdivisionCode; + +use Respect\Validation\Rules\AbstractSearcher; + +/** + * Validator for Sweden subdivision code. + * + * ISO 3166-1 alpha-2: SE + * + * @link http://www.geonames.org/SE/administrative-division-sweden.html + */ +class SeSubdivisionCode extends AbstractSearcher +{ + public $haystack = array( + '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 + ); + + public $compareIdentical = true; +}