From 4c9c7d5f5a1eb72d072260e11024adde5fffee8d Mon Sep 17 00:00:00 2001 From: Lukas Scharmer Date: Mon, 30 Sep 2024 17:07:46 +0200 Subject: [PATCH] LegalDocuments: Load ui factory and template later --- .../classes/class.ilObjDataProtectionGUI.php | 2 +- .../LegalDocuments/classes/ConsumerToolbox/Blocks.php | 2 +- .../LegalDocuments/classes/ConsumerToolbox/UI.php | 8 ++++---- Services/LegalDocuments/classes/DefaultMappings.php | 3 +-- .../classes/Provide/ProvideDocument.php | 2 +- .../LegalDocuments/classes/Provide/ProvideHistory.php | 2 +- .../class.ilLegalDocumentsAdministrationGUI.php | 3 +-- .../test/ConsumerToolbox/BlocksTest.php | 7 +------ .../LegalDocuments/test/ConsumerToolbox/UITest.php | 11 ++++++----- .../classes/class.ilObjTermsOfServiceGUI.php | 2 +- 10 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Services/DataProtection/classes/class.ilObjDataProtectionGUI.php b/Services/DataProtection/classes/class.ilObjDataProtectionGUI.php index 0c0799b8bde7..51f6a1cf5772 100644 --- a/Services/DataProtection/classes/class.ilObjDataProtectionGUI.php +++ b/Services/DataProtection/classes/class.ilObjDataProtectionGUI.php @@ -61,7 +61,7 @@ public function __construct() $this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $config, $this->afterDocumentDeletion(...)); $this->data_protection_settings = $this->createDataProtectionSettings(); - $this->ui = new UI($this->getType(), $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language()); + $this->ui = new UI($this->getType(), $this->container->ui(), $this->container->language()); } public function getType(): string diff --git a/Services/LegalDocuments/classes/ConsumerToolbox/Blocks.php b/Services/LegalDocuments/classes/ConsumerToolbox/Blocks.php index 287249e03a25..6497c258f3ab 100644 --- a/Services/LegalDocuments/classes/ConsumerToolbox/Blocks.php +++ b/Services/LegalDocuments/classes/ConsumerToolbox/Blocks.php @@ -108,7 +108,7 @@ public function sessionStore(): KeyValueStore public function ui(): UI { - return new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language()); + return new UI($this->id, $this->container->ui(), $this->container->language()); } public function user(Settings $global_settings, UserSettings $user_settings, ilObjUser $user): User diff --git a/Services/LegalDocuments/classes/ConsumerToolbox/UI.php b/Services/LegalDocuments/classes/ConsumerToolbox/UI.php index 5b9f04988ddb..f7c3ade42e9d 100644 --- a/Services/LegalDocuments/classes/ConsumerToolbox/UI.php +++ b/Services/LegalDocuments/classes/ConsumerToolbox/UI.php @@ -21,6 +21,7 @@ namespace ILIAS\LegalDocuments\ConsumerToolbox; use ILIAS\UI\Factory as UIFactory; +use ILIAS\DI\UIServices; use ilGlobalTemplateInterface; use ilLanguage; use ilObjLegalDocumentsGUI; @@ -29,20 +30,19 @@ class UI { public function __construct( private readonly string $id, - private readonly UIFactory $create, - private readonly ilGlobalTemplateInterface $main_template, + private readonly UIServices $services, private readonly ilLanguage $language ) { } public function create(): UIFactory { - return $this->create; + return $this->services->factory(); } public function mainTemplate(): ilGlobalTemplateInterface { - return $this->main_template; + return $this->services->mainTemplate(); } public function loadLanguageModule(string $module): void diff --git a/Services/LegalDocuments/classes/DefaultMappings.php b/Services/LegalDocuments/classes/DefaultMappings.php index 2051d96792e2..11fc18683ece 100644 --- a/Services/LegalDocuments/classes/DefaultMappings.php +++ b/Services/LegalDocuments/classes/DefaultMappings.php @@ -42,8 +42,7 @@ public function conditionDefinitions(): SelectionMap { $ui = new UI( $this->id, - $this->container->ui()->factory(), - $this->container->ui()->mainTemplate(), + $this->container->ui(), $this->container->language() ); diff --git a/Services/LegalDocuments/classes/Provide/ProvideDocument.php b/Services/LegalDocuments/classes/Provide/ProvideDocument.php index 5b9423924b76..dd6c8a7b565d 100644 --- a/Services/LegalDocuments/classes/Provide/ProvideDocument.php +++ b/Services/LegalDocuments/classes/Provide/ProvideDocument.php @@ -76,7 +76,7 @@ public function table(object $gui, string $command, ?EditLinks $edit_links = nul $t = new DocumentTable( fn($criterion) => $this->toCondition($criterion)->asComponent(), $this->document_repository, - new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language()), + new UI($this->id, $this->container->ui(), $this->container->language()), new DocumentModal($this->container->ui(), $this->contentAsComponent(...)) ); diff --git a/Services/LegalDocuments/classes/Provide/ProvideHistory.php b/Services/LegalDocuments/classes/Provide/ProvideHistory.php index e4a35515342f..13ba5ed86e2b 100644 --- a/Services/LegalDocuments/classes/Provide/ProvideHistory.php +++ b/Services/LegalDocuments/classes/Provide/ProvideHistory.php @@ -54,7 +54,7 @@ public function __construct( public function table(object $gui, string $command, string $reset_command, string $auto_complete_command): Component { $auto_complete_link = $this->container->ctrl()->getLinkTarget($gui, $auto_complete_command, '', true); - $ui = new UI($this->id, $this->container->ui()->factory(), $this->container->ui()->mainTemplate(), $this->container->language()); + $ui = new UI($this->id, $this->container->ui(), $this->container->language()); $modal = new DocumentModal($this->container->ui(), $this->document->contentAsComponent(...)); $create = fn(string $class, ...$args) => $class === ilObjUser::class && !ilObjUser::_lookupLogin($args[0], 'login') ? null : diff --git a/Services/LegalDocuments/classes/class.ilLegalDocumentsAdministrationGUI.php b/Services/LegalDocuments/classes/class.ilLegalDocumentsAdministrationGUI.php index 24b7586ea2d6..71cc1aef6af6 100644 --- a/Services/LegalDocuments/classes/class.ilLegalDocumentsAdministrationGUI.php +++ b/Services/LegalDocuments/classes/class.ilLegalDocumentsAdministrationGUI.php @@ -53,8 +53,7 @@ public function __construct( $this->container->language()->loadLanguageModule('ldoc'); $this->ui = new UI( $this->config->legalDocuments()->id(), - $this->container->ui()->factory(), - $this->container->ui()->mainTemplate(), + $this->container->ui(), $this->container->language() ); $this->admin = new Administration($this->config, $this->container, $this->ui); diff --git a/Services/LegalDocuments/test/ConsumerToolbox/BlocksTest.php b/Services/LegalDocuments/test/ConsumerToolbox/BlocksTest.php index 9386a52719cd..ee31a45b17d2 100644 --- a/Services/LegalDocuments/test/ConsumerToolbox/BlocksTest.php +++ b/Services/LegalDocuments/test/ConsumerToolbox/BlocksTest.php @@ -95,12 +95,7 @@ public function testGlobalStore(): void public function testUi(): void { $container = $this->mock(Container::class); - - $ui = $this->mock(UIServices::class); - $ui->expects(self::once())->method('factory')->willReturn($this->mock(UIFactory::class)); - $ui->expects(self::once())->method('mainTemplate')->willReturn($this->mock(ilGlobalTemplateInterface::class)); - - $container->method('ui')->willReturn($ui); + $container->expects(self::once())->method('ui')->willReturn($this->mock(UIServices::class)); $container->expects(self::once())->method('language')->willReturn($this->mock(ilLanguage::class)); $instance = new Blocks( diff --git a/Services/LegalDocuments/test/ConsumerToolbox/UITest.php b/Services/LegalDocuments/test/ConsumerToolbox/UITest.php index f51c86e3f237..980e0aca1c35 100644 --- a/Services/LegalDocuments/test/ConsumerToolbox/UITest.php +++ b/Services/LegalDocuments/test/ConsumerToolbox/UITest.php @@ -21,6 +21,7 @@ namespace ILIAS\LegalDocuments\test\ConsumerToolbox; use ILIAS\LegalDocuments\test\ContainerMock; +use ILIAS\DI\UIServices; use ILIAS\UI\Factory as UIFactory; use PHPUnit\Framework\TestCase; use ILIAS\LegalDocuments\ConsumerToolbox\UI; @@ -35,19 +36,19 @@ class UITest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $this->mock(ilLanguage::class))); + $this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIServices::class), $this->mock(ilLanguage::class))); } public function testCreate(): void { $ui_factory = $this->mock(UIFactory::class); - $this->assertSame($ui_factory, (new UI('foo', $ui_factory, $this->mock(ilGlobalTemplateInterface::class), $this->mock(ilLanguage::class)))->create()); + $this->assertSame($ui_factory, (new UI('foo', $this->mockTree(UIServices::class, ['factory' => $ui_factory]), $this->mock(ilLanguage::class)))->create()); } public function testMainTemplate(): void { $template = $this->mock(ilGlobalTemplateInterface::class); - $this->assertSame($template, (new UI('foo', $this->mock(UIFactory::class), $template, $this->mock(ilLanguage::class)))->mainTemplate()); + $this->assertSame($template, (new UI('foo', $this->mockTree(UIServices::class, ['mainTemplate' => $template]), $this->mock(ilLanguage::class)))->mainTemplate()); } public function testTxt(): void @@ -55,7 +56,7 @@ public function testTxt(): void $language = $this->mockMethod(ilLanguage::class, 'txt', ['ldoc_foo'], 'baz'); $language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturnOnConsecutiveCalls(false, true); - $instance = new UI('bar', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $language); + $instance = new UI('bar', $this->mock(UIServices::class), $language); $this->assertSame('baz', $instance->txt('foo')); } @@ -64,7 +65,7 @@ public function testTxtFallback(): void $language = $this->mockMethod(ilLanguage::class, 'txt', ['foo'], 'baz'); $language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturn(false); - $instance = new UI('bar', $this->mock(UIFactory::class), $this->mock(ilGlobalTemplateInterface::class), $language); + $instance = new UI('bar', $this->mock(UIServices::class), $language); $this->assertSame('baz', $instance->txt('foo')); } } diff --git a/Services/TermsOfService/classes/class.ilObjTermsOfServiceGUI.php b/Services/TermsOfService/classes/class.ilObjTermsOfServiceGUI.php index 5dfe02697835..f1e21b116fb4 100644 --- a/Services/TermsOfService/classes/class.ilObjTermsOfServiceGUI.php +++ b/Services/TermsOfService/classes/class.ilObjTermsOfServiceGUI.php @@ -62,7 +62,7 @@ public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a } $this->config = $config; $this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $this->config, $this->afterDocumentDeletion(...)); - $this->ui = new UI(Consumer::ID, $this->dic->ui()->factory(), $this->dic->ui()->mainTemplate(), $this->dic->language()); + $this->ui = new UI(Consumer::ID, $this->dic->ui(), $this->dic->language()); $this->tos_settings = $this->createSettings(); }