Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions components/ILIAS/DI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion components/ILIAS/DI/src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions components/ILIAS/DI/src/ServiceContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/


declare(strict_types=1);

namespace ILIAS\DI;

/**
* Dependency injection container for the global as well as for local, component
* specific containers.
*
* Components extend or instantiate this class instead of the underlying library
* (pimple/pimple), which stays an implementation detail of the DI component.
*/
class ServiceContainer extends \Pimple\Container
{
}
4 changes: 2 additions & 2 deletions components/ILIAS/ILIASObject/src/LocalDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
use ILIAS\ILIASObject\Properties\Aggregator;
use ILIAS\ILIASObject\Properties\MultiPropertiesManipulator;
use ILIAS\ILIASObject\Properties\Translations\CachedRepository as TranslationsRepository;
use Pimple\Container as PimpleContainer;
use ILIAS\DI\ServiceContainer;
use ILIAS\DI\Container as ILIASContainer;

class LocalDIC extends PimpleContainer
class LocalDIC extends ServiceContainer
{
private static ?LocalDIC $dic = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
declare(strict_types=1);

use ILIAS\Data;
use Pimple\Container;
use ILIAS\DI\ServiceContainer as Container;
use ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder;

trait ilIndividualAssessmentDIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ilObjIndividualAssessment extends ilObject
protected ilIndividualAssessmentMembersStorageDB $members_storage;
protected ilIndividualAssessmentAccessHandler $access_handler;
protected ilAccessHandler $il_access_handler;
protected ?Pimple\Container $dic = null;
protected ?ILIAS\DI\ServiceContainer $dic = null;

protected ?ilIndividualAssessmentInfoSettings $info_settings = null;
protected ?ilIndividualAssessmentFileStorage $file_storage = null;
Expand Down Expand Up @@ -286,7 +286,7 @@ public function getParentContainerIdByType(int $id, array $types): int
return 0;
}

protected function getDic(): Pimple\Container
protected function getDic(): ILIAS\DI\ServiceContainer
{
if (is_null($this->dic)) {
global $DIC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Init/src/AllModernComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/LearningSequence/classes/class.ilLSDI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

declare(strict_types=1);

use Pimple\Container;
use ILIAS\DI\ServiceContainer as Container;

class ilOrgUnitLocalDIC
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

declare(strict_types=1);

use Pimple\Container;
use ILIAS\DI\ServiceContainer as Container;

class ilStudyProgrammeDIC
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/Test/src/GUIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =>
Expand Down
6 changes: 3 additions & 3 deletions components/ILIAS/Test/src/TestDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Test/tests/TestDICTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*********************************************************************/

use Pimple\Container;
use ILIAS\DI\ServiceContainer as Container;
use ILIAS\Test\TestDIC;

class TestDICTest extends ilTestBaseTestCase
Expand Down
20 changes: 10 additions & 10 deletions components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/TestQuestionPool/src/QuestionPoolDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/User/src/LocalDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/WebDAV/classes/class.ilWebDAVDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading