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\OffsetNotWritable;
15
16 /**
17 * Representation of a calendar collection.
18 *
19 * <pre>
20 * <?php
21 *
22 * $calendar_collection = $repository->locales['fr']->calendars;
23 * $gregorian_callendar = $calendar_collection['gregorian'];
24 * </pre>
25 */
26 class CalendarCollection implements \ArrayAccess
27 {
28 /**
29 * Representation of a locale.
30 *
31 * @var Locale
32 */
33 protected $repository;
34
35 /**
36 * Calendar instances.
37 *
38 * @var Calendar[]
39 */
40 protected $collection = array();
41
42 /**
43 * Initialiazes the {@link $repository} property.
44 *
45 * @param Repository $repository Representation of a CLDR.
46 */
47 public function __construct(Locale $locale)
48 {
49 $this->locale = $locale;
50 }
51
52 public function offsetExists($offset)
53 {
54 throw new \BadMethodCallException("The method is not implemented");
55 }
56
57 public function offsetGet($offset)
58 {
59 if (empty($this->collection[$offset]))
60 {
61 $this->collection[$offset] = new Calendar($this->locale, $this->locale["ca-{$offset}"]);
62 }
63
64 return $this->collection[$offset];
65 }
66
67 public function offsetSet($offset, $value)
68 {
69 throw new OffsetNotWritable(array($offset, $this));
70 }
71
72 public function offsetUnset($offset)
73 {
74 throw new OffsetNotWritable(array($offset, $this));
75 }
76 }