ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
InitCtrlService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 final class InitCtrlService
32 {
40  public function init(Container $dic): void
41  {
42  $this->abortIfMissingDependencies($dic);
43  $ilias_path = dirname(__FILE__, 5) . '/';
44 
45  try {
46  $ctrl_structure = new ilCtrlStructure(
50  );
51  } catch (Throwable $t) {
52  throw new ilCtrlException(self::class . " could not require artifacts, try `composer du` first.");
53  }
54 
55  $token_repository = new ilCtrlTokenRepository();
56  $path_factory = new ilCtrlPathFactory($ctrl_structure);
57  $context = new ilCtrlContext(
58  $path_factory,
59  $dic->http()->wrapper()->query(),
60  $dic->refinery()
61  );
62 
63  // create global instance of ilCtrl
64  $GLOBALS['ilCtrl'] = new ilCtrl(
65  $ctrl_structure,
66  $token_repository,
67  $path_factory,
68  $context,
69  $dic["http.response_sender_strategy"],
70  $dic->http()->request(),
71  $dic->http()->wrapper()->post(),
72  $dic->http()->wrapper()->query(),
73  $dic->refinery(),
74  $dic["component.factory"],
75  new ilCtrlSubject(),
77  );
78 
79  // add helper function to DI container that
80  // returns the global instance.
81  $dic['ilCtrl'] = static function () {
82  return $GLOBALS['ilCtrl'];
83  };
84  }
85 
93  private function abortIfMissingDependencies(Container $dic): void
94  {
95  if (!$dic->offsetExists('http')) {
96  throw new ilCtrlException("Cannot initialize ilCtrl if HTTP Services are not yet available.");
97  }
98 
99  if (!$dic->offsetExists('refinery')) {
100  throw new ilCtrlException("Cannot initialize ilCtrl if Refinery Factory is not yet available.");
101  }
102 
103  // if (!$dic->offsetExists('ilDB')) {
104  // throw new ilCtrlException("Cannot initialize ilCtrl if Database is not yet available.");
105  // }
106  }
107 }
$context
Definition: webdav.php:31
Class InitCtrlService wraps the initialization of ilCtrl.
Class ilCtrlPathFactory.
Class ilCtrlContext is responsible for holding the current context information.
Class ilCtrlStructure holds the currently read control structure.
init(Container $dic)
Initializes the ilCtrl service.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$GLOBALS["DIC"]
Definition: wac.php:31
Class ilCtrlTokenRepository.
abortIfMissingDependencies(Container $dic)
Aborts if another dependency required by the ctrl service is not yet available.
ilCtrl exceptions
$dic
Definition: result.php:32