Skip to content

Commit

Permalink
Removing Number::addFormat(), given that intl has all formats it was …
Browse files Browse the repository at this point in the history
…not needed

Removed the escaping option from Number methods, they belonto into a helper
  • Loading branch information
lorenzo committed Aug 2, 2014
1 parent 939bdb7 commit 7a28637
Showing 1 changed file with 1 addition and 68 deletions.
69 changes: 1 addition & 68 deletions src/Utility/Number.php
Expand Up @@ -26,45 +26,6 @@
*/
class Number {

/**
* Currencies supported by the helper. You can add additional currency formats
* with Cake\Utility\Number::addFormat
*
* @var array
*/
protected static $_currencies = array(
'AUD' => array(
'wholeSymbol' => '$', 'wholePosition' => 'before', 'fractionSymbol' => 'c', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true,
'fractionExponent' => 2
),
'CAD' => array(
'wholeSymbol' => '$', 'wholePosition' => 'before', 'fractionSymbol' => 'c', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true,
'fractionExponent' => 2
),
'USD' => array(
'wholeSymbol' => '$', 'wholePosition' => 'before', 'fractionSymbol' => 'c', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true,
'fractionExponent' => 2
),
'EUR' => array(
'wholeSymbol' => '€', 'wholePosition' => 'before', 'fractionSymbol' => false, 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => '.', 'decimals' => ',', 'negative' => '()', 'escape' => true,
'fractionExponent' => 0
),
'GBP' => array(
'wholeSymbol' => '£', 'wholePosition' => 'before', 'fractionSymbol' => 'p', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true,
'fractionExponent' => 2
),
'JPY' => array(
'wholeSymbol' => '¥', 'wholePosition' => 'before', 'fractionSymbol' => false, 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true,
'fractionExponent' => 0
),
);

/**
* A list of number formatters indexed by locale
*
Expand Down Expand Up @@ -195,7 +156,6 @@ public static function toPercentage($value, $precision = 2, array $options = arr
* - `locale` - The locale name to use for formatting the number, e.g. fr_FR
* - `before` - The string to place before whole numbers, e.g. '['
* - `after` - The string to place after decimal numbers, e.g. ']'
* - `escape` - Set to false to prevent escaping
*
* @param float $value A floating point number.
* @param array $options An array with options.
Expand Down Expand Up @@ -225,13 +185,9 @@ public static function format($value, array $options = []) {
}
}

$options += ['before' => '', 'after' => '', 'escape' => true];
$options += ['before' => '', 'after' => ''];
$out = $options['before'] . $formatter->format($value) . $options['after'];

if (!empty($options['escape'])) {
return h($out);
}

return $out;
}

Expand Down Expand Up @@ -335,29 +291,6 @@ public static function currency($value, $currency = null, array $options = array
return $before . $formatter->formatCurrency($value, $currency) . $after;
}

/**
* Add a currency format to the Number helper. Makes reusing
* currency formats easier.
*
* {{{ $number->addFormat('NOK', array('before' => 'Kr. ')); }}}
*
* You can now use `NOK` as a shortform when formatting currency amounts.
*
* {{{ $number->currency($value, 'NOK'); }}}
*
* Added formats are merged with the defaults defined in Cake\Utility\Number::$_currencyDefaults
* See Cake\Utility\Number::currency() for more information on the various options and their function.
*
* @param string $formatName The format name to be used in the future.
* @param array $options The array of options for this format.
* @return void
* @see NumberHelper::currency()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::addFormat
*/
public static function addFormat($formatName, array $options) {
static::$_currencies[$formatName] = $options + static::$_currencyDefaults;
}

/**
* Getter/setter for default currency
*
Expand Down

0 comments on commit 7a28637

Please sign in to comment.