get defintions files from file container
This commit is contained in:
parent
0c8c04701a
commit
e0c5dff74f
@ -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.",
|
"description": "Provides bridges for OXID services that are not reliably listed in the DIC cache.",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -15,12 +15,9 @@
|
|||||||
|
|
||||||
namespace D3\DIContainerHandler;
|
namespace D3\DIContainerHandler;
|
||||||
|
|
||||||
use D3\ModCfg\Application\Model\Modulemetadata\d3moduleconfiguration;
|
use d3DIContainerCache;
|
||||||
use d3CacheContainer;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use OxidEsales\Eshop\Core\Module\ModuleList;
|
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use OxidEsales\Eshop\Core\Request;
|
|
||||||
use OxidEsales\Facts\Config\ConfigFile;
|
use OxidEsales\Facts\Config\ConfigFile;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
@ -102,12 +99,12 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return d3CacheContainer|object
|
* @return d3DIContainerCache|object
|
||||||
*/
|
*/
|
||||||
public function d3GetCacheContainer()
|
public function d3GetCacheContainer()
|
||||||
{
|
{
|
||||||
require_once $this->d3GetCacheFilePath();
|
require_once $this->d3GetCacheFilePath();
|
||||||
return oxNew(d3CacheContainer::class);
|
return oxNew(d3DIContainerCache::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +129,8 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
{
|
{
|
||||||
$loader = $this->d3GetFileLoader($container);
|
$loader = $this->d3GetFileLoader($container);
|
||||||
|
|
||||||
foreach ($this->getShopDefinitionFiles() as $file) {
|
$fileContainer = oxNew(definitionFileContainer::class);
|
||||||
|
foreach ($fileContainer->getYamlDefinitions() as $file) {
|
||||||
$fullPath = $this->d3GetConfig()->getModulesDir().$file;
|
$fullPath = $this->d3GetConfig()->getModulesDir().$file;
|
||||||
if (is_file($fullPath)) {
|
if (is_file($fullPath)) {
|
||||||
$loader->load($file);
|
$loader->load($file);
|
||||||
@ -165,7 +163,7 @@ class d3DicHandler implements d3DicHandlerInterface
|
|||||||
|
|
||||||
if (false == defined('OXID_PHP_UNIT')) {
|
if (false == defined('OXID_PHP_UNIT')) {
|
||||||
$dumper = new PhpDumper($container);
|
$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 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
|
* clone
|
||||||
*/
|
*/
|
||||||
|
68
definitionFileContainer.php
Normal file
68
definitionFileContainer.php
Normal 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 = [];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user