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