diff --git a/Model/ModuleMetadata.php b/Model/ModuleMetadata.php index d61841b..4561015 100644 --- a/Model/ModuleMetadata.php +++ b/Model/ModuleMetadata.php @@ -20,10 +20,7 @@ use Magento\Framework\App\CacheInterface; use Magento\Framework\App\Config; use Magento\Framework\App\ProductMetadataInterface; -use Magento\Framework\Component\ComponentRegistrarInterface; -use Magento\Framework\Component\ComponentRegistrar; -use Magento\Framework\Filesystem\Directory\ReadFactory; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Module\ModuleListInterface; use Psr\Log\LoggerInterface; /** @@ -44,16 +41,6 @@ class ModuleMetadata implements ModuleMetadataInterface */ private $version; - /** - * @var ComponentRegistrar - */ - private $componentRegistrar; - - /** - * @var ReadFactory - */ - private $readFactory; - /** * ProductMetadataInterface */ @@ -65,36 +52,31 @@ class ModuleMetadata implements ModuleMetadataInterface private $cache; /** - * @var SerializerInterface + * @var LoggerInterface */ - private $serializer; + private $logger; /** - * @var LoggerInterface + * @var ModuleListInterface */ - private $logger; + private $moduleList; /** - * Metadata constructor. - * - * @param ResourceInterface $resource * @param ProductMetadataInterface $systemMetadata * @param CacheInterface $cache + * @param ModuleListInterface $moduleList + * @param LoggerInterface $logger */ public function __construct( - ComponentRegistrarInterface $componentRegistrar, - ReadFactory $readFactory, - SerializerInterface $serializer, ProductMetadataInterface $systemMetadata, CacheInterface $cache, + ModuleListInterface $moduleList, LoggerInterface $logger ) { - $this->componentRegistrar = $componentRegistrar; - $this->readFactory = $readFactory; $this->systemMetadata = $systemMetadata; $this->cache = $cache; - $this->serializer = $serializer; $this->logger = $logger; + $this->moduleList = $moduleList; } /** @@ -156,22 +138,14 @@ private function getModuleVersion(): string if ($this->version) { return (string) $this->version; } - + $this->version = (string) $this->cache->load(self::VERSION_CACHE_KEY); if ($this->version) { return $this->version; } - $path = $this->componentRegistrar->getPath( - ComponentRegistrar::MODULE, - 'Vipps_Payment' - ); - try { - $directoryRead = $this->readFactory->create($path); - $composerJsonData = $directoryRead->readFile('composer.json'); - $data = $this->serializer->unserialize($composerJsonData); - $this->version = $data['version'] ?? 'UNKNOWN'; + $this->version = (string)$this->moduleList->getOne('Vipps_Payment')['setup_version']; } catch (\Throwable $t) { $this->logger->error($t); $this->version = 'UNKNOWN'; diff --git a/etc/module.xml b/etc/module.xml index 97d0e76..4466c13 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -14,7 +14,7 @@ ~ IN THE SOFTWARE. --> - +