get defintions files from file container

This commit is contained in:
Daniel Seifert 2022-12-30 23:05:33 +01:00
parent 0c8c04701a
commit e0c5dff74f
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
3 changed files with 75 additions and 65 deletions

View File

@ -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": [

View File

@ -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
*/

View File

@ -0,0 +1,68 @@
<?php
namespace D3\DIContainerHandler;
class definitionFileContainer
{
public const TYPE_YAML = 'yml';
protected $definitionFiles = [
self::TYPE_YAML => []
];
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 = [];
}
}