blob: 0df2b60ba3a1f25d000b3eab1e61e49c34ac5444 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php
declare(strict_types=1);
namespace Zhineng\RegionChina\Build;
use Symfony\Component\VarExporter\VarExporter;
final class TopLevelHandler implements RegionHandler
{
/**
* A list of top-level region codes.
*
* @var int[]
*/
private array $data = [];
public function handle(string $code, string $name): void
{
if (! $this->isProvince($code)) {
return;
}
$this->data[] = (int) $code;
}
private function isProvince(string $code): bool
{
return substr($code, -4) === '0000';
}
public function export(string $destination): void
{
$exported = VarExporter::export($this->data);
file_put_contents($destination, sprintf('<?php return %s;'.PHP_EOL,
$exported
));
}
}
|