View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}


[Yegor Bugayenko|]


1.0 ? 9 November 2008: Initial Draft.

Zend_Money is a monetary value holder and converter.

* [Zend_Currency]

* This component *will* allow to create object equivalents of monetary values.
* This component *will* allow to do math manipulations with monetary values.
* This component *will* enable integration with currency conversion web services.

* Zend_Currency

The component is instantiated when you need to store, manage and output a monetary value.

* Milestone 1: Prototype checked into the incubator (full support of all operations and one web service)
* Milestone 2: 100% test code covered
* Milestone 3: Full documentation exists.

* Zend_Money
* Zend_Money_Converter (factory class)
* Zend_Money_Converter_? (web service proxy, maybe,, etc.)


// this converter will be used by default by all instances of Zend_Money

// we create a new object of class Zend_Money and it is automatically parsed from string
// in current Locale
$price = new Zend_Money('15.6 USD');

// we add new monetary value to the object
// instant conversion through specified webservice is done automatically
$price->add('19 EUR');

// the object still has value in the same currency as it was created (USD)
// and we get something like this: '35.15 USD'
// format of the output is specified in Zend_Money defaults
echo $price;


// we can easily manipulate with Zend_Money objects
$price = new Zend_Money('15 USD');

// for example, we can add one object to another
$price->add(new Zend_Money('500 GBP'));

// or we can do other math operations:

// we can compare objects
$isIt = $price->greaterThan('$450');

class Zend_Money
static function setDefaultConverter($converter); // set converter to be used by default
function setConverter($converter); // set converter to be used in this particular object

function add($delta); // adds $delta to current object
function deduct($delta); // deducts $delta from current object
function multiply($mul); // multiplies current object to $mul
function divide($div); // divides current object by $div

function greaterThan($money); // compares current object with another one
function lessThan($money); // adds $delta to current object

function usd(); // returns monetary value in USD, as float
function cents(); // returns monetary value in USD cents

function __toString(); // returns textual presentation of the object