View Source

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

{zone-data:component-name}
Zend_Money
{zone-data}

{zone-data:proposer-list}
[Yegor Bugayenko|mailto:yegor256@yahoo.com]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
1.0 ? 9 November 2008: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Money is a monetary value holder and converter.
{zone-data}

{zone-data:references}
* [Zend_Currency]
{zone-data}

{zone-data:requirements}
* 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.
{zone-data}

{zone-data:dependencies}
* Zend_Currency
{zone-data}

{zone-data:operation}
The component is instantiated when you need to store, manage and output a monetary value.
{zone-data}

{zone-data:milestones}
* 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.
{zone-data}

{zone-data:class-list}
* Zend_Money
* Zend_Money_Converter (factory class)
* Zend_Money_Converter_? (web service proxy, maybe xe.com, oanda.com, etc.)
{zone-data}

{zone-data:use-cases}
||UC-01||

{code}
// this converter will be used by default by all instances of Zend_Money
Zend_Money::setDefaultConverter('xe');

// 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;
{code}

||UC-02||

{code}
// 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:
$price->divide(5);

// we can compare objects
$isIt = $price->greaterThan('$450');
{code}
{zone-data}

{zone-data:skeletons}
{code}
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
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>