ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InitResourceStorage.php
Go to the documentation of this file.
1<?php
2
46
51{
52 public const D_SERVICE = 'resource_storage';
53 public const D_REPOSITORIES = self::D_SERVICE . '.repositories';
54 public const D_STORAGE_HANDLERS = self::D_SERVICE . '.storage_handlers';
55 public const D_RESOURCE_BUILDER = self::D_SERVICE . '.resource_builder';
56 public const D_FLAVOUR_BUILDER = self::D_SERVICE . '.flavour_builder';
57 public const D_REPOSITORY_PRELOADER = self::D_SERVICE . '.repository_preloader';
58 public const D_SOURCE_BUILDER = self::D_SERVICE . '.source_builder';
59 public const D_LOCK_HANDLER = self::D_SERVICE . '.lock_handler';
60 public const D_FILENAME_POLICY = self::D_SERVICE . '.filename_policy';
61 public const D_STREAM_ACCESS = self::D_SERVICE . '.stream_access';
62 public const D_ARTIFACTS = self::D_SERVICE . '.artifacts';
63 public const D_MACHINE_FACTORY = self::D_SERVICE . '.machine_factory';
64 public const D_MIGRATOR = self::D_SERVICE . '.migrator';
65
66 private bool $init = false;
67
73 {
74 $this->init($c);
76 return new ResourceBuilder(
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 );
83 };
85 }
86
92 {
93 $this->init($c);
95 return new FlavourBuilder(
96 $c[self::D_REPOSITORIES]->getFlavourRepository(),
97 $c[self::D_MACHINE_FACTORY],
98 $c[self::D_RESOURCE_BUILDER],
99 $c[self::D_STORAGE_HANDLERS],
100 $c[self::D_STREAM_ACCESS],
101 new Subject(),
102 );
103 };
105 }
106
107 public function init(\ILIAS\DI\Container $c): void
108 {
109 if ($this->init) {
110 return;
111 }
112 $base_dir = $this->buildBasePath();
113
114 // DB Repositories
115 $c[self::D_REPOSITORIES] = static function (Container $c): Repositories {
116 return new Repositories(
117 new RevisionDBRepository($c->database()),
118 new ResourceDBRepository($c->database()),
119 new CollectionDBRepository($c->database()),
120 new InformationDBRepository($c->database()),
121 new StakeholderDBRepository($c->database()),
122 new FlavourDBRepository($c->database()),
123 );
124 };
125
126 // Repository Preloader
127 $c[self::D_REPOSITORY_PRELOADER] = static function (Container $c) {
128 return new DBRepositoryPreloader(
129 $c->database(),
130 $c[self::D_REPOSITORIES]
131 );
132 };
133
134 // Lock Handler
135 $c[self::D_LOCK_HANDLER] = static function (Container $c): LockHandler {
136 return new LockHandlerilDB($c->database());
137 };
138
139 // Storage Handlers
140 $c[self::D_STORAGE_HANDLERS] = static function (Container $c) use (
141 $base_dir
143 return new StorageHandlerFactory([
144 new MaxNestingFileSystemStorageHandler($c['filesystem.storage'], Location::STORAGE),
145 new FileSystemStorageHandler($c['filesystem.storage'], Location::STORAGE)
146 ], $base_dir);
147 };
148
149 // Source Builder for Consumers
150 $c[self::D_SOURCE_BUILDER] = static function (Container $c): ?SrcBuilder {
151 return new ilSecureTokenSrcBuilder(
152 $c->fileDelivery()
153 );
154 };
155
156 // Filename Policy for Consumers
158 if ($c->isDependencyAvailable('settings') && $c->isDependencyAvailable('clientIni')) {
159 return new ilFileServicesPolicy($c->fileServiceSettings());
160 }
161 return new NoneFileNamePolicy();
162 };
163
164 // Artifacts
165 $c[self::D_ARTIFACTS] = static function (Container $c): Artifacts {
166 $flavour_data = is_readable(ilResourceStorageFlavourArtifact::PATH()) ?
168 : [];
169 return new Artifacts(
170 $flavour_data['machines'] ?? [],
171 $flavour_data['definitions'] ?? []
172 );
173 };
174
175 // Stream Access for Consumers and internal Usage
176 $c[self::D_STREAM_ACCESS] = static function (Container $c) use ($base_dir): StreamAccess {
177 return new StreamAccess(
178 $base_dir,
179 $c[self::D_STORAGE_HANDLERS]
180 );
181 };
182
183 // Flavours
184 $c[self::D_MACHINE_FACTORY] = static function (Container $c): Factory {
185 return new Factory(
186 new \ILIAS\ResourceStorage\Flavour\Engine\Factory(),
187 $c[self::D_ARTIFACTS]->getFlavourMachines()
188 );
189 };
190
191 //
192 // IRSS
193 //
194 $c[self::D_SERVICE] = static function (Container $c): \ILIAS\ResourceStorage\Services {
195 $services = new \ILIAS\ResourceStorage\Services(
196 $c[self::D_STORAGE_HANDLERS],
197 $c[self::D_REPOSITORIES],
198 $c[self::D_ARTIFACTS],
199 $c[self::D_LOCK_HANDLER],
200 $c[self::D_FILENAME_POLICY],
201 $c[self::D_STREAM_ACCESS],
202 $c[self::D_MACHINE_FACTORY],
203 $c[self::D_SOURCE_BUILDER],
204 $c[self::D_REPOSITORY_PRELOADER],
205 );
206
207 // attach general observers
208 $services->events()->attach(new IRSSEventLogObserver($c->logger()->irss()), Event::ALL);
209
210 return $services;
211 };
212
213 $c[self::D_MIGRATOR] = function (Container $c) use ($base_dir): Migrator {
214 return new Migrator(
215 $c[self::D_STORAGE_HANDLERS],
216 $this->getResourceBuilder($c),
217 $c->database(),
218 $base_dir
219 );
220 };
221
222 $this->init = true;
223 }
224
225 protected function buildBasePath(): string
226 {
227 return (defined('ILIAS_DATA_DIR') && defined('CLIENT_ID'))
228 ? rtrim(ILIAS_DATA_DIR, "/") . "/" . CLIENT_ID
229 : '-';
230 }
231}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Responsible for loading the Resource Storage into the dependency injection container of ILIAS.
getFlavourBuilder(\ILIAS\DI\Container $c)
getResourceBuilder(\ILIAS\DI\Container $c)
init(\ILIAS\DI\Container $c)
Class ilFileServicesPolicy.
const CLIENT_ID
Definition: constants.php:41
const ILIAS_DATA_DIR
Definition: constants.php:44
$c
Definition: deliver.php:25
@ ALL
event string being used if
Interface Location.
Definition: Location.php:33
Class HTTPServicesTest.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.