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

53 lines
1.1 KiB
PHP
Raw Normal View History

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