ICanBoogie/CLDR v1.4.1
  • 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
  • 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 
<?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;

/**
 * A currency.
 *
 * ```php
 * <?php
 *
 * use ICanBoogie\CLDR\Currency;
 *
 * $euro = new Currency($cldr, 'EUR');
 * # or
 * $euro = $cldr->currencies['EUR'];
 *
 * echo $euro->code;        // EUR
 * echo $euro->digits;      // 2
 * echo $euro->rounding;    // 0
 * echo $euro->cash_digits;   //
 * ```
 *
 * @property-read string $code The ISO 4217 code for the currency.
 * @property-read int $digits The minimum and maximum number of decimal digits normally formatted.
 * @property-read int $rounding The rounding increment, in units of 10^-digits.
 * @property-read int $cash_digits The number of decimal digits to be used when formatting quantities used in cash transactions.
 * @property-read int $cash_rounding The cash rounding increment, in units of 10^cashDigits
 *
 * @see http://unicode.org/reports/tr35/tr35-numbers.html#Supplemental_Currency_Data
 */
class Currency
{
    use AccessorTrait;
    use RepositoryPropertyTrait;
    use CodePropertyTrait;

    /**
     * @param Repository $repository
     * @param string $code Currency ISO code.
     */
    public function __construct(Repository $repository, $code)
    {
        $this->repository = $repository;
        $this->code = $code;
    }

    public function __get($property)
    {
        if (in_array($property, [ 'digits', 'rounding', 'cash_digits', 'cash_rounding' ]))
        {
            $data = $this->repository->supplemental['currencyData'][$this->code];
            $offset = '_' . $property;

            return isset($data[$offset]) ? (int) $data[$offset] : null;
        }

        return $this->accessor_get($property);
    }

    /**
     * Localize the currency.Doc
     *
     * @param string $locale_code
     *
     * @return LocalizedCurrency
     */
    public function localize($locale_code)
    {
        return $this->repository->locales[$locale_code]->localize($this);
    }
}
ICanBoogie/CLDR v1.4.1 API documentation generated by ApiGen