diff --git a/application/datamodel.application.xml b/application/datamodel.application.xml index 206fbe40a..0cca2b0aa 100644 --- a/application/datamodel.application.xml +++ b/application/datamodel.application.xml @@ -999,14 +999,12 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att - + - {{query.selected_class}} - {{group_by.value}} - + {{group_by.attribute}} diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 977cf54b2..4cea94364 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -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', + '�' => $vendorDir . '/symfony/cache/Traits/ValueWrapper.php', ); diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index ab4134cc7..92a502981 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.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', + '�' => __DIR__ . '/..' . '/symfony/cache/Traits/ValueWrapper.php', ); public static function getInitializer(ClassLoader $loader) diff --git a/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php b/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php index 5edf03482..3e64fce2d 100644 --- a/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php +++ b/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php @@ -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) { diff --git a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php index 7b7cf32aa..7f47e5eab 100644 --- a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php +++ b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php @@ -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 ?? [])); diff --git a/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php b/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php index 22a33bf32..9b606b567 100644 --- a/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php +++ b/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php @@ -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 { diff --git a/sources/Forms/Block/FormBlockService.php b/sources/Forms/Block/FormBlockService.php index d45089fe6..ca3e38019 100644 --- a/sources/Forms/Block/FormBlockService.php +++ b/sources/Forms/Block/FormBlockService.php @@ -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(); } diff --git a/sources/Forms/IO/Converter/OqlToClassConverter.php b/sources/Forms/IO/Converter/OqlToClassConverter.php index d5520c7cb..1211ecd07 100644 --- a/sources/Forms/IO/Converter/OqlToClassConverter.php +++ b/sources/Forms/IO/Converter/OqlToClassConverter.php @@ -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) { diff --git a/sources/Forms/IO/Format/AttributeTypeArrayIOFormat.php b/sources/Forms/IO/Format/AttributeTypeArrayIOFormat.php index 3fb0e046f..132f6ff22 100644 --- a/sources/Forms/IO/Format/AttributeTypeArrayIOFormat.php +++ b/sources/Forms/IO/Format/AttributeTypeArrayIOFormat.php @@ -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; /** diff --git a/sources/Forms/IO/Format/ClassIOFormat.php b/sources/Forms/IO/Format/ClassIOFormat.php index 61cdcfb23..ec19e94ce 100644 --- a/sources/Forms/IO/Format/ClassIOFormat.php +++ b/sources/Forms/IO/Format/ClassIOFormat.php @@ -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"); } diff --git a/sources/Forms/Validator/AttributeExistValidator.php b/sources/Forms/Validator/AttributeExistValidator.php index ab364b6f2..f765a0393 100644 --- a/sources/Forms/Validator/AttributeExistValidator.php +++ b/sources/Forms/Validator/AttributeExistValidator.php @@ -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)) { diff --git a/sources/PropertyTree/ValueType/ValueTypeClass.php b/sources/PropertyTree/ValueType/ValueTypeClass.php index fe462a257..7961a6ed1 100644 --- a/sources/PropertyTree/ValueType/ValueTypeClass.php +++ b/sources/PropertyTree/ValueType/ValueTypeClass.php @@ -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); diff --git a/sources/Service/DependencyInjection/DIService.php b/sources/Service/DependencyInjection/ServiceLocator.php similarity index 58% rename from sources/Service/DependencyInjection/DIService.php rename to sources/Service/DependencyInjection/ServiceLocator.php index f5d0ad75c..a8f64f340 100644 --- a/sources/Service/DependencyInjection/DIService.php +++ b/sources/Service/DependencyInjection/ServiceLocator.php @@ -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]); } } diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/FormsCompilerTest.php b/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/FormsCompilerTest.php index dd8302acc..0810b0ba3 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/FormsCompilerTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/FormsCompilerTest.php @@ -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);