ICanBoogie/CLDR v1.5.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • CLDR

Classes

  • Calendar
  • CalendarCollection
  • Currency
  • CurrencyCollection
  • CurrencyFormatter
  • DateFormatter
  • DateTimeFormatter
  • FileProvider
  • ListFormatter
  • Locale
  • LocaleCollection
  • LocalizedCurrency
  • LocalizedDateTime
  • LocalizedListFormatter
  • LocalizedLocale
  • LocalizedNumberFormatter
  • LocalizedObject
  • LocalizedObjectWithFormatter
  • LocalizedTerritory
  • NumberFormatter
  • NumberPattern
  • NumberPatternParser
  • Numbers
  • ProviderCollection
  • RedisProvider
  • Repository
  • RunTimeProvider
  • Supplemental
  • Territory
  • TerritoryCollection
  • TimeFormatter
  • WebProvider

Interfaces

  • Exception
  • Formatter
  • LocalizeAwareInterface
  • Provider

Traits

  • CodePropertyTrait
  • CollectionTrait
  • LocalePropertyTrait
  • ProviderStorageBinding
  • RepositoryPropertyTrait

Exceptions

  • ResourceNotFound
  • TerritoryNotDefined
  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 
<?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\OffsetNotDefined;

/**
 * Representation of the "supplemental" section.
 *
 * <pre>
 * <?php
 *
 * use ICanBoogie\CLDR\Supplemental;
 *
 * $supplemental = new Supplemental($repository);
 *
 * echo $supplemental['calendarPreferenceData']['001']; // gregorian
 * </pre>
 */
class Supplemental implements \ArrayAccess
{
    use CollectionTrait;
    use RepositoryPropertyTrait;

    static private $available_sections = [

        'calendarData'           => 'calendarData',
        'calendarPreferenceData' => 'calendarPreferenceData',
        'characterFallbacks'     => 'characters/character-fallback',
        'codeMappings'           => 'codeMappings',
        'currencyData'           => 'currencyData',
        'dayPeriods'             => 'dayPeriodRuleSet',
        'gender'                 => 'gender',
        'languageData'           => 'languageData',
        'languageMatching'       => 'languageMatching',
        'likelySubtags'          => 'likelySubtags',
        'measurementData'        => 'measurementData',
        'metaZones'              => 'metaZones',
        'numberingSystems'       => 'numberingSystems',
        'ordinals'               => 'plurals-type-ordinal',
        'parentLocales'          => 'parentLocales',
        'plurals'                => 'plurals-type-cardinal',
        'postalCodeData'         => 'postalCodeData',
        'primaryZones'           => 'primaryZones',
        'references'             => 'references',
        'telephoneCodeData'      => 'telephoneCodeData',
        'territoryContainment'   => 'territoryContainment',
        'territoryInfo'          => 'territoryInfo',
        'timeData'               => 'timeData',
        'weekData'               => 'weekData',
        'windowsZones'           => 'windowsZones'

    ];

    /**
     * Loaded sections.
     *
     * @var array
     */
    protected $sections = [];

    /**
     * Initializes the {@link $repository} property.
     *
     * @param Repository $repository
     */
    public function __construct(Repository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * @inheritdoc
     */
    public function offsetExists($offset)
    {
        return isset(self::$available_sections[$offset]);
    }

    /**
     * @inheritdoc
     */
    public function offsetGet($offset)
    {
        if (isset($this->sections[$offset]))
        {
            return $this->sections[$offset];
        }

        if (empty(self::$available_sections[$offset]))
        {
            throw new OffsetNotDefined([ $offset, $this ]);
        }

        $data = $this->repository->fetch("supplemental/{$offset}");
        $path = 'supplemental/' . self::$available_sections[$offset];
        $path_parts = explode('/', $path);

        foreach ($path_parts as $part)
        {
            $data = $data[$part];
        }

        return $this->sections[$offset] = $data;
    }
}
ICanBoogie/CLDR v1.5.0 API documentation generated by ApiGen