From e0c5dff74f63676b8176b984ac41e29ba6191165 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 30 Dec 2022 23:05:33 +0100 Subject: [PATCH] get defintions files from file container --- composer.json | 2 +- d3DicHandler.php | 70 ++++--------------------------------- definitionFileContainer.php | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 definitionFileContainer.php diff --git a/composer.json b/composer.json index 010df4e..ef3cd3a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "d3/dicontainerhandler", + "name": "d3/oxid-dic-handler", "description": "Provides bridges for OXID services that are not reliably listed in the DIC cache.", "type": "library", "keywords": [ diff --git a/d3DicHandler.php b/d3DicHandler.php index 2f4f197..b9e9cdf 100644 --- a/d3DicHandler.php +++ b/d3DicHandler.php @@ -15,12 +15,9 @@ namespace D3\DIContainerHandler; -use D3\ModCfg\Application\Model\Modulemetadata\d3moduleconfiguration; -use d3CacheContainer; +use d3DIContainerCache; use Exception; -use OxidEsales\Eshop\Core\Module\ModuleList; use OxidEsales\Eshop\Core\Registry; -use OxidEsales\Eshop\Core\Request; use OxidEsales\Facts\Config\ConfigFile; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -102,12 +99,12 @@ class d3DicHandler implements d3DicHandlerInterface } /** - * @return d3CacheContainer|object + * @return d3DIContainerCache|object */ public function d3GetCacheContainer() { require_once $this->d3GetCacheFilePath(); - return oxNew(d3CacheContainer::class); + return oxNew(d3DIContainerCache::class); } /** @@ -132,7 +129,8 @@ class d3DicHandler implements d3DicHandlerInterface { $loader = $this->d3GetFileLoader($container); - foreach ($this->getShopDefinitionFiles() as $file) { + $fileContainer = oxNew(definitionFileContainer::class); + foreach ($fileContainer->getYamlDefinitions() as $file) { $fullPath = $this->d3GetConfig()->getModulesDir().$file; if (is_file($fullPath)) { $loader->load($file); @@ -165,7 +163,7 @@ class d3DicHandler implements d3DicHandlerInterface if (false == defined('OXID_PHP_UNIT')) { $dumper = new PhpDumper($container); - file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(array('class' => 'd3CacheContainer'))); + file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(array('class' => 'd3DIContainerCache'))); } } } @@ -180,62 +178,6 @@ class d3DicHandler implements d3DicHandlerInterface return oxNew(ContainerBuilder::class); } - /** - * @return array - */ - public function getShopDefinitionFiles() - { - return $this->getDefinitionFiles('d3DICDefinitionFiles'); - } - - /** - * @param $sMetaDataIdent - * @return array - */ - public function getDefinitionFiles($sMetaDataIdent) - { - $aDICDefintionFileList = []; - - /** @var ModuleList $oModuleList */ - $oModuleList = oxNew(ModuleList::class); - $aActiveModuleIdList = array_keys($oModuleList->getActiveModuleInfo()); - - if (Registry::get(Request::class)->getRequestEscapedParameter('cl') === 'module_main' - && ($sCurrentModuleId = Registry::get(Request::class)->getRequestEscapedParameter('oxid')) - && false === in_array($sCurrentModuleId, $aActiveModuleIdList) - ) { - $aActiveModuleIdList[] = $sCurrentModuleId; - } - - foreach ($aActiveModuleIdList as $sModuleId) { - $oModuleConfiguration = oxNew(d3moduleconfiguration::class); - $aDICDefintionFiles = $oModuleConfiguration->getInfo($sMetaDataIdent, $sModuleId); - if (isset($aDICDefintionFiles) && is_array($aDICDefintionFiles)) { - $aDICDefintionFileList = array_merge($aDICDefintionFileList, $aDICDefintionFiles); - } - } - - $aBaseServiceIds = array( - 'd3/modcfg' - ); - - $aDefFileList = array(); - - foreach ($aDICDefintionFileList as $sKey => $sFileName) { - foreach ($aBaseServiceIds as $sBaseKey => $sBaseClass) { - if (strstr(strtolower($sFileName), strtolower($sBaseClass))) { - $aDefFileList[$sBaseKey] = $sFileName; - unset($aDICDefintionFileList[$sKey]); - } - } - } - - ksort($aDefFileList, SORT_NUMERIC); - $aDefFileList = array_merge($aDefFileList, $aDICDefintionFileList); - - return $aDefFileList; - } - /** * clone */ diff --git a/definitionFileContainer.php b/definitionFileContainer.php new file mode 100644 index 0000000..3163dbe --- /dev/null +++ b/definitionFileContainer.php @@ -0,0 +1,68 @@ + [] + ]; + + protected $allowedTypes = [ + self::TYPE_YAML + ]; + + public function __construct() + { + $this->addYamlDefinitions('d3/modcfg/Config/services.yaml'); + } + + public function addDefinitions($definitionFile, $type) + { + if (!in_array($type, $this->allowedTypes)) { + throw new \InvalidArgumentException('invalid definition file type'); + } + + $this->definitionFiles[$type][md5($definitionFile)] = $definitionFile; + } + + public function addYamlDefinitions($definitionFile) + { + $this->addDefinitions($definitionFile, self::TYPE_YAML); + } + + public function getDefinitions($type) + { + if (!in_array($type, $this->allowedTypes)) { + throw new \InvalidArgumentException('invalid definition file type'); + } + + return $this->definitionFiles[$type]; + } + + public function getYamlDefinitions() + { + return $this->getDefinitions(self::TYPE_YAML); + } + + /** + * @param string $definitionFile + * @return bool + */ + public function has($definitionFile): bool + { + return isset($this->definitionFiles[md5($definitionFile)]); + } + + public function getAll() + { + return $this->definitionFiles; + } + + public function clear() + { + $this->definitionFiles = []; + } +} \ No newline at end of file