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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
<?php
/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ICanBoogie\CLDR;
use ICanBoogie\Accessor\AccessorTrait;
/**
* Representation of a CLDR.
*
* <pre>
* <?php
*
* namespace ICanBoogie\CLDR;
*
* $repository = new Repository($provider);
*
* var_dump($repository->locales['fr']);
* var_dump($repository->territories['FR']);
* </pre>
*
* @property-read Provider $provider
* @property-read LocaleCollection $locales
* @property-read Supplemental $supplemental
* @property-read TerritoryCollection $territories
* @property-read CurrencyCollection $currencies
* @property-read NumberFormatter $number_formatter
* @property-read ListFormatter $list_formatter
* @property-read Plurals $plurals
*
* @see http://www.unicode.org/repos/cldr-aux/json/24/
*/
class Repository
{
use AccessorTrait;
/**
* @var Provider
*/
private $provider;
/**
* @return Provider
*/
protected function get_provider()
{
return $this->provider;
}
/**
* @return LocaleCollection
*/
protected function lazy_get_locales()
{
return new LocaleCollection($this);
}
/**
* @return Supplemental
*/
protected function lazy_get_supplemental()
{
return new Supplemental($this);
}
/**
* @return TerritoryCollection
*/
protected function lazy_get_territories()
{
return new TerritoryCollection($this);
}
/**
* @return CurrencyCollection
*/
protected function lazy_get_currencies()
{
return new CurrencyCollection($this);
}
/**
* @return NumberFormatter
*/
protected function lazy_get_number_formatter()
{
return new NumberFormatter($this);
}
/**
* @return ListFormatter
*/
protected function lazy_get_list_formatter()
{
return new ListFormatter($this);
}
/**
* @return Plurals
*/
protected function lazy_get_plurals()
{
return new Plurals($this->supplemental['plurals']);
}
/**
* Initializes the {@link $provider} property.
*
* @param Provider $provider
*/
public function __construct(Provider $provider)
{
$this->provider = $provider;
}
/**
* Fetches the data available at the specified path.
*
* Note: The method is forwarded to {@link Provider::provide}.
*
* @param string $path
*
* @return array
*/
public function fetch($path)
{
return $this->provider->provide($path);
}
/**
* Format a number with the specified pattern.
*
* @param mixed $number The number to be formatted.
* @param string $pattern The pattern used to format the number.
* @param array $symbols Symbols.
*
* @return string
*
* @see NumberFormatter::format()
*/
public function format_number($number, $pattern, array $symbols = [])
{
return $this->number_formatter->format($number, $pattern, $symbols);
}
/**
* Formats a variable-length lists of things.
*
* @param array $list The list to format.
* @param array $list_patterns A list patterns.
*
* @return string
*
* @see ListFormatter::format()
*/
public function format_list(array $list, array $list_patterns)
{
return $this->list_formatter->format($list, $list_patterns);
}
}