HighSpeaker/vendor/workerman/validation/library/Rules/SubdivisionCode.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2022-12-24 22:10:40 +08:00
<?php
/*
2024-01-31 22:15:08 +08:00
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2022-12-24 22:10:40 +08:00
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
2024-01-31 22:15:08 +08:00
use Respect\Validation\Helpers\CountryInfo;
2022-12-24 22:10:40 +08:00
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[]
*/
2024-01-31 22:15:08 +08:00
private $countryInfo;
2022-12-24 22:10:40 +08:00
public function __construct(string $countryCode)
{
2024-01-31 22:15:08 +08:00
$countryInfo = new CountryInfo($countryCode);
2022-12-24 22:10:40 +08:00
2024-01-31 22:15:08 +08:00
$this->countryName = $countryInfo->getCountry();
$this->countryInfo = array_keys($countryInfo->getSubdivisions());
2022-12-24 22:10:40 +08:00
}
/**
* {@inheritDoc}
*/
2024-01-31 22:15:08 +08:00
protected function getDataSource($input = null): array
2022-12-24 22:10:40 +08:00
{
2024-01-31 22:15:08 +08:00
return $this->countryInfo;
2022-12-24 22:10:40 +08:00
}
}