Source of file Zone.php
Size: 3,453 Bytes - Last Modified: 2021-12-24T06:51:34+00:00
/var/www/docs.ssmods.com/process/src/src/Locale/Zone.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | <?php namespace Heystack\Ecommerce\Locale; use Heystack\Core\Identifier\Identifier; use Heystack\Core\Identifier\IdentifierInterface; use Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface; use Heystack\Ecommerce\Locale\Interfaces\LocaleServiceInterface; use Heystack\Ecommerce\Locale\Interfaces\ZoneInterface; use Heystack\Ecommerce\Locale\Traits\HasLocaleServiceTrait; /** * @package Heystack\Ecommerce\Locale */ class Zone implements ZoneInterface { use HasLocaleServiceTrait; /** * @var */ protected $name; /** * @var \Heystack\Ecommerce\Locale\Interfaces\CountryInterface[] */ protected $countries = []; /** * @var \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface|null */ protected $currency; /** * @param \Heystack\Ecommerce\Locale\Interfaces\LocaleServiceInterface $localeService * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService * @param string $name * @param array $countries * @param string|void $currency */ public function __construct( LocaleServiceInterface $localeService, CurrencyServiceInterface $currencyService, $name, array $countries, $currency = null ) { $this->localeService = $localeService; $this->currencyService = $currencyService; $this->name = $name; $this->setCountries($countries); if ($currency !== null) { $this->currency = $this->currencyService->getCurrency(new Identifier($currency)); } } /** * Returns a unique identifier * @return \Heystack\Core\Identifier\Identifier */ public function getIdentifier() { return new Identifier($this->name); } /** * Returns the name of the Zone object * @return string */ public function getName() { return $this->name; } /** * @param \Heystack\Core\Identifier\IdentifierInterface $identifier * @return void * @throws \InvalidArgumentException */ public function addCountry(IdentifierInterface $identifier) { if (!$this->localeService->hasCountry($identifier)) { throw new \InvalidArgumentException( sprintf( "Country '%s' added to zone doesn't exist in locale service", $identifier->getFull() ) ); } $this->countries[$identifier->getFull()] = $this->localeService->getCountry($identifier); } /** * @param array $countries * @return void */ public function setCountries(array $countries) { foreach ($countries as $country) { $this->addCountry($country instanceof IdentifierInterface ? : new Identifier($country)); } } /** * @return \Heystack\Ecommerce\Locale\Interfaces\CountryInterface[] */ public function getCountries() { return $this->countries; } /** * @param \Heystack\Core\Identifier\IdentifierInterface $identifier * @return bool */ public function hasCountry(IdentifierInterface $identifier) { return isset($this->countries[$identifier->getFull()]); } /** * @return \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface */ public function getCurrency() { return $this->currency; } } |