1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace ICanBoogie\CLDR;
13
14 use ICanBoogie\PropertyNotDefined;
15
16 /**
17 * Representation of a CLDR.
18 *
19 * <pre>
20 * <?php
21 *
22 * namespace ICanBoogie\CLDR;
23 *
24 * $repository = new Repository($provider);
25 *
26 * var_dump($repository->locales['fr']);
27 * </pre>
28 *
29 * @property-read Provider $provider A CLDR provider.
30 * @property-read LocaleCollection $locales Locale collection.
31 * @property-read Supplemental $supplemental Representation of the "supplemental" section.
32 *
33 * @see http://www.unicode.org/repos/cldr-aux/json/24/
34 */
35 class Repository
36 {
37 /**
38 * A CLDR provider.
39 *
40 * @var Provider
41 */
42 protected $provider;
43
44 /**
45 * Locale collection.
46 *
47 * @var LocaleCollection
48 */
49 protected $locales;
50
51 /**
52 * Representation of the "supplemental" section.
53 *
54 * @var Supplemental
55 */
56 protected $supplemental;
57
58 /**
59 * Initializes the {@link $provider} property.
60 *
61 * @param Provider $provider
62 */
63 public function __construct(Provider $provider)
64 {
65 $this->provider = $provider;
66 }
67
68 public function __get($property)
69 {
70 switch ($property)
71 {
72 case 'provider': return $this->get_provider();
73 case 'locales': return $this->get_locales();
74 case 'supplemental': return $this->get_supplemental();
75 }
76
77 throw new PropertyNotDefined(array($property, $this));
78 }
79
80 protected function get_provider()
81 {
82 return $this->provider;
83 }
84
85 protected function get_locales()
86 {
87 if ($this->locales)
88 {
89 return $this->locales;
90 }
91
92 return $this->locales = new LocaleCollection($this);
93 }
94
95 protected function get_supplemental()
96 {
97 if ($this->supplemental)
98 {
99 return $this->supplemental;
100 }
101
102 return $this->supplemental = new Supplemental($this);
103 }
104
105 /**
106 * Fetches the data available at the specified path.
107 *
108 * Note: The method is forwarded to {@link Provider::fetch}.
109 *
110 * @param string $path
111 */
112 public function fetch($path)
113 {
114 return $this->provider->fetch($path);
115 }
116 }