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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
namespace ICanBoogie\CLDR;
use ICanBoogie\OffsetNotDefined;
class Supplemental implements \ArrayAccess
{
use CollectionTrait;
use RepositoryPropertyTrait;
static private $available_sections = [
'calendarData' => 'calendarData',
'calendarPreferenceData' => 'calendarPreferenceData',
'characterFallbacks' => 'characters/character-fallback',
'codeMappings' => 'codeMappings',
'currencyData' => 'currencyData',
'dayPeriods' => 'dayPeriodRuleSet',
'gender' => 'gender',
'languageData' => 'languageData',
'languageMatching' => 'languageMatching',
'likelySubtags' => 'likelySubtags',
'measurementData' => 'measurementData',
'metaZones' => 'metaZones',
'numberingSystems' => 'numberingSystems',
'ordinals' => 'plurals-type-ordinal',
'parentLocales' => 'parentLocales',
'plurals' => 'plurals-type-cardinal',
'postalCodeData' => 'postalCodeData',
'primaryZones' => 'primaryZones',
'references' => 'references',
'telephoneCodeData' => 'telephoneCodeData',
'territoryContainment' => 'territoryContainment',
'territoryInfo' => 'territoryInfo',
'timeData' => 'timeData',
'weekData' => 'weekData',
'windowsZones' => 'windowsZones'
];
protected $sections = [];
public function __construct(Repository $repository)
{
$this->repository = $repository;
}
public function offsetExists($offset)
{
return isset(self::$available_sections[$offset]);
}
public function offsetGet($offset)
{
if (isset($this->sections[$offset]))
{
return $this->sections[$offset];
}
if (empty(self::$available_sections[$offset]))
{
throw new OffsetNotDefined([ $offset, $this ]);
}
$data = $this->repository->fetch("supplemental/{$offset}");
$path = 'supplemental/' . self::$available_sections[$offset];
$path_parts = explode('/', $path);
foreach ($path_parts as $part)
{
$data = $data[$part];
}
return $this->sections[$offset] = $data;
}
}