2015-09-21 18:28:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
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;
|
|
|
|
|
2023-02-18 22:09:26 +01:00
|
|
|
use Respect\Validation\Helpers\CountryInfo;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2021-03-19 14:59:31 +01:00
|
|
|
use function array_keys;
|
2019-03-11 00:40:14 +01:00
|
|
|
|
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
|
|
|
*/
|
2021-03-19 14:59:31 +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
|
|
|
|
*/
|
2023-02-18 17:38:47 +01:00
|
|
|
private $countryName;
|
2019-03-11 00:40:14 +01:00
|
|
|
|
|
|
|
/**
|
2021-03-19 14:59:31 +01:00
|
|
|
* @var string[]
|
2019-03-11 00:40:14 +01:00
|
|
|
*/
|
2023-02-18 22:09:26 +01:00
|
|
|
private $countryInfo;
|
2019-03-11 00:40:14 +01:00
|
|
|
|
|
|
|
public function __construct(string $countryCode)
|
|
|
|
{
|
2023-02-18 22:09:26 +01:00
|
|
|
$countryInfo = new CountryInfo($countryCode);
|
2019-03-11 00:40:14 +01:00
|
|
|
|
2023-02-18 22:09:26 +01:00
|
|
|
$this->countryName = $countryInfo->getCountry();
|
|
|
|
$this->countryInfo = array_keys($countryInfo->getSubdivisions());
|
2019-03-11 00:40:14 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2021-03-19 14:59:31 +01:00
|
|
|
protected function getDataSource(): array
|
2015-09-21 18:28:59 +02:00
|
|
|
{
|
2023-02-18 22:09:26 +01:00
|
|
|
return $this->countryInfo;
|
2015-09-21 18:28:59 +02:00
|
|
|
}
|
|
|
|
}
|