1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\CLDR;
13
14 15 16 17 18 19 20 21 22 23 24 25 26
27 class Supplemental implements \ArrayAccess
28 {
29 static private $available_sections = array
30 (
31 'calendarData' => 'calendarData',
32 'calendarPreferenceData' => 'calendarPreferenceData',
33 'characterFallbacks' => 'characters/character-fallback',
34 'codeMappings' => 'codeMappings',
35 'currencyData' => 'currencyData',
36 'dayPeriods' => 'dayPeriodRuleSet',
37 'gender' => 'gender',
38 'languageData' => 'languageData',
39 'languageMatching' => 'languageMatching',
40 'likelySubtags' => 'likelySubtags',
41 'measurementData' => 'measurementData',
42 'metaZones' => 'metaZones',
43 'numberingSystems' => 'numberingSystems',
44 'ordinals' => 'plurals-type-ordinal',
45 'parentLocales' => 'parentLocales',
46 'plurals' => 'plurals-type-cardinal',
47 'postalCodeData' => 'postalCodeData',
48 'primaryZones' => 'primaryZones',
49 'references' => 'references',
50 'telephoneCodeData' => 'telephoneCodeData',
51 'territoryContainment' => 'territoryContainment',
52 'territoryInfo' => 'territoryInfo',
53 'timeData' => 'timeData',
54 'weekData' => 'weekData',
55 'windowsZones' => 'windowsZones'
56 );
57
58 59 60 61 62
63 protected $repository;
64
65 66 67 68 69
70 protected $sections = array();
71
72 73 74 75 76
77 public function __construct(Repository $repository)
78 {
79 $this->repository = $repository;
80 }
81
82 public function offsetExists($offset)
83 {
84 return isset(self::$available_sections[$offset]);
85 }
86
87 public function offsetGet($offset)
88 {
89 if (empty($this->sections[$offset]))
90 {
91 if (empty(self::$available_sections[$offset]))
92 {
93 throw new OffsetNotDefined(array($offset, $this));
94 }
95
96 $data = $this->repository->provider->fetch("supplemental/{$offset}");
97 $path = 'supplemental/' . self::$available_sections[$offset];
98 $path_parts = explode('/', $path);
99
100 foreach ($path_parts as $part)
101 {
102 $data = $data[$part];
103 }
104
105 $this->sections[$offset] = $data;
106 }
107
108 return $this->sections[$offset];
109 }
110
111 public function offsetSet($offset, $value)
112 {
113 throw new OffsetNotWritable(array($offset, $this));
114 }
115
116 public function offsetUnset($offset)
117 {
118 throw new OffsetNotWritable(array($offset, $this));
119 }
120 }