Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (127 sloc) 4.35 KB
<?php
/**
* Number Helper.
*
* Methods to make numbers more readable.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View.Helper
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeNumber', 'Utility');
App::uses('AppHelper', 'View/Helper');
/**
* Number helper library.
*
* Methods to make numbers more readable.
*
* @package Cake.View.Helper
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html
* @see CakeNumber
*/
class NumberHelper extends AppHelper {
/** CakeNumber instance
*/
protected $_CakeNumber = null;
/* Default Constructor
*
* @param View $View The View this helper is being attached to.
* @param array $settings Configuration settings for the helper
*/
function __construct(View $View, $settings = array()) {
$settings = Set::merge(array('engine' => 'CakeNumber'), $settings);
parent::__construct($View, $settings);
$engineClass = $settings['engine'];
App::uses($engineClass, 'Utility');
if (class_exists($engineClass)) {
$this->_CakeNumber = new $engineClass($settings);
} else {
throw new CakeException(__d('cake_dev', '%s could not be found', $engineClass));
}
}
/**
* Call methods from CakeNumber utility class
*/
public function __call($method, $params) {
return call_user_func_array(array($this->_CakeNumber, $method), $params);
}
/**
* @see: CakeNumber::precision()
*
* @param float $number A floating point number.
* @param integer $precision The precision of the returned number.
* @return float Formatted float.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision
*/
public function precision($number, $precision = 3) {
return $this->_CakeNumber->precision($number, $precision);
}
/**
* @see: CakeNumber::toReadableSize()
*
* @param integer $size Size in bytes
* @return string Human readable size
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize
*/
public function toReadableSize($size) {
return $this->_CakeNumber->toReadableSize($size);
}
/**
* @see: CakeNumber::toPercentage()
*
* @param float $number A floating point number
* @param integer $precision The precision of the returned number
* @return string Percentage string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage
*/
public function toPercentage($number, $precision = 2) {
return $this->_CakeNumber->toPercentage($number, $precision);
}
/**
* @see: CakeNumber::format()
*
* @param float $number A floating point number
* @param integer $options if int then places, if string then before, if (,.-) then use it
* or array with places and before keys
* @return string formatted number
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format
*/
public function format($number, $options = false) {
return $this->_CakeNumber->format($number, $options);
}
/**
* @see: CakeNumber::currency()
*
* @param float $number
* @param string $currency Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise
* set at least 'before' and 'after' options.
* @param array $options
* @return string Number formatted as a currency.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency
*/
public function currency($number, $currency = 'USD', $options = array()) {
return $this->_CakeNumber->currency($number, $currency, $options);
}
/**
* @see: CakeNumber::addFormat()
*
* @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 function addFormat($formatName, $options) {
return $this->_CakeNumber->addFormat($formatName, $options);
}
}
Jump to Line
Something went wrong with that request. Please try again.