From a6afcc944cc48fee74fb20b39e011cdaa2ca0713 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 27 Feb 2018 21:38:05 -0600 Subject: [PATCH] Add Money composition class to Support --- app/Support/Money.php | 111 ++++++++++++++++++++++++++++ modules/Installer/Config/config.php | 1 + 2 files changed, 112 insertions(+) create mode 100644 app/Support/Money.php diff --git a/app/Support/Money.php b/app/Support/Money.php new file mode 100644 index 00000000..ddef57c2 --- /dev/null +++ b/app/Support/Money.php @@ -0,0 +1,111 @@ +money = static::create($amount); + } + + /** + * @return string + */ + public function getAmount() + { + return $this->money->getAmount(); + } + + /** + * + * @return string + */ + public function __toString() + { + // TODO: Implement __toString() method. + return $this->money->getAmount(); + } + + /** + * Add an amount + * @param $amount + */ + public function add($amount) + { + $this->money = $this->money->add($amount); + } + + /** + * Subtract an amount + * @param $amount + */ + public function subtract($amount) + { + $this->money = $this->money->subtract($amount); + } + + /** + * Multiply by an amount + * @param $amount + */ + public function multiply($amount) + { + $this->money = $this->money->multiply($amount); + } + + /** + * Divide by an amount + * @param $amount + */ + public function divide($amount) + { + $this->money = $this->money->divide($amount); + } + + /** + * @param $money + * @return bool + * @throws \InvalidArgumentException + */ + public function equals($money) + { + if($money instanceof Money) { + return $this->money->equals($money->money); + } elseif($money instanceof MoneyBase) { + return $this->money->equals($money); + } else { + return $this->money->equals(static::create($money)); + } + } +} diff --git a/modules/Installer/Config/config.php b/modules/Installer/Config/config.php index 8f66bce2..87ef623d 100644 --- a/modules/Installer/Config/config.php +++ b/modules/Installer/Config/config.php @@ -8,6 +8,7 @@ return [ 'extensions' => [ 'openssl', 'pdo', + 'intl', 'mbstring', 'tokenizer', 'json',