ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
InitResourceStorage.php
Go to the documentation of this file.
1<?php
2
46
52{
53 public const D_SERVICE = 'resource_storage';
54 public const D_REPOSITORIES = self::D_SERVICE . '.repositories';
55 public const D_STORAGE_HANDLERS = self::D_SERVICE . '.storage_handlers';
56 public const D_RESOURCE_BUILDER = self::D_SERVICE . '.resource_builder';
57 public const D_FLAVOUR_BUILDER = self::D_SERVICE . '.flavour_builder';
58 public const D_REPOSITORY_PRELOADER = self::D_SERVICE . '.repository_preloader';
59 public const D_SOURCE_BUILDER = self::D_SERVICE . '.source_builder';
60 public const D_LOCK_HANDLER = self::D_SERVICE . '.lock_handler';
61 public const D_FILENAME_POLICY = self::D_SERVICE . '.filename_policy';
62 public const D_STREAM_ACCESS = self::D_SERVICE . '.stream_access';
63 public const D_ARTIFACTS = self::D_SERVICE . '.artifacts';
64 public const D_MACHINE_FACTORY = self::D_SERVICE . '.machine_factory';
65 public const D_MIGRATOR = self::D_SERVICE . '.migrator';
66
67 private bool $init = false;
68
74 {
75 $this->init($c);
77 $c[self::D_STORAGE_HANDLERS],
78 $c[self::D_REPOSITORIES],
79 $c[self::D_LOCK_HANDLER],
80 $c[self::D_STREAM_ACCESS],
81 $c[self::D_FILENAME_POLICY],
82 ));
84 }
85
91 {
92 $this->init($c);
94 $c[self::D_REPOSITORIES]->getFlavourRepository(),
95 $c[self::D_MACHINE_FACTORY],
96 $c[self::D_RESOURCE_BUILDER],
97 $c[self::D_STORAGE_HANDLERS],
98 $c[self::D_STREAM_ACCESS],
99 new Subject(),
100 ));
102 }
103
104 public function init(Container $c): void
105 {
106 if ($this->init) {
107 return;
108 }
109 $base_dir = $this->buildBasePath();
110
111 // DB Repositories
113 new RevisionDBRepository($c->database()),
114 new ResourceDBRepository($c->database()),
115 new CollectionDBRepository($c->database()),
116 new InformationDBRepository($c->database()),
117 new StakeholderDBRepository($c->database()),
118 new FlavourDBRepository($c->database()),
119 ));
120
121 // Repository Preloader
123 $c->database(),
124 $c[self::D_REPOSITORIES]
125 ));
126
127 // Lock Handler
128 $c[self::D_LOCK_HANDLER] = (static fn(Container $c): LockHandler => new LockHandlerilDB($c->database()));
129
130 // Storage Handlers
132 new MaxNestingFileSystemStorageHandler($c['filesystem.storage'], Location::STORAGE),
133 new FileSystemStorageHandler($c['filesystem.storage'], Location::STORAGE)
134 ], $base_dir));
135
136 // Source Builder for Consumers
138 $c->fileDelivery()
139 ));
140
141 // Filename Policy for Consumers
143 if ($c->isDependencyAvailable('settings') && $c->isDependencyAvailable('clientIni')) {
144 return new ilFileServicesPolicy($c->fileServiceSettings());
145 }
146 return new NoneFileNamePolicy();
147 };
148
149 // Artifacts
150 $c[self::D_ARTIFACTS] = static function (Container $c): Artifacts {
151 $flavour_data = is_readable(ilResourceStorageFlavourArtifact::PATH()) ?
153 : [];
154 return new Artifacts(
155 $flavour_data['machines'] ?? [],
156 $flavour_data['definitions'] ?? []
157 );
158 };
159
160 // Stream Access for Consumers and internal Usage
162 $base_dir,
163 $c[self::D_STORAGE_HANDLERS]
164 ));
165
166 // Flavours
167 $c[self::D_MACHINE_FACTORY] = (static fn(Container $c): Factory => new Factory(
168 new \ILIAS\ResourceStorage\Flavour\Engine\Factory(),
169 $c[self::D_ARTIFACTS]->getFlavourMachines()
170 ));
171
172 //
173 // IRSS
174 //
175 $c[self::D_SERVICE] = (static fn(Container $c): Services => new Services(
176 $c[self::D_STORAGE_HANDLERS],
177 $c[self::D_REPOSITORIES],
178 $c[self::D_ARTIFACTS],
179 $c[self::D_LOCK_HANDLER],
180 $c[self::D_FILENAME_POLICY],
181 $c[self::D_STREAM_ACCESS],
182 $c[self::D_MACHINE_FACTORY],
183 $c[self::D_SOURCE_BUILDER],
184 $c[self::D_REPOSITORY_PRELOADER],
185 static fn(): \ilLogger => $c->logger()->irss(),
186 ));
187
188 $c[self::D_MIGRATOR] = function (Container $c) use ($base_dir): Migrator {
189 $rb = $this->getResourceBuilder($c);
190 return new Migrator(
191 $c[self::D_STORAGE_HANDLERS],
192 static fn(StorableResource $r): bool => $rb->remove($r),
193 $c->database(),
194 $base_dir
195 );
196 };
197
198 $this->init = true;
199 }
200
201 protected function buildBasePath(): string
202 {
203 return (defined('ILIAS_DATA_DIR') && defined('CLIENT_ID'))
204 ? rtrim((string) ILIAS_DATA_DIR, "/") . "/" . CLIENT_ID
205 : '-';
206 }
207}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:38
Responsible for loading the Resource Storage into the dependency injection container of ILIAS.
getResourceBuilder(Container $c)
getFlavourBuilder(Container $c)
Component logger with individual log levels by component id.
const CLIENT_ID
Definition: constants.php:41
const ILIAS_DATA_DIR
Definition: constants.php:44
Interface Location.
Definition: Location.php:33
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.