2015-09-21 18:28:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
2019-05-23 16:21:34 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
|
|
* that was distributed with this source code.
|
2015-09-21 18:28:59 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-09-21 18:28:59 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2019-03-11 00:40:14 +01:00
|
|
|
use Respect\Validation\Helpers\Subdivisions;
|
|
|
|
use function array_keys;
|
|
|
|
|
2015-09-21 18:28:59 +02:00
|
|
|
/**
|
|
|
|
* Validates country subdivision codes according to ISO 3166-2.
|
|
|
|
*
|
2017-11-19 19:01:31 +01:00
|
|
|
* @see http://en.wikipedia.org/wiki/ISO_3166-2
|
|
|
|
* @see http://www.geonames.org/countries/
|
2018-01-28 13:14:15 +01:00
|
|
|
*
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2019-03-11 00:40:14 +01:00
|
|
|
* @author Mazen Touati <mazen_touati@hotmail.com>
|
2015-09-21 18:28:59 +02:00
|
|
|
*/
|
2019-03-11 00:40:14 +01:00
|
|
|
final class SubdivisionCode extends AbstractSearcher
|
2015-09-21 18:28:59 +02:00
|
|
|
{
|
2019-03-11 00:40:14 +01:00
|
|
|
/**
|
|
|
|
* @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());
|
|
|
|
}
|
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-28 13:14:15 +01:00
|
|
|
*/
|
2019-03-11 00:40:14 +01:00
|
|
|
protected function getDataSource(): array
|
2015-09-21 18:28:59 +02:00
|
|
|
{
|
2019-03-11 00:40:14 +01:00
|
|
|
return $this->subdivisions;
|
2015-09-21 18:28:59 +02:00
|
|
|
}
|
|
|
|
}
|