Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • Calendar
  • CalendarCollection
  • DateFormatter
  • DateTimeFormatter
  • FileCache
  • Locale
  • LocaleCollection
  • LocalizedDateTime
  • LocalizedObject
  • Provider
  • Repository
  • Retriever
  • RunTimeCache
  • Supplemental
  • TimeFormatter

Interfaces

  • Cache

Exceptions

  • ResourceNotFound
  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 use ICanBoogie\OffsetNotDefined;
 16 use ICanBoogie\PropertyNotDefined;
 17 
 18 /**
 19  * Representation of a locale.
 20  *
 21  * @property-read Repository $repository The repository provided during construct.
 22  * @property-read string $identity The identity of the locale.
 23  * @property-read CalendarCollection $calendars The calendar collection of the locale.
 24  * @property-read Calendar $calendar The prefered calendar for this locale.
 25  */
 26 class Locale implements \ArrayAccess
 27 {
 28     static private $available_sections = array
 29     (
 30         'ca-buddhist'            => 'dates/calendars/buddhist',
 31         'ca-chinese'             => 'dates/calendars/chinese',
 32         'ca-coptic'              => 'dates/calendars/coptic',
 33         'ca-dangi'               => 'dates/calendars/dangi',
 34         'ca-ethiopic-amete-alem' => 'dates/calendars/ethiopic-amete-alem',
 35         'ca-ethiopic'            => 'dates/calendars/ethiopic',
 36         'ca-generic'             => 'dates/calendars/generic',
 37         'ca-gregorian'           => 'dates/calendars/gregorian',
 38         'ca-hebrew'              => 'dates/calendars/hebrew',
 39         'ca-indian'              => 'dates/calendars/indian',
 40         'ca-islamic-civil'       => 'dates/calendars/islamic-civil',
 41         'ca-islamic-rgsa'        => 'dates/calendars/islamic-rgsa',
 42         'ca-islamic-tbla'        => 'dates/calendars/islamic-tbla',
 43         'ca-islamic-umalqura'    => 'dates/calendars/islamic-umalqura',
 44         'ca-islamic'             => 'dates/calendars/islamic',
 45         'ca-japanese'            => 'dates/calendars/japanese',
 46         'ca-persian'             => 'dates/calendars/persian',
 47         'ca-roc'                 => 'dates/calendars/roc',
 48         'characters'             => 'characters',
 49         'contextTransforms'      => 'contextTransforms',
 50         'currencies'             => 'numbers/currencies',
 51         'dateFields'             => 'dates/fields',
 52         'delimiters'             => 'delimiters',
 53         'languages'              => 'localeDisplayNames/languages',
 54         'layout'                 => 'layout',
 55         'listPatterns'           => 'listPatterns',
 56         'localeDisplayNames'     => 'localeDisplayNames',
 57         'measurementSystemNames' => 'localeDisplayNames/measurementSystemNames',
 58         'numbers'                => 'numbers',
 59         'posix'                  => 'posix',
 60         'scripts'                => 'localeDisplayNames/scripts',
 61         'territories'            => 'localeDisplayNames/territories',
 62         'timeZoneNames'          => 'dates/timeZoneNames',
 63         'transformNames'         => 'localeDisplayNames/transformNames',
 64         'units'                  => 'units',
 65         'variants'               => 'localeDisplayNames/variants'
 66     );
 67 
 68     /**
 69      * Representation of a CLDR.
 70      *
 71      * @var Repository
 72      */
 73     protected $repository;
 74 
 75     /**
 76      * CLDR identity.
 77      *
 78      * @var string
 79      */
 80     protected $identity;
 81 
 82     /**
 83      * Loaded sections.
 84      *
 85      * @var array
 86      */
 87     protected $sections = array();
 88 
 89     /**
 90      * Initializes the {@link $repository} and {@link $identity} properties.
 91      *
 92      * @param Repository $repository
 93      * @param string $identity Locale identifier.
 94      */
 95     public function __construct(Repository $repository, $identity)
 96     {
 97         $this->repository = $repository;
 98         $this->identity = $identity;
 99     }
100 
101     public function __get($property)
102     {
103         switch ($property)
104         {
105             case 'repository': return $this->get_repository();
106             case 'identity':   return $this->get_identity();
107             case 'calendars':  return $this->get_calendars();
108             case 'calendar':  return $this->get_calendar();
109         }
110 
111         throw new PropertyNotDefined(array($property, $this));
112     }
113 
114     protected function get_repository()
115     {
116         return $this->repository;
117     }
118 
119     protected function get_identity()
120     {
121         return $this->identity;
122     }
123 
124     /**
125      * Collection of calendars.
126      *
127      * @var CalendarCollection
128      */
129     private $calendars;
130 
131     /**
132      * Returns the calendars available for this locale.
133      *
134      * @return \ICanBoogie\CLDR\CalendarCollection
135      */
136     protected function get_calendars()
137     {
138         if ($this->calendars)
139         {
140             return $this->calendars;
141         }
142 
143         return $this->calendars = new CalendarCollection($this);
144     }
145 
146     private $calendar;
147 
148     protected function get_calendar()
149     {
150         if ($this->calendar)
151         {
152             return $this->calendar;
153         }
154 
155         return $this->calendar = $this->get_calendars()->offsetGet('gregorian'); // TODO-20131101: use prefered data
156     }
157 
158     public function offsetExists($offset)
159     {
160         return isset(self::$available_sections[$offset]);
161     }
162 
163     public function offsetGet($offset)
164     {
165         if (empty($this->sections[$offset]))
166         {
167             if (empty(self::$available_sections[$offset]))
168             {
169                 throw new OffsetNotDefined(array($offset, $this));
170             }
171 
172             $data = $this->repository->provider->fetch("{$this->identity}/{$offset}");
173             $path = "main/{$this->identity}/" . self::$available_sections[$offset];
174             $path_parts = explode('/', $path);
175 
176             foreach ($path_parts as $part)
177             {
178                 $data = $data[$part];
179             }
180 
181             $this->sections[$offset] = $data;
182         }
183 
184         return $this->sections[$offset];
185     }
186 
187     public function offsetSet($offset, $value)
188     {
189         throw new OffsetNotWritable(array($offset, $this));
190     }
191 
192     public function offsetUnset($offset)
193     {
194         throw new OffsetNotWritable(array($offset, $this));
195     }
196 }
Autodoc API documentation generated by ApiGen 2.8.0