mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-29 21:09:10 +02:00
Compare commits
1 Commits
develop
...
faf/Servic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a95f6c605 |
@@ -563,6 +563,17 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att
|
||||
</event_datum>
|
||||
</event_data>
|
||||
</event>
|
||||
<event id="EVENT_SERVICE_LOCATOR_INITIALIZED" _delta="define">
|
||||
<name>Service Locator Initialized</name>
|
||||
<internal>true</internal>
|
||||
<description><![CDATA[Inform the listeners that Service Locator has been (re)initialized]]></description>
|
||||
<event_data>
|
||||
<event_datum id="file_name">
|
||||
<description>The configuration file used to initialize Service Locator</description>
|
||||
<type>string</type>
|
||||
</event_datum>
|
||||
</event_data>
|
||||
</event>
|
||||
</events>
|
||||
<meta>
|
||||
<classes>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
use Combodo\iTop\Application\EventRegister\ApplicationEvents;
|
||||
use Combodo\iTop\Core\MetaModel\FriendlyNameType;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
@@ -130,6 +131,8 @@ abstract class MetaModel
|
||||
private static $m_aClassToFile = [];
|
||||
/** @var string */
|
||||
protected static $m_sEnvironment = ITOP_DEFAULT_ENV;
|
||||
/** @var \Combodo\iTop\Service\DependencyInjection\ServiceLocator */
|
||||
private static ?ServiceLocator $oServiceLocator = null;
|
||||
|
||||
/**
|
||||
* Objects currently created/updated.
|
||||
@@ -5778,6 +5781,7 @@ abstract class MetaModel
|
||||
// Event service must be initialized after the MetaModel startup, otherwise it cannot discover classes implementing the iEventServiceSetup interface
|
||||
EventService::InitService();
|
||||
EventService::FireEvent(new EventData(ApplicationEvents::APPLICATION_EVENT_METAMODEL_STARTED));
|
||||
self::$oServiceLocator = new ServiceLocator(self::GetConfig());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -5793,6 +5797,8 @@ abstract class MetaModel
|
||||
// Event service must be initialized after the MetaModel startup, otherwise it cannot discover classes implementing the iEventServiceSetup interface
|
||||
EventService::InitService();
|
||||
EventService::FireEvent(new EventData(ApplicationEvents::APPLICATION_EVENT_METAMODEL_STARTED));
|
||||
self::$oServiceLocator = new ServiceLocator();
|
||||
self::$oServiceLocator->InitFromConfig(self::GetConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -7085,6 +7091,11 @@ abstract class MetaModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetServiceLocator(): ?ServiceLocator
|
||||
{
|
||||
return self::$oServiceLocator;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard attribute lists
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<service_locator>
|
||||
<services>
|
||||
<service id="DataFeatureRemoverExtension">
|
||||
<class id="Combodo\iTop\DataFeatureRemoval\Service\DataFeatureRemoverExtensionService"/>
|
||||
</service>
|
||||
</services>
|
||||
</service_locator>
|
||||
@@ -16,7 +16,6 @@ use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalException;
|
||||
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalHelper;
|
||||
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalLog;
|
||||
use Combodo\iTop\DataFeatureRemoval\Service\DataCleanupService;
|
||||
use Combodo\iTop\DataFeatureRemoval\Service\DataFeatureRemoverExtensionService;
|
||||
use Combodo\iTop\DataFeatureRemoval\Service\StaticDeletionPlan;
|
||||
use Combodo\iTop\Service\Session\SessionParameters;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\SetupAudit;
|
||||
@@ -77,7 +76,7 @@ class DataFeatureRemovalController extends Controller
|
||||
$this->iCount = 0;
|
||||
foreach ($this->aCountClassesToCleanup as $sClass => $iCount) {
|
||||
$sModuleName = MetaModel::GetModuleName($sClass);
|
||||
$aExtensions = DataFeatureRemoverExtensionService::GetInstance()->GetIncludingExtensions($sModuleName);
|
||||
$aExtensions = Metamodel::GetServiceLocator()->Get('DataFeatureRemoverExtension')->GetIncludingExtensions($sModuleName);
|
||||
$sExtensions = implode(' ', $aExtensions);
|
||||
$aColumns = ['ClassName','FeatureName','Module','Occurrence'];
|
||||
$aData[] = [$sClass,$sExtensions,$sModuleName,$iCount];
|
||||
@@ -190,7 +189,7 @@ class DataFeatureRemovalController extends Controller
|
||||
);
|
||||
|
||||
if (count($aSelectedModules) === 0) {
|
||||
$aSelectedExtensions = DataFeatureRemoverExtensionService::GetInstance()->GetExtensionMap()->GetSelectedExtensions($oConfig, array_keys($aAddedExtensions), array_keys($aRemovedExtensions));
|
||||
$aSelectedExtensions = Metamodel::GetServiceLocator()->Get('DataFeatureRemoverExtension')->GetExtensionMap()->GetSelectedExtensions($oConfig, array_keys($aAddedExtensions), array_keys($aRemovedExtensions));
|
||||
$oParameters->SetParameter('selected_extensions', $this->ConvertIntoSetupFormat($aSelectedExtensions));
|
||||
}
|
||||
|
||||
@@ -364,9 +363,9 @@ class DataFeatureRemovalController extends Controller
|
||||
{
|
||||
$aExtensionsData = [];
|
||||
if ($bIncludePackageExtensions) {
|
||||
$aExtensionsRef = DataFeatureRemoverExtensionService::GetInstance()->GetExtensionMap()->GetAllExtensionsWithPreviouslyInstalled();
|
||||
$aExtensionsRef = Metamodel::GetServiceLocator()->Get('DataFeatureRemoverExtension')->GetExtensionMap()->GetAllExtensionsWithPreviouslyInstalled();
|
||||
} else {
|
||||
$aExtensionsRef = DataFeatureRemoverExtensionService::GetInstance()->ReadItopExtensions();
|
||||
$aExtensionsRef = Metamodel::GetServiceLocator()->Get('DataFeatureRemoverExtension')->ReadItopExtensions();
|
||||
}
|
||||
|
||||
foreach ($aExtensionsRef as $oExtension) {
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\DataFeatureRemoval\Helper;
|
||||
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
class DataFeatureRemovalConfig
|
||||
{
|
||||
private static DataFeatureRemovalConfig $oInstance;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): DataFeatureRemovalConfig
|
||||
{
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new DataFeatureRemovalConfig();
|
||||
}
|
||||
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
public function Get(string $sParamName, $default = null)
|
||||
{
|
||||
return MetaModel::GetModuleSetting(DataFeatureRemovalHelper::MODULE_NAME, $sParamName, $default);
|
||||
}
|
||||
|
||||
public function GetBoolean(string $sParamName, $default = null): bool
|
||||
{
|
||||
$res = $this->Get($sParamName, $default);
|
||||
|
||||
return boolval($res);
|
||||
}
|
||||
|
||||
public function IsEnabled(): bool
|
||||
{
|
||||
return $this->GetBoolean('enable', false);
|
||||
}
|
||||
|
||||
public function Set(string $sParamName, $value)
|
||||
{
|
||||
$oConfig = utils::GetConfig();
|
||||
$oConfig->SetModuleSetting(DataFeatureRemovalHelper::MODULE_NAME, $sParamName, $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2026 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\DataFeatureRemoval\Hook;
|
||||
|
||||
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalHelper;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Combodo\iTop\Service\Events\iEventServiceSetup;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
class EventListener implements iEventServiceSetup
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function RegisterEventsAndListeners()
|
||||
{
|
||||
EventService::RegisterListener(
|
||||
sEvent: \EVENT_SERVICE_LOCATOR_INITIALIZED,
|
||||
callback: [$this, 'OnServiceLocatorInitialized']
|
||||
);
|
||||
}
|
||||
|
||||
public function OnServiceLocatorInitialized(EventData $oEventData): void
|
||||
{
|
||||
MetaModel::GetServiceLocator()->AddClassesFromFile(utils::GetAbsoluteModulePath(DataFeatureRemovalHelper::MODULE_NAME).'Config/ServiceLocator.xml');
|
||||
}
|
||||
}
|
||||
@@ -13,34 +13,19 @@ use MetaModel;
|
||||
|
||||
class DataFeatureRemoverExtensionService
|
||||
{
|
||||
private static DataFeatureRemoverExtensionService $oInstance;
|
||||
private ?iTopExtensionsMap $oMap = null;
|
||||
private array $aItopExtensions = [];
|
||||
private array $aIncludingExtensionsByModuleName = [];
|
||||
|
||||
protected function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): DataFeatureRemoverExtensionService
|
||||
{
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new DataFeatureRemoverExtensionService();
|
||||
}
|
||||
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?DataFeatureRemoverExtensionService $oInstance): void
|
||||
{
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sModuleName
|
||||
*
|
||||
* @return array
|
||||
* @throws \Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetIncludingExtensions(string $sModuleName): array
|
||||
{
|
||||
@@ -62,6 +47,7 @@ class DataFeatureRemoverExtensionService
|
||||
|
||||
/**
|
||||
* @return \iTopExtensionsMap
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetExtensionMap(): iTopExtensionsMap
|
||||
{
|
||||
@@ -74,6 +60,7 @@ class DataFeatureRemoverExtensionService
|
||||
|
||||
/**
|
||||
* @return iTopExtension[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function ReadItopExtensions(): array
|
||||
{
|
||||
|
||||
@@ -10,10 +10,10 @@ return array(
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DataCleanupSummaryEntity' => $baseDir . '/src/Entity/DataCleanupSummaryEntity.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DeletionPlanEntity' => $baseDir . '/src/Entity/DeletionPlanEntity.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DeletionPlanItem' => $baseDir . '/src/Entity/DeletionPlanItem.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalConfig' => $baseDir . '/src/Helper/DataFeatureRemovalConfig.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => $baseDir . '/src/Helper/DataFeatureRemovalException.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => $baseDir . '/src/Helper/DataFeatureRemovalHelper.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => $baseDir . '/src/Helper/DataFeatureRemovalLog.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Hook\\EventListener' => $baseDir . '/src/Hook/EventListener.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => $baseDir . '/src/Service/DataCleanupService.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => $baseDir . '/src/Service/DataFeatureRemoverExtensionService.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => $baseDir . '/src/Service/ObjectService.php',
|
||||
|
||||
@@ -25,10 +25,10 @@ class ComposerStaticInit4f96a7199e2c0d90e547333758b26464
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DataCleanupSummaryEntity' => __DIR__ . '/../..' . '/src/Entity/DataCleanupSummaryEntity.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DeletionPlanEntity' => __DIR__ . '/../..' . '/src/Entity/DeletionPlanEntity.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Entity\\DeletionPlanItem' => __DIR__ . '/../..' . '/src/Entity/DeletionPlanItem.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalConfig' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalConfig.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalException.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalHelper.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalLog.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Hook\\EventListener' => __DIR__ . '/../..' . '/src/Hook/EventListener.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => __DIR__ . '/../..' . '/src/Service/DataCleanupService.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => __DIR__ . '/../..' . '/src/Service/DataFeatureRemoverExtensionService.php',
|
||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => __DIR__ . '/../..' . '/src/Service/ObjectService.php',
|
||||
|
||||
@@ -56,7 +56,6 @@ use Symfony\Component\Security\Csrf\CsrfTokenManager;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\RuntimeLoader\FactoryRuntimeLoader;
|
||||
use utils;
|
||||
use ZipArchive;
|
||||
|
||||
abstract class Controller extends AbstractController
|
||||
{
|
||||
@@ -129,6 +128,9 @@ abstract class Controller extends AbstractController
|
||||
*/
|
||||
public function __construct($sViewPath = '', $sModuleName = 'core', $aAdditionalPaths = [], array $aThemes = ['application/forms/itop_console_layout.html.twig', 'application/forms/wip_form_demonstrator.html.twig'])
|
||||
{
|
||||
if (is_null(MetaModel::GetServiceLocator())) {
|
||||
MetaModel::InitServiceLocator();
|
||||
}
|
||||
IssueLog::Enable(APPROOT.'log/error.log');
|
||||
$this->aLinkedScripts = [];
|
||||
$this->aLinkedStylesheets = [];
|
||||
|
||||
@@ -16,7 +16,7 @@ use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
use Combodo\iTop\Forms\Register\RegisterException;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIException;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
|
||||
*/
|
||||
public static function ListAttributeCodesByCategory(string $sClass, string $sCategory = ''): array
|
||||
{
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
$aNonGroupableAttributes = [
|
||||
'AttributeLinkedSet',
|
||||
'AttributeFriendlyName',
|
||||
|
||||
@@ -13,8 +13,8 @@ use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* A block to choose some values from attribute of a given class.
|
||||
@@ -58,7 +58,7 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
|
||||
|
||||
try {
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
$aValues = $oModelReflection->GetAllowedValues_att($sClass, $sAttCode);
|
||||
|
||||
$oOptionsRegister->SetOption('choices', array_flip($aValues ?? []));
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Combodo\iTop\Forms\Block\DataModel\Dashlet;
|
||||
use Combodo\iTop\Forms\Block\DataModel\AttributeChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* A block to manage an attribute of a data model class for grouping purpose
|
||||
@@ -32,7 +32,7 @@ class ClassAttributeGroupByFormBlock extends AttributeChoiceFormBlock
|
||||
public function UpdateOptions(OptionsRegister $oOptionsRegister): void
|
||||
{
|
||||
parent::UpdateOptions($oOptionsRegister);
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
|
||||
$aGroupBy = [];
|
||||
try {
|
||||
|
||||
@@ -8,13 +8,10 @@
|
||||
namespace Combodo\iTop\Forms\Block;
|
||||
|
||||
use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompiler;
|
||||
use Combodo\iTop\PropertyType\PropertyTypeService;
|
||||
use Combodo\iTop\Service\Cache\DataModelDependantCache;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use MetaModel;
|
||||
use ModelReflection;
|
||||
use ModelReflectionRuntime;
|
||||
use utils;
|
||||
|
||||
class FormBlockService
|
||||
{
|
||||
@@ -22,7 +19,7 @@ class FormBlockService
|
||||
|
||||
protected function __construct(?ModelReflection $oModelReflection = null)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', $oModelReflection ?? new ModelReflectionRuntime());
|
||||
MetaModel::GetServiceLocator()->RegisterService('ModelReflection', $oModelReflection ?? new ModelReflectionRuntime());
|
||||
}
|
||||
|
||||
final public static function GetInstance(?ModelReflection $oModelReflection = null): FormBlockService
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Converter;
|
||||
|
||||
use Combodo\iTop\Service\DependencyInjection\DIException;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIException;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use ModelReflection;
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ class OqlToClassConverter extends AbstractConverter
|
||||
}
|
||||
|
||||
/** @var ModelReflection $oModelReflection */
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
try {
|
||||
$oQuery = $oModelReflection->GetQuery($oData);
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Format;
|
||||
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Class IO format.
|
||||
@@ -23,7 +23,7 @@ class ClassIOFormat extends AbstractIOFormat
|
||||
{
|
||||
// Check class validity
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
if (!$oModelReflection->IsValidClass($sClassName)) {
|
||||
throw new FormBlockIOException("Class ".json_encode($sClassName)." is not valid");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
namespace Combodo\iTop\Forms\Validator;
|
||||
|
||||
use Combodo\iTop\Forms\IO\Converter\OqlToClassConverter;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use MetaModel;
|
||||
use ModelReflection;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
@@ -42,7 +43,7 @@ class AttributeExistValidator extends ConstraintValidator
|
||||
$sClass = "UserRequest";
|
||||
|
||||
/** List attributes @var ModelReflection $oModelReflection */
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
$aAttributeCodes = array_keys($oModelReflection->ListAttributes($sClass));
|
||||
|
||||
if (!in_array($value, $aAttributeCodes, true)) {
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace Combodo\iTop\PropertyType\ValueType\Leaf;
|
||||
use Combodo\iTop\DesignElement;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\PropertyType\ValueType\Branch\AbstractBranchValueType;
|
||||
use Combodo\iTop\PropertyType\ValueType\Branch\ValueTypePropertyTree;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
@@ -32,7 +31,7 @@ class ValueTypeClass extends AbstractLeafValueType
|
||||
|
||||
$sCategories = $oDomNode->GetChildText('categories-csv', '');
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$oModelReflection = MetaModel::GetServiceLocator()->get('ModelReflection');
|
||||
|
||||
$sChoices = "[\n";
|
||||
$aClasses = $oModelReflection->GetClasses($sCategories, true);
|
||||
|
||||
@@ -189,7 +189,7 @@ class DataModelDependantCache
|
||||
protected function GetStorageRootDir(): string
|
||||
{
|
||||
// Could be forced by tests
|
||||
return $this->sStorageRootDir ?? utils::GetCachePath();
|
||||
return $this->sStorageRootDir ?? utils::GetCachePath().DIRECTORY_SEPARATOR.'DataModelDependantCache';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,24 +7,89 @@
|
||||
|
||||
namespace Combodo\iTop\Service\DependencyInjection;
|
||||
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompilerException;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Config;
|
||||
use DOMDocument;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ServiceLocator implements ContainerInterface
|
||||
{
|
||||
private static ServiceLocator $oInstance;
|
||||
private array $aServices = [];
|
||||
private array $aClasses = [];
|
||||
|
||||
protected function __construct()
|
||||
public const DEFAULT_PRODUCTION_SERVICES = __DIR__.DIRECTORY_SEPARATOR.'ServiceLocator.xml';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): ServiceLocator
|
||||
final public function InitFromConfig(Config $oConfig): void
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new ServiceLocator();
|
||||
}
|
||||
$this->InitFromFile($oConfig->Get('service_locator.services.production') ?? self::DEFAULT_PRODUCTION_SERVICES);
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
/**
|
||||
* Init ServiceLocator from an XML file
|
||||
*
|
||||
* @param string $sFileName
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
final public function InitFromFile(string $sFileName): void
|
||||
{
|
||||
$this->aServices = [];
|
||||
$this->aClasses = [];
|
||||
|
||||
$this->AddClassesFromFile($sFileName);
|
||||
|
||||
// Service locator has been (re)initialized
|
||||
EventService::FireEvent(new EventData(sEvent: \EVENT_SERVICE_LOCATOR_INITIALIZED, aEventData: ['file_name' => $sFileName]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or replace classes from an XML file
|
||||
*
|
||||
* @param string $sFileName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function AddClassesFromFile(string $sFileName): void
|
||||
{
|
||||
$oDoc = new DOMDocument();
|
||||
libxml_clear_errors();
|
||||
$oDoc->loadXML(file_get_contents($sFileName));
|
||||
$aErrors = libxml_get_errors();
|
||||
if (count($aErrors) > 0) {
|
||||
throw new PropertyTypeCompilerException('Property types definition not correctly formatted!');
|
||||
}
|
||||
$oNode = $oDoc->firstChild;
|
||||
$oNode = $oNode->getElementsByTagName('services')->item(0);
|
||||
foreach ($oNode->getElementsByTagName('service') as $oServiceElement) {
|
||||
$sServiceName = $oServiceElement->getAttribute('id');
|
||||
$oClassNode = $oNode->getElementsByTagName('class')->item(0);
|
||||
if (!$oClassNode) {
|
||||
continue;
|
||||
}
|
||||
$sClassName = $oClassNode->getAttribute('id');
|
||||
|
||||
$this->RegisterClass($sServiceName, $sClassName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Service with the instance of the service
|
||||
*
|
||||
* @param string $sServiceName
|
||||
* @param string $sClassName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function RegisterClass(string $sServiceName, string $sClassName): void
|
||||
{
|
||||
$this->aClasses[$sServiceName] = $sClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,15 +115,22 @@ class ServiceLocator implements ContainerInterface
|
||||
*/
|
||||
public function get(string $id): mixed
|
||||
{
|
||||
if (!isset($this->aServices[$id])) {
|
||||
throw new DIException("Service ".json_encode($id)." not found");
|
||||
if (isset($this->aServices[$id])) {
|
||||
return $this->aServices[$id];
|
||||
}
|
||||
|
||||
return $this->aServices[$id];
|
||||
// Search in classes
|
||||
if (!isset($this->aClasses[$id])) {
|
||||
throw new DIException("Service ".json_encode($id)." not found");
|
||||
}
|
||||
$oService = new $this->aClasses[$id]();
|
||||
$this->RegisterService($id, $oService);
|
||||
|
||||
return $oService;
|
||||
}
|
||||
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return isset($this->aServices[$id]);
|
||||
return isset($this->aServices[$id]) || isset($this->aClasses[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
8
sources/Service/DependencyInjection/ServiceLocator.xml
Normal file
8
sources/Service/DependencyInjection/ServiceLocator.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<service_locator>
|
||||
<services>
|
||||
<service id="ModelReflection">
|
||||
<class id="ModelReflectionRuntime"/>
|
||||
</service>
|
||||
</services>
|
||||
</service_locator>
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup\FeatureRemoval;
|
||||
|
||||
use Combodo\iTop\DataFeatureRemoval\Service\DataFeatureRemoverExtensionService;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\ModelReflectionSerializer;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\SetupAudit;
|
||||
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
|
||||
use Combodo\iTop\Test\UnitTest\Service\UnitTestRunTimeEnvironment;
|
||||
use Config;
|
||||
use MetaModel;
|
||||
use RunTimeEnvironment;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
@@ -67,7 +67,7 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
$oRuntimeEnvironment->CopySetupFiles();
|
||||
$oConfig = new Config(utils::GetConfigFilePath($this->GetTestEnvironment()));
|
||||
$aRemovedExtensions = ['nominal_ext1', 'finalclass_ext2'];
|
||||
$aSelectedExtensions = DataFeatureRemoverExtensionService::GetInstance()->GetExtensionMap()->GetSelectedExtensions($oConfig, ['finalclass_ext1', 'finalclass_ext3'], $aRemovedExtensions);
|
||||
$aSelectedExtensions = Metamodel::GetServiceLocator()->Get('DataFeatureRemoverExtension')->GetExtensionMap()->GetSelectedExtensions($oConfig, ['finalclass_ext1', 'finalclass_ext3'], $aRemovedExtensions);
|
||||
$aSelectedModules = $oRuntimeEnvironment->GetModulesToLoadFromSelectedExtensions($oConfig, $aSelectedExtensions);
|
||||
|
||||
$oRuntimeEnvironment->DoCompile($aSelectedExtensions, $aRemovedExtensions, $aSelectedModules);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompiler;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class FormsCompilerTest extends ItopDataTestCase
|
||||
@@ -24,7 +23,7 @@ class FormsCompilerTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testCompileFormFromXML(string $sXMLContent, string $sExpectedPHP)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
MetaModel::GetServiceLocator()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$sProducedPHP = PropertyTypeCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompiler;
|
||||
use Combodo\iTop\PropertyType\PropertyTypeDesign;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class XMLSerializerTest extends ItopDataTestCase
|
||||
@@ -24,7 +22,7 @@ class XMLSerializerTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testSerializeXML($inputContent, string $sPropertyTypeXML, string $sExpectedXMLContent)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
MetaModel::GetServiceLocator()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$oDOMDocument = new PropertyTypeDesign();
|
||||
$oDOMDocument->preserveWhiteSpace = false;
|
||||
@@ -184,7 +182,7 @@ XML,
|
||||
*/
|
||||
public function testUnserializeXML($sInputXMLContent, string $sPropertyTypeXML, $expectedValue)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
MetaModel::GetServiceLocator()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$oDoc = new PropertyTypeDesign();
|
||||
$oDoc->loadXML($sInputXMLContent);
|
||||
|
||||
Reference in New Issue
Block a user