Source of file MoneyCasting.php
Size: 2,391 Bytes - Last Modified: 2021-12-24T06:51:34+00:00
/var/www/docs.ssmods.com/process/src/src/Currency/MoneyCasting.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | <?php namespace Heystack\Ecommerce\Currency; use Heystack\Ecommerce\Currency\Traits\HasCurrencyServiceTrait; use Heystack\Ecommerce\Locale\Traits\HasLocaleServiceTrait; use SebastianBergmann\Money\IntlFormatter; use SebastianBergmann\Money\Money; /** * Class Money * @package Heystack\Ecommerce\Currency */ class MoneyCasting extends \ViewableData { use HasLocaleServiceTrait; private static $casting = [ 'Nice' => 'Text', 'Currency' => 'Text', 'Amount' => 'Decimal' ]; /** * @var \SebastianBergmann\Money\Money */ protected $value; /** * @param \SebastianBergmann\Money\Money $value * @param mixed|null|void $record * @return \Heystack\Ecommerce\Currency\MoneyCasting */ public function setValue(Money $value, $record = null) { $this->value = $value; return $this; } /** * @return \SebastianBergmann\Money\Money */ public function getValue() { return $this->value; } /** * Remove country codes that sometimes appear in front of currency symbols * @return string */ public function Nice() { return preg_replace('/[A-Za-z]/', '', $this->getFormatter()->format($this->value)); } /** * @return string */ public function Currency() { return $this->value->getCurrency()->getCurrencyCode(); } /** * @return string */ public function Amount() { return \Heystack\Ecommerce\convertMoneyToString( $this->value ); } /** * @return string */ public function forTemplate() { return $this->Nice(); } /** * @return \SebastianBergmann\Money\IntlFormatter */ protected function getFormatter() { return new IntlFormatter( sprintf( 'en-%s', $this->localeService->getActiveCountry()->getCountryCode() ) ); } /** * The value "exists" if it is not 0 * @return bool */ public function exists() { return $this->value->getAmount() !== 0; } /** * @param \SebastianBergmann\Money\Money $value */ public static function castMoneyToString(Money $value) { return \Injector::inst()->get(__CLASS__)->setValue($value)->Nice(); } } |