mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°8772 - Move DIService into PSR-11 Service Locator
This commit is contained in:
@@ -999,14 +999,12 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att
|
||||
</node>
|
||||
<node id="values">
|
||||
<label>UI:DashletHeaderDynamic:Prop-Values</label>
|
||||
<value-type xsi:type="Combodo-ValueType-CollectionOfValues">
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttributeValue">
|
||||
<data-transform>
|
||||
<xml-format xsi:type="xml-format-csv"/>
|
||||
</data-transform>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttributeValue">
|
||||
<class>{{query.selected_class}}</class>
|
||||
<attribute>{{group_by.value}}</attribute>
|
||||
</value-type>
|
||||
<attribute>{{group_by.attribute}}</attribute>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
@@ -598,7 +598,7 @@ return array(
|
||||
'Combodo\\iTop\\Service\\Base\\iDataPostProcessor' => $baseDir . '/sources/Service/Base/iDataPostProcessor.php',
|
||||
'Combodo\\iTop\\Service\\Cache\\DataModelDependantCache' => $baseDir . '/sources/Service/Cache/DataModelDependantCache.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\DIException' => $baseDir . '/sources/Service/DependencyInjection/DIException.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\DIService' => $baseDir . '/sources/Service/DependencyInjection/DIService.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\ServiceLocator' => $baseDir . '/sources/Service/DependencyInjection/ServiceLocator.php',
|
||||
'Combodo\\iTop\\Service\\Events\\Description\\EventDataDescription' => $baseDir . '/sources/Service/Events/Description/EventDataDescription.php',
|
||||
'Combodo\\iTop\\Service\\Events\\Description\\EventDescription' => $baseDir . '/sources/Service/Events/Description/EventDescription.php',
|
||||
'Combodo\\iTop\\Service\\Events\\EventData' => $baseDir . '/sources/Service/Events/EventData.php',
|
||||
@@ -3932,5 +3932,5 @@ return array(
|
||||
'privUITransactionFile' => $baseDir . '/application/transaction.class.inc.php',
|
||||
'privUITransactionSession' => $baseDir . '/application/transaction.class.inc.php',
|
||||
'utils' => $baseDir . '/application/utils.inc.php',
|
||||
'©' => $vendorDir . '/symfony/cache/Traits/ValueWrapper.php',
|
||||
'<EFBFBD>' => $vendorDir . '/symfony/cache/Traits/ValueWrapper.php',
|
||||
);
|
||||
|
||||
@@ -984,7 +984,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'Combodo\\iTop\\Service\\Base\\iDataPostProcessor' => __DIR__ . '/../..' . '/sources/Service/Base/iDataPostProcessor.php',
|
||||
'Combodo\\iTop\\Service\\Cache\\DataModelDependantCache' => __DIR__ . '/../..' . '/sources/Service/Cache/DataModelDependantCache.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\DIException' => __DIR__ . '/../..' . '/sources/Service/DependencyInjection/DIException.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\DIService' => __DIR__ . '/../..' . '/sources/Service/DependencyInjection/DIService.php',
|
||||
'Combodo\\iTop\\Service\\DependencyInjection\\ServiceLocator' => __DIR__ . '/../..' . '/sources/Service/DependencyInjection/ServiceLocator.php',
|
||||
'Combodo\\iTop\\Service\\Events\\Description\\EventDataDescription' => __DIR__ . '/../..' . '/sources/Service/Events/Description/EventDataDescription.php',
|
||||
'Combodo\\iTop\\Service\\Events\\Description\\EventDescription' => __DIR__ . '/../..' . '/sources/Service/Events/Description/EventDescription.php',
|
||||
'Combodo\\iTop\\Service\\Events\\EventData' => __DIR__ . '/../..' . '/sources/Service/Events/EventData.php',
|
||||
@@ -4318,7 +4318,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'privUITransactionFile' => __DIR__ . '/../..' . '/application/transaction.class.inc.php',
|
||||
'privUITransactionSession' => __DIR__ . '/../..' . '/application/transaction.class.inc.php',
|
||||
'utils' => __DIR__ . '/../..' . '/application/utils.inc.php',
|
||||
'©' => __DIR__ . '/..' . '/symfony/cache/Traits/ValueWrapper.php',
|
||||
'<EFBFBD>' => __DIR__ . '/..' . '/symfony/cache/Traits/ValueWrapper.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
|
||||
@@ -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\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
|
||||
*/
|
||||
public static function ListAttributeCodesByCategory(string $sClass, string $sCategory = ''): array
|
||||
{
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$aAttributeCodes = [];
|
||||
|
||||
switch ($sCategory) {
|
||||
|
||||
@@ -13,7 +13,7 @@ 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\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
|
||||
|
||||
try {
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$aValues = $oModelReflection->GetAllowedValues_att($sClass, $sAttCode);
|
||||
|
||||
$oOptionsRegister->SetOption('choices', array_flip($aValues ?? []));
|
||||
|
||||
@@ -10,7 +10,7 @@ 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\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Dict;
|
||||
use Exception;
|
||||
|
||||
@@ -32,7 +32,7 @@ class ClassAttributeGroupByFormBlock extends AttributeChoiceFormBlock
|
||||
public function UpdateOptions(OptionsRegister $oOptionsRegister): void
|
||||
{
|
||||
parent::UpdateOptions($oOptionsRegister);
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
|
||||
$aGroupBy = [];
|
||||
try {
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Combodo\iTop\Forms\Block;
|
||||
use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\Forms\Compiler\FormsCompiler;
|
||||
use Combodo\iTop\Service\Cache\DataModelDependantCache;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use ModelReflection;
|
||||
use ModelReflectionRuntime;
|
||||
use utils;
|
||||
@@ -23,7 +23,7 @@ class FormBlockService
|
||||
|
||||
protected function __construct(ModelReflection $oModelReflection = null)
|
||||
{
|
||||
DIService::GetInstance()->RegisterService('ModelReflection', $oModelReflection ?? new ModelReflectionRuntime());
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', $oModelReflection ?? new ModelReflectionRuntime());
|
||||
$this->oCacheService = DataModelDependantCache::GetInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace Combodo\iTop\Forms\IO\Converter;
|
||||
|
||||
use Combodo\iTop\Service\DependencyInjection\DIException;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
use Exception;
|
||||
@@ -33,7 +33,7 @@ class OqlToClassConverter extends AbstractConverter
|
||||
}
|
||||
|
||||
/** @var ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
try {
|
||||
$oQuery = $oModelReflection->GetQuery($oData);
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Format;
|
||||
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Format;
|
||||
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ class ClassIOFormat extends AbstractIOFormat
|
||||
{
|
||||
// Check class validity
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
if (!$oModelReflection->IsValidClass($sClassName)) {
|
||||
throw new FormBlockIOException("Class ".json_encode($sClassName)." is not valid");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace Combodo\iTop\Forms\Validator;
|
||||
|
||||
use Combodo\iTop\Forms\IO\Converter\OqlToClassConverter;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
@@ -42,7 +42,7 @@ class AttributeExistValidator extends ConstraintValidator
|
||||
$sClass = "UserRequest";
|
||||
|
||||
/** List attributes @var ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
$aAttributeCodes = array_keys($oModelReflection->ListAttributes($sClass));
|
||||
|
||||
if (!in_array($value, $aAttributeCodes, true)) {
|
||||
|
||||
@@ -12,7 +12,7 @@ use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\TextFormBlock;
|
||||
use Combodo\iTop\PropertyTree\AbstractProperty;
|
||||
use Combodo\iTop\PropertyTree\ValueType\AbstractValueType;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use utils;
|
||||
|
||||
class ValueTypeClass extends AbstractValueType
|
||||
@@ -30,7 +30,7 @@ class ValueTypeClass extends AbstractValueType
|
||||
|
||||
$sCategories = $oDomNode->GetChildText('categories-csv');
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
|
||||
$sChoices = "[\n";
|
||||
$aClasses = $oModelReflection->GetClasses($sCategories, true);
|
||||
|
||||
@@ -7,19 +7,21 @@
|
||||
|
||||
namespace Combodo\iTop\Service\DependencyInjection;
|
||||
|
||||
class DIService
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ServiceLocator implements ContainerInterface
|
||||
{
|
||||
private static DIService $oInstance;
|
||||
private static ServiceLocator $oInstance;
|
||||
private array $aServices = [];
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): DIService
|
||||
final public static function GetInstance(): ServiceLocator
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new DIService();
|
||||
static::$oInstance = new ServiceLocator();
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
@@ -28,8 +30,6 @@ class DIService
|
||||
/**
|
||||
* Register a service by name
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @param string $sName Name of the service to register
|
||||
* @param mixed $oService Service to register
|
||||
*
|
||||
@@ -43,24 +43,22 @@ class DIService
|
||||
/**
|
||||
* Get a previously registered service
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @param string $sName name of the service to get
|
||||
* @param bool $bMustBeFound if true a DIException is thrown when the service is not found
|
||||
* @param string $id Service id to search for
|
||||
*
|
||||
* @return mixed The service or null when the service is not found and $bMustBeFound is false
|
||||
* @throws \Combodo\iTop\Service\DependencyInjection\DIException
|
||||
*/
|
||||
final public function GetService(string $sName, bool $bMustBeFound = true): mixed
|
||||
public function get(string $id): mixed
|
||||
{
|
||||
if (!isset($this->aServices[$sName])) {
|
||||
if ($bMustBeFound) {
|
||||
throw new DIException("Service ".json_encode($sName)." not found");
|
||||
}
|
||||
|
||||
return null;
|
||||
if (!isset($this->aServices[$id])) {
|
||||
throw new DIException("Service ".json_encode($id)." not found");
|
||||
}
|
||||
|
||||
return $this->aServices[$sName];
|
||||
return $this->aServices[$id];
|
||||
}
|
||||
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return isset($this->aServices[$id]);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Forms\Compiler\FormsCompiler;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class FormsCompilerTest extends ItopDataTestCase
|
||||
@@ -24,7 +24,7 @@ class FormsCompilerTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testCompileFormFromXML(string $sXMLContent, string $sExpectedPHP)
|
||||
{
|
||||
DIService::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$sProducedPHP = FormsCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user