1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ICanBoogie\CLDR\Generator\Command; |
4
|
|
|
|
5
|
|
|
use ICanBoogie\CLDR\Repository; |
6
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\VarExporter\VarExporter; |
11
|
|
|
|
12
|
|
|
use function ICanBoogie\CLDR\Generator\indent; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Generates `CalendarPreferenceData.php` from |
16
|
|
|
* {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-core/supplemental/calendarPreferenceData.json}. |
17
|
|
|
*/ |
18
|
|
|
#[AsCommand(self::GENERATED_FILE)] |
19
|
|
|
final class GenerateCalendarPreferenceData extends Command |
20
|
|
|
{ |
21
|
|
|
private const GENERATED_FILE = 'src/Supplemental/CalendarPreferenceData.php'; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
private readonly Repository $repository, |
25
|
|
|
) { |
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
30
|
|
|
{ |
31
|
|
|
$by_region = $this->repository->supplemental['calendarPreferenceData']; |
32
|
|
|
|
33
|
|
|
$contents = $this->render( |
34
|
|
|
by_region: indent(VarExporter::export($by_region), 2), |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
file_put_contents(self::GENERATED_FILE, $contents); |
38
|
|
|
|
39
|
|
|
return self::SUCCESS; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
private function render( |
43
|
|
|
string $by_region, |
44
|
|
|
): string { |
45
|
|
|
$class = __CLASS__; |
46
|
|
|
|
47
|
|
|
return <<<PHP |
48
|
|
|
<?php |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* CODE GENERATED; DO NOT EDIT. |
52
|
|
|
* |
53
|
|
|
* {@see \\$class} |
54
|
|
|
*/ |
55
|
|
|
|
56
|
|
|
namespace ICanBoogie\CLDR\Supplemental; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @codeCoverageIgnore |
60
|
|
|
*/ |
61
|
|
|
final class CalendarPreferenceData |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* @link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-core/supplemental/calendarPreferenceData.json |
65
|
|
|
*/ |
66
|
|
|
public const BY_REGION = |
67
|
|
|
$by_region; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the preference calendar for a region. |
71
|
|
|
*/ |
72
|
|
|
public static function preferred_calendar_for_region(string \$region): string |
73
|
|
|
{ |
74
|
|
|
\$preference = self::BY_REGION[\$region] ?? self::BY_REGION['001']; |
75
|
|
|
|
76
|
|
|
return current(\$preference); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
PHP; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|