From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- .../intl/src/NumberFormat/NumberFormat.php | 285 ++++++++++----------- 1 file changed, 142 insertions(+), 143 deletions(-) (limited to 'vendor/commerceguys/intl/src/NumberFormat/NumberFormat.php') diff --git a/vendor/commerceguys/intl/src/NumberFormat/NumberFormat.php b/vendor/commerceguys/intl/src/NumberFormat/NumberFormat.php index 077f6721f..156470eee 100644 --- a/vendor/commerceguys/intl/src/NumberFormat/NumberFormat.php +++ b/vendor/commerceguys/intl/src/NumberFormat/NumberFormat.php @@ -2,8 +2,22 @@ namespace CommerceGuys\Intl\NumberFormat; -class NumberFormat implements NumberFormatEntityInterface +/** + * Provides metadata for number formatting. + */ +final class NumberFormat { + // Arabic-Indic digits. + const NUMBERING_SYSTEM_ARABIC = 'arab'; + // Extended Arabic-Indic digits. + const NUMBERING_SYSTEM_ARABIC_EXTENDED = 'arabext'; + // Bengali digits. + const NUMBERING_SYSTEM_BENGALI = 'beng'; + // Devanagari digits. + const NUMBERING_SYSTEM_DEVANAGARI = 'deva'; + // Latin digits + const NUMBERING_SYSTEM_LATIN = 'latn'; + /** * The locale (i.e. "en_US"). * @@ -12,159 +26,230 @@ class NumberFormat implements NumberFormatEntityInterface protected $locale; /** - * The numbering system. + * The number pattern used to format decimal numbers. * * @var string */ - protected $numberingSystem = []; + protected $decimalPattern; /** - * The decimal separator. + * The number pattern used to format percentages. * * @var string */ - protected $decimalSeparator = []; + protected $percentPattern; /** - * The grouping separator. + * The number pattern used to format currency amounts. * * @var string */ - protected $groupingSeparator = []; + protected $currencyPattern; /** - * The plus sign. + * The number pattern used to format accounting currency amounts. * * @var string */ - protected $plusSign = []; + protected $accountingCurrencyPattern; /** - * The number symbols. + * The numbering system. * * @var string */ - protected $minusSign = []; + protected $numberingSystem = self::NUMBERING_SYSTEM_LATIN; /** - * The percent sign. + * The decimal separator. * * @var string */ - protected $percentSign = []; + protected $decimalSeparator = '.'; /** - * The number pattern used to format decimal numbers. + * The grouping separator. * * @var string */ - protected $decimalPattern; + protected $groupingSeparator = ','; /** - * The number pattern used to format percentages. + * The plus sign. * * @var string */ - protected $percentPattern; + protected $plusSign = '+'; /** - * The number pattern used to format currency amounts. + * The number symbols. * * @var string */ - protected $currencyPattern; + protected $minusSign = '-'; /** - * The number pattern used to format accounting currency amounts. + * The percent sign. * * @var string */ - protected $accountingCurrencyPattern; + protected $percentSign = '%'; /** - * {@inheritdoc} + * Creates a new NumberFormat instance. + * + * @param array $definition The definition array. */ - public function getLocale() + public function __construct(array $definition) { - return $this->locale; + // Validate the presence of required properties. + $requiredProperties = [ + 'locale', 'decimal_pattern', 'percent_pattern', + 'currency_pattern', 'accounting_currency_pattern', + ]; + foreach ($requiredProperties as $requiredProperty) { + if (empty($definition[$requiredProperty])) { + throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $requiredProperty)); + } + } + // Validate the numbering system. + if (isset($definition['numbering_system'])) { + if (!in_array($definition['numbering_system'], ['arab', 'arabext', 'beng', 'deva', 'latn'])) { + throw new \InvalidArgumentException(sprintf('Invalid numbering system "%s".', $definition['numbering_system'])); + } + } + + $this->locale = $definition['locale']; + $this->decimalPattern = $definition['decimal_pattern']; + $this->percentPattern = $definition['percent_pattern']; + $this->currencyPattern = $definition['currency_pattern']; + $this->accountingCurrencyPattern = $definition['accounting_currency_pattern']; + if (isset($definition['numbering_system'])) { + $this->numberingSystem = $definition['numbering_system']; + } + if (isset($definition['decimal_separator'])) { + $this->decimalSeparator = $definition['decimal_separator']; + } + if (isset($definition['grouping_separator'])) { + $this->groupingSeparator = $definition['grouping_separator']; + } + if (isset($definition['plus_sign'])) { + $this->plusSign = $definition['plus_sign']; + } + if (isset($definition['minus_sign'])) { + $this->minusSign = $definition['minus_sign']; + } + if (isset($definition['percent_sign'])) { + $this->percentSign = $definition['percent_sign']; + } } /** - * {@inheritdoc} + * Gets the locale. + * + * @return string */ - public function setLocale($locale) + public function getLocale() { - $this->locale = $locale; - - return $this; + return $this->locale; } /** - * {@inheritdoc} + * Gets the number pattern used to format decimal numbers. + * + * @return string + * + * @see http://cldr.unicode.org/translation/number-patterns */ - public function getNumberingSystem() + public function getDecimalPattern() { - return $this->numberingSystem; + return $this->decimalPattern; } /** - * {@inheritdoc} + * Gets the number pattern used to format percentages. + * + * @return string + * + * @see http://cldr.unicode.org/translation/number-patterns */ - public function setNumberingSystem($numberingSystem) + public function getPercentPattern() { - $this->numberingSystem = $numberingSystem; + return $this->percentPattern; } /** - * {@inheritdoc} + * Gets the number pattern used to format currency amounts. + * + * @return string + * + * @see http://cldr.unicode.org/translation/number-patterns */ - public function getDecimalSeparator() + public function getCurrencyPattern() { - return $this->decimalSeparator; + return $this->currencyPattern; } /** - * {@inheritdoc} + * Gets the number pattern used to format accounting currency amounts. + * + * Most commonly used when formatting amounts on invoices. + * + * @return string + * + * @see http://cldr.unicode.org/translation/number-patterns */ - public function setDecimalSeparator($decimalSeparator) + public function getAccountingCurrencyPattern() { - $this->decimalSeparator = $decimalSeparator; + return $this->accountingCurrencyPattern; } /** - * {@inheritdoc} + * Gets the numbering system. + * + * The value is one of the NUMBERING_SYSTEM_ constants. + * + * @return string */ - public function getGroupingSeparator() + public function getNumberingSystem() { - return $this->groupingSeparator; + return $this->numberingSystem; } /** - * {@inheritdoc} + * Gets the decimal separator. + * + * @return string */ - public function setGroupingSeparator($groupingSeparator) + public function getDecimalSeparator() { - $this->groupingSeparator = $groupingSeparator; + return $this->decimalSeparator; } /** - * {@inheritdoc} + * Gets the grouping separator. + * + * @return string */ - public function getPlusSign() + public function getGroupingSeparator() { - return $this->plusSign; + return $this->groupingSeparator; } /** - * {@inheritdoc} + * Gets the plus sign. + * + * @return string */ - public function setPlusSign($plusSign) + public function getPlusSign() { - $this->plusSign = $plusSign; + return $this->plusSign; } /** - * {@inheritdoc} + * Gets the minus sign. + * + * @return string */ public function getMinusSign() { @@ -172,98 +257,12 @@ class NumberFormat implements NumberFormatEntityInterface } /** - * {@inheritdoc} - */ - public function setMinusSign($minusSign) - { - $this->minusSign = $minusSign; - } - - /** - * {@inheritdoc} + * Gets the percent sign. + * + * @return string */ public function getPercentSign() { return $this->percentSign; } - - /** - * {@inheritdoc} - */ - public function setPercentSign($percentSign) - { - $this->percentSign = $percentSign; - } - - /** - * {@inheritdoc} - */ - public function getDecimalPattern() - { - return $this->decimalPattern; - } - - /** - * {@inheritdoc} - */ - public function setDecimalPattern($decimalPattern) - { - $this->decimalPattern = $decimalPattern; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getPercentPattern() - { - return $this->percentPattern; - } - - /** - * {@inheritdoc} - */ - public function setPercentPattern($percentPattern) - { - $this->percentPattern = $percentPattern; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getCurrencyPattern() - { - return $this->currencyPattern; - } - - /** - * {@inheritdoc} - */ - public function setCurrencyPattern($currencyPattern) - { - $this->currencyPattern = $currencyPattern; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getAccountingCurrencyPattern() - { - return $this->accountingCurrencyPattern; - } - - /** - * {@inheritdoc} - */ - public function setAccountingCurrencyPattern($accountingCurrencyPattern) - { - $this->accountingCurrencyPattern = $accountingCurrencyPattern; - - return $this; - } } -- cgit v1.2.3