PHP Class ValueObjects\Money\Money

Inheritance: implements ValueObjects\ValueObjectInterface
Show file Open project: nicolopignatelli/valueobjects Class Usage Examples

Protected Properties

Property Type Description
$currency ValueObjects\Money\Currency
$money Money\Money

Public Methods

Method Description
__construct ( integer $amount, ValueObjects\Money\Currency $currency ) Returns a Money object
__toString ( ) : string Returns a string representation of the Money value in format "CUR AMOUNT" (e.g.: EUR 1000)
add ( integer $quantity ) : Money Add an integer quantity to the amount and returns a new Money object.
fromNative ( ) : static Returns a Money object from native int amount and string currency code
getAmount ( ) : ValueObjects\Number\Integer Returns money amount
getCurrency ( ) : ValueObjects\Money\Currency Returns money currency
multiply ( ValueObjects\Number\Real $multiplier, ValueObjects\Number\RoundingMode $rounding_mode = null ) : Money Multiply the Money amount for a given number and returns a new Money object.
sameValueAs ( ValueObjects\ValueObjectInterface $money ) : boolean Tells whether two Currency are equal by comparing their amount and currency

Method Details

__construct() public method

Returns a Money object
public __construct ( integer $amount, ValueObjects\Money\Currency $currency )
$amount integer Amount expressed in the smallest units of $currency (e.g. cents)
$currency ValueObjects\Money\Currency Currency of the money object

__toString() public method

Returns a string representation of the Money value in format "CUR AMOUNT" (e.g.: EUR 1000)
public __toString ( ) : string
return string

add() public method

Use a negative quantity for subtraction.
public add ( integer $quantity ) : Money
$quantity integer Quantity to add
return Money

fromNative() public static method

Returns a Money object from native int amount and string currency code
public static fromNative ( ) : static
return static

getAmount() public method

Returns money amount
public getAmount ( ) : ValueObjects\Number\Integer
return ValueObjects\Number\Integer

getCurrency() public method

Returns money currency
public getCurrency ( ) : ValueObjects\Money\Currency
return ValueObjects\Money\Currency

multiply() public method

Use 0 < Real $multipler < 1 for division.
public multiply ( ValueObjects\Number\Real $multiplier, ValueObjects\Number\RoundingMode $rounding_mode = null ) : Money
$multiplier ValueObjects\Number\Real
$rounding_mode ValueObjects\Number\RoundingMode Rounding mode of the operation. Defaults to RoundingMode::HALF_UP.
return Money

sameValueAs() public method

Tells whether two Currency are equal by comparing their amount and currency
public sameValueAs ( ValueObjects\ValueObjectInterface $money ) : boolean
$money ValueObjects\ValueObjectInterface
return boolean

Property Details

$currency protected property

protected Currency,ValueObjects\Money $currency
return ValueObjects\Money\Currency

$money protected property

protected Money,Money $money
return Money\Money