diff --git a/components/ILIAS/AccessControl/classes/class.ilRbacSystem.php b/components/ILIAS/AccessControl/classes/class.ilRbacSystem.php index 399c9b9002bf..cb81f5b91b69 100755 --- a/components/ILIAS/AccessControl/classes/class.ilRbacSystem.php +++ b/components/ILIAS/AccessControl/classes/class.ilRbacSystem.php @@ -72,7 +72,7 @@ public static function getInstance(): ilRbacSystem return self::$instance; } global $DIC; - if ($DIC instanceof \Pimple\Container && isset($DIC['rbacsystem'])) { + if ($DIC instanceof \ILIAS\DI\Container && isset($DIC['rbacsystem'])) { return self::$instance = $DIC['rbacsystem']; } throw new \LogicException( diff --git a/components/ILIAS/DI/README.md b/components/ILIAS/DI/README.md index 26ad3aea6632..2bd2846aa4e1 100755 --- a/components/ILIAS/DI/README.md +++ b/components/ILIAS/DI/README.md @@ -51,3 +51,25 @@ $tree = $DIC->logger()->tree(); $objDefinition = $DIC["objDefinition"]; ``` + +## Local Containers + +Components which need a container of their own (a "local DIC") extend or instantiate +`ILIAS\DI\ServiceContainer`, which is also the base of the global `ILIAS\DI\Container`. +They MUST NOT use the classes of pimple directly, so the library stays an +implementation detail of this component. + +```php +use ILIAS\DI\ServiceContainer; + +class MyComponentDIC extends ServiceContainer +{ + public function __construct() + { + parent::__construct(); + $this['repository'] = static fn(ServiceContainer $c): Repository => new DBRepository(); + } +} +``` + +Code which expects the global `$DIC` types against `ILIAS\DI\Container`. diff --git a/components/ILIAS/DI/src/Container.php b/components/ILIAS/DI/src/Container.php index e11b0cd9ede9..39ee36fe68c6 100755 --- a/components/ILIAS/DI/src/Container.php +++ b/components/ILIAS/DI/src/Container.php @@ -34,7 +34,7 @@ * This just exposes some services in the container as plain methods * to help IDEs when using ILIAS. */ -class Container extends \Pimple\Container +class Container extends ServiceContainer { /** * Get interface to the Database. diff --git a/components/ILIAS/DI/src/ServiceContainer.php b/components/ILIAS/DI/src/ServiceContainer.php new file mode 100644 index 000000000000..315b7639e215 --- /dev/null +++ b/components/ILIAS/DI/src/ServiceContainer.php @@ -0,0 +1,33 @@ +dic)) { global $DIC; diff --git a/components/ILIAS/Init/classes/Dependencies/InitComponentService.php b/components/ILIAS/Init/classes/Dependencies/InitComponentService.php index 4d17fed57a1e..fed46698702a 100755 --- a/components/ILIAS/Init/classes/Dependencies/InitComponentService.php +++ b/components/ILIAS/Init/classes/Dependencies/InitComponentService.php @@ -33,9 +33,9 @@ public function init(\ILIAS\DI\Container $c): void ); } - public function initInternal(\ILIAS\DI\Container $c): \Pimple\Container + public function initInternal(\ILIAS\DI\Container $c): \ILIAS\DI\ServiceContainer { - $int = new \Pimple\Container(); + $int = new \ILIAS\DI\ServiceContainer(); $data_factory = new \ILIAS\Data\Factory(); $int["plugin_state_db"] = fn($int): \ilPluginStateDB => new ilPluginStateDBOverIlDBInterface( diff --git a/components/ILIAS/Init/src/AllModernComponents.php b/components/ILIAS/Init/src/AllModernComponents.php index e50f113ad099..c8f72d200260 100644 --- a/components/ILIAS/Init/src/AllModernComponents.php +++ b/components/ILIAS/Init/src/AllModernComponents.php @@ -157,7 +157,7 @@ public function __construct( * using their legacy offset, since it cannot be service-located by legacy components * otherwise. */ - protected function populateComponentsInLegacyEnvironment(\Pimple\Container $DIC): void + protected function populateComponentsInLegacyEnvironment(\ILIAS\DI\Container $DIC): void { $DIC[\ILIAS\Data\Factory::class] = fn(): \ILIAS\Data\Factory => $this->data_factory; diff --git a/components/ILIAS/LearningSequence/classes/class.ilLSDI.php b/components/ILIAS/LearningSequence/classes/class.ilLSDI.php index ccd046c6305d..33a5f7bf9cb2 100755 --- a/components/ILIAS/LearningSequence/classes/class.ilLSDI.php +++ b/components/ILIAS/LearningSequence/classes/class.ilLSDI.php @@ -18,7 +18,7 @@ declare(strict_types=1); -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; use ILIAS\GlobalScreen\ScreenContext\ScreenContext; class ilLSDI extends Container diff --git a/components/ILIAS/LearningSequence/classes/class.ilLSLocalDI.php b/components/ILIAS/LearningSequence/classes/class.ilLSLocalDI.php index 0875a9854b5c..d4070d9d71a6 100755 --- a/components/ILIAS/LearningSequence/classes/class.ilLSLocalDI.php +++ b/components/ILIAS/LearningSequence/classes/class.ilLSLocalDI.php @@ -18,7 +18,7 @@ declare(strict_types=1); -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; use ILIAS\Data\Factory as DataFactory; use ILIAS\HTTP\Wrapper\ArrayBasedRequestWrapper; diff --git a/components/ILIAS/Logging/classes/error/class.ilLoggingErrorSettings.php b/components/ILIAS/Logging/classes/error/class.ilLoggingErrorSettings.php index b484dab5e2dc..e5a4831cb09f 100755 --- a/components/ILIAS/Logging/classes/error/class.ilLoggingErrorSettings.php +++ b/components/ILIAS/Logging/classes/error/class.ilLoggingErrorSettings.php @@ -40,7 +40,7 @@ public function __construct(LoggingConfig $config) public static function getInstance(): self { global $DIC; - if ($DIC instanceof \Pimple\Container && isset($DIC['logging.services'])) { + if ($DIC instanceof \ILIAS\DI\Container && isset($DIC['logging.services'])) { return new self($DIC['logging.services']->getConfig()); } return new self(new \ILIAS\Logging\Configuration\NullLoggingConfig()); diff --git a/components/ILIAS/OrgUnit/classes/class.ilOrgUnitLocalDIC.php b/components/ILIAS/OrgUnit/classes/class.ilOrgUnitLocalDIC.php index cd7b0bd9dfc0..1badb9680a8b 100755 --- a/components/ILIAS/OrgUnit/classes/class.ilOrgUnitLocalDIC.php +++ b/components/ILIAS/OrgUnit/classes/class.ilOrgUnitLocalDIC.php @@ -18,7 +18,7 @@ declare(strict_types=1); -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; class ilOrgUnitLocalDIC { diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php index 149cf61aa5c2..552b0984d725 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php @@ -30,7 +30,7 @@ class ilPrgUpdateProgressCronJob extends CronJob { private const ID = 'prg_update_progress'; - protected Pimple\Container $dic; + protected ILIAS\DI\ServiceContainer $dic; protected ilLanguage $lng; protected ilStudyProgrammeSettingsDBRepository $settings_repo; protected ilPRGAssignmentDBRepository $assignment_repo; diff --git a/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeDIC.php b/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeDIC.php index f2e1d29aab45..f276e585ab99 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeDIC.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeDIC.php @@ -18,7 +18,7 @@ declare(strict_types=1); -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; class ilStudyProgrammeDIC { diff --git a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php index 59718031a25d..f6e205a06de4 100755 --- a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php +++ b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php @@ -23,9 +23,9 @@ */ class ilStudyProgrammeMembershipSourceReaderFactory { - protected Pimple\Container $dic; + protected ILIAS\DI\Container $dic; - public function __construct(Pimple\Container $dic) + public function __construct(ILIAS\DI\Container $dic) { $this->dic = $dic; } diff --git a/components/ILIAS/Test/src/GUIFactory.php b/components/ILIAS/Test/src/GUIFactory.php index ae478334cd68..395a5d50d294 100644 --- a/components/ILIAS/Test/src/GUIFactory.php +++ b/components/ILIAS/Test/src/GUIFactory.php @@ -20,7 +20,7 @@ namespace ILIAS\Test; -use Pimple\Container as PimpleContainer; +use ILIAS\DI\Container as GlobalContainer; use ILIAS\Test\Scoring\Manual\ConsecutiveScoringGUI; use ILIAS\Test\Scoring\Manual\TestScoring; use ILIAS\Test\Scoring\Manual\ConsecutiveScoring; @@ -43,7 +43,7 @@ public function get(string $gui_name, \ilObjTest $test_obj) } public function __construct( - private PimpleContainer $global_dic, + private GlobalContainer $global_dic, private TestDIC $test_dic ) { $this->definitions['ILIAS\Test\Scoring\Manual\ConsecutiveScoringGUI'] = fn(\ilObjTest $test_obj): ConsecutiveScoringGUI => diff --git a/components/ILIAS/Test/src/TestDIC.php b/components/ILIAS/Test/src/TestDIC.php index 134b3bb69325..940edf34a5ae 100755 --- a/components/ILIAS/Test/src/TestDIC.php +++ b/components/ILIAS/Test/src/TestDIC.php @@ -53,12 +53,12 @@ use ILIAS\TestQuestionPool\RequestDataCollector as QPLRequestDataCollector; use ILIAS\Data\Factory as DataFactory; use ILIAS\DI\Container as ILIASContainer; -use Pimple\Container as PimpleContainer; +use ILIAS\DI\ServiceContainer; -class TestDIC extends PimpleContainer +class TestDIC extends ServiceContainer { protected static ?self $dic = null; - protected static ?PimpleContainer $specific_dic = null; + protected static ?ServiceContainer $specific_dic = null; public static function dic(): self { diff --git a/components/ILIAS/Test/tests/TestDICTest.php b/components/ILIAS/Test/tests/TestDICTest.php index 199d0c523f4a..1cc0ac2c73df 100644 --- a/components/ILIAS/Test/tests/TestDICTest.php +++ b/components/ILIAS/Test/tests/TestDICTest.php @@ -16,7 +16,7 @@ * *********************************************************************/ -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; use ILIAS\Test\TestDIC; class TestDICTest extends ilTestBaseTestCase diff --git a/components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php b/components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php index 5cad50136567..a3c640da4568 100644 --- a/components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php +++ b/components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php @@ -489,43 +489,43 @@ protected function buildLocalDICMock(): ILIAS\Test\TestDIC { $local_dic_mock = $this->getMockBuilder(ILIAS\Test\TestDIC::class) ->onlyMethods([])->getMock(); - $local_dic_mock['question.general_properties.repository'] = fn(Pimple\Container $c) + $local_dic_mock['question.general_properties.repository'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository::class ); - $local_dic_mock['request_data_collector'] = fn(Pimple\Container $c) + $local_dic_mock['request_data_collector'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ILIAS\Test\RequestDataCollector::class ); - $local_dic_mock['participant.access_filter.factory'] = fn(Pimple\Container $c) + $local_dic_mock['participant.access_filter.factory'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ilTestParticipantAccessFilterFactory::class ); - $local_dic_mock['logging.logger'] = fn(Pimple\Container $c) + $local_dic_mock['logging.logger'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ILIAS\Test\Logging\TestLogger::class ); - $local_dic_mock['logging.viewer'] = fn(Pimple\Container $c) + $local_dic_mock['logging.viewer'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ILIAS\Test\Logging\TestLogViewer::class ); - $local_dic_mock['shuffler'] = fn(Pimple\Container $c) + $local_dic_mock['shuffler'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ilTestShuffler::class ); - $local_dic_mock['results.presentation.factory'] = fn(Pimple\Container $c) + $local_dic_mock['results.presentation.factory'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( ILIAS\Test\Results\Presentation\Factory::class ); - $local_dic_mock['results.data.factory'] = fn(Pimple\Container $c) + $local_dic_mock['results.data.factory'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( ILIAS\Test\Results\Data\Factory::class ); - $local_dic_mock['results.data.repository'] = fn(Pimple\Container $c) + $local_dic_mock['results.data.repository'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( \ILIAS\Test\Results\Data\Repository::class ); - $local_dic_mock['questions.properties.repository'] = fn(Pimple\Container $c) + $local_dic_mock['questions.properties.repository'] = fn(\ILIAS\DI\ServiceContainer $c) => $this->createMock( ILIAS\Test\Questions\Properties\Repository::class ); diff --git a/components/ILIAS/TestQuestionPool/src/QuestionPoolDIC.php b/components/ILIAS/TestQuestionPool/src/QuestionPoolDIC.php index f2cce4c0a366..f2a08497c00a 100755 --- a/components/ILIAS/TestQuestionPool/src/QuestionPoolDIC.php +++ b/components/ILIAS/TestQuestionPool/src/QuestionPoolDIC.php @@ -20,7 +20,7 @@ namespace ILIAS\TestQuestionPool; -use Pimple\Container as PimpleContainer; +use ILIAS\DI\ServiceContainer; use ILIAS\DI\Container as ILIASContainer; use ILIAS\TestQuestionPool\Questions\SuggestedSolution\SuggestedSolutionsDatabaseRepository; use ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository; @@ -29,7 +29,7 @@ use ILIAS\Test\Settings\GlobalSettings\Repository as GlobalTestSettingsRepository; use ILIAS\Test\Settings\GlobalSettings\GlobalTestSettings; -class QuestionPoolDIC extends PimpleContainer +class QuestionPoolDIC extends ServiceContainer { public static ?self $dic = null; diff --git a/components/ILIAS/User/src/LocalDIC.php b/components/ILIAS/User/src/LocalDIC.php index 8620f0a3d60f..df487d9fa112 100755 --- a/components/ILIAS/User/src/LocalDIC.php +++ b/components/ILIAS/User/src/LocalDIC.php @@ -40,12 +40,12 @@ use ILIAS\User\Profile\Fields\Custom\CollectTypesObjective; use ILIAS\User\Profile\Fields\Standard; use ILIAS\User\Profile\ChangeListeners\CollectListenersObjective; -use Pimple\Container as PimpleContainer; +use ILIAS\DI\ServiceContainer; use ILIAS\DI\Container as ILIASContainer; use ILIAS\Data\Factory as DataFactory; use ILIAS\Data\UUID\Factory as UUIDFactory; -class LocalDIC extends PimpleContainer +class LocalDIC extends ServiceContainer { private static ?LocalDIC $dic = null; diff --git a/components/ILIAS/WebDAV/classes/class.ilWebDAVDIC.php b/components/ILIAS/WebDAV/classes/class.ilWebDAVDIC.php index bd8919d7603d..1225c6d1481c 100755 --- a/components/ILIAS/WebDAV/classes/class.ilWebDAVDIC.php +++ b/components/ILIAS/WebDAV/classes/class.ilWebDAVDIC.php @@ -18,7 +18,7 @@ declare(strict_types=1); -use Pimple\Container; +use ILIAS\DI\ServiceContainer as Container; use ILIAS\DI\Container as ILIASContainer; use ILIAS\WebDAV\Mount\Repository as MountRepository; use ILIAS\WebDAV\Mount\RepositoryDB as MountRepositoryDB;