![]() 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-two-factor-auth/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\TwoFactorAuth\Model; use Magento\TwoFactorAuth\Api\Data\CountryInterface; /** * Country entity registry * * @SuppressWarnings(PHPMD.ShortVariable) */ class CountryRegistry { /** * @var array */ private $registry = []; /** * @var array */ private $registryByKey = [ 'code' => [], ]; /** * Remove registry entity by id * * @param int $id */ public function removeById(int $id): void { if (isset($this->registry[$id])) { unset($this->registry[$id]); } foreach (array_keys($this->registryByKey) as $key) { $reverseMap = array_flip($this->registryByKey[$key]); if (isset($reverseMap[$id])) { unset($this->registryByKey[$key][$reverseMap[$id]]); } } } /** * Push one object into registry * * @param int $id * @return CountryInterface|null */ public function retrieveById(int $id): ?CountryInterface { if (isset($this->registry[$id])) { return $this->registry[$id]; } return null; } /** * Retrieve by Code value * * @param string $value * @return CountryInterface|null */ public function retrieveByCode(string $value): ?CountryInterface { if (isset($this->registryByKey['code'][$value])) { return $this->retrieveById($this->registryByKey['code'][$value]); } return null; } /** * Push one object into registry * * @param Country $country */ public function push(Country $country): void { $this->registry[$country->getId()] = $country->getDataModel(); foreach (array_keys($this->registryByKey) as $key) { $this->registryByKey[$key][$country->getData($key)] = $country->getId(); } } }