![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-tax/Model/Calculation/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Tax\Model\Calculation; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Tax\Model\Calculation\Rate as TaxRateModel; use Magento\Tax\Model\Calculation\RateFactory as TaxRateModelFactory; class RateRegistry { /** * Tax rate model factory * * @var TaxRateModelFactory */ private $taxRateModelFactory; /** * Tax rate models * * @var TaxRateModel[] */ private $taxRateRegistryById = []; /** * Constructor * * @param TaxRateModelFactory $taxModelRateFactory */ public function __construct( TaxRateModelFactory $taxModelRateFactory ) { $this->taxRateModelFactory = $taxModelRateFactory; } /** * Register TaxRate Model to registry * * @param TaxRateModel $taxRateModel * @return void */ public function registerTaxRate(TaxRateModel $taxRateModel) { $this->taxRateRegistryById[$taxRateModel->getId()] = $taxRateModel; } /** * Retrieve TaxRate Model from registry given an id * * @param int $taxRateId * @return TaxRateModel * @throws NoSuchEntityException */ public function retrieveTaxRate($taxRateId) { if (isset($this->taxRateRegistryById[$taxRateId])) { return $this->taxRateRegistryById[$taxRateId]; } /** @var TaxRateModel $taxRateModel */ $taxRateModel = $this->taxRateModelFactory->create()->load($taxRateId); if (!$taxRateModel->getId()) { // tax rate does not exist throw NoSuchEntityException::singleField('taxRateId', $taxRateId); } $this->taxRateRegistryById[$taxRateModel->getId()] = $taxRateModel; return $taxRateModel; } /** * Remove an instance of the TaxRate Model from the registry * * @param int $taxRateId * @return void */ public function removeTaxRate($taxRateId) { unset($this->taxRateRegistryById[$taxRateId]); } }