19 declare(strict_types=1);
53 private readonly
Factory $flavour_machine_factory,
57 private readonly
Subject $events
66 return $this->flavour_resource_repository->has(
79 bool $force_building = false
82 if (!$this->resource_builder->has($rid)) {
85 if ($this->
has($rid, $definition)) {
86 return $this->
read($rid, $definition, $force_building);
89 return $this->
build($rid, $definition);
96 $flavour = $this->
new($definition, $rid);
97 $flavour = $this->
runMachine($rid, $definition, $flavour);
100 $this->flavour_resource_repository->store($flavour);
110 bool $force_building =
false 112 $current_revision = $this->
getResource($rid)->getCurrentRevision();
113 $flavour = $this->flavour_resource_repository->get(
115 $current_revision->getVersionNumber(),
122 $storage->deleteFlavour($current_revision, $flavour);
124 return $this->
runMachine($rid, $definition, $flavour);
139 public function delete(
143 $current_revision = $this->
getResource($rid)->getCurrentRevision();
144 $revision_number = $current_revision->getVersionNumber();
146 if ($this->flavour_resource_repository->has($rid, $revision_number, $definition)) {
147 $flavour = $this->flavour_resource_repository->get($rid, $revision_number, $definition);
148 $this->flavour_resource_repository->delete($flavour);
150 $storage->deleteFlavour($current_revision, $flavour);
171 $storable->setStreams($streams);
188 ) as $index => $file_stream
190 $flavour = $this->stream_access->populateFlavour($flavour, $file_stream, $index);
199 throw new \InvalidArgumentException(
"FlavourDefinition not supported by machine");
208 if (strlen($definition->
getVariantName()) > self::VARIANT_NAME_MAX_LENGTH) {
209 throw new \InvalidArgumentException(
"FlavourDefinition variant name too long");
219 $machine = $this->flavour_machine_factory->get($definition);
227 $engine = $machine->getEngine();
228 if (!$engine->isRunning()) {
231 $current_revision = $this->
getResource($rid)->getCurrentRevision();
232 $suffix = $current_revision->getInformation()->getSuffix();
233 $size = $current_revision->getInformation()->getSize();
234 if ($size > $engine->getSizeLimitInBytes()) {
238 return $engine->supports($suffix);
252 $stream = $this->resource_builder->extractStream($revision);
261 $machine = $this->flavour_machine_factory->get($definition);
265 $storable_streams = [];
268 $machine->processStream(
269 $revision->getInformation(),
274 $generated_stream = $result->getStream();
275 if ($result->isStoreable()) {
277 $storable_streams[$result->getIndex()] = $generated_stream;
282 $flavour = $this->stream_access->populateFlavour(
299 $this->events->notify(Event::FLAVOUR_BUILD_SUCCESS,
new FlavourData($rid, $definition, $flavour));
309 if (isset($this->current_revision_cache[$rid])) {
313 return $this->current_revision_cache[$rid] = $this->
getResourceOfFlavour($flavour)->getCurrentRevision();
319 return $this->resources_cache[$rid_string] ?? ($this->resources_cache[$rid_string] = $this->resource_builder->get(
326 return $this->
getResource($flavour->getResourceID());
331 return $this->storage_handler_factory->getHandlerForResource($this->
getResourceOfFlavour($flavour));
getStorageHandler(Flavour $flavour)
checkDefinition(FlavourDefinition $definition)
build(ResourceIdentification $rid, FlavourDefinition $definition)
Class FileResourceHandler.
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
getResourceOfFlavour(Flavour $flavour)
Interface StorageResource.
storeFlavourStreams(Flavour $flavour, array $streams)
read(ResourceIdentification $rid, FlavourDefinition $definition, bool $force_building=false)
persist()
Define whether the generated flavor and the respective streams should be persisted, or whether they should only be generated and used in-memory.
getVariantName()
If a definition can be used in several variants (e.g.
getResource(ResourceIdentification $rid)
checkDefinitionForMachine(FlavourDefinition $definition, FlavourMachine $machine)
has(ResourceIdentification $identification, FlavourDefinition $definition)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const VARIANT_NAME_MAX_LENGTH
hasFlavourStreams(Flavour $flavour)
array $current_revision_cache
Class ResourceIdentification.
getCurrentRevision(Flavour $flavour)
event string being used if a new Resource has been stored to the IRSS.
static ofString(string $string)
Creates a new stream with an initial value.
Class ResourceNotFoundException.
runMachine(ResourceIdentification $rid, FlavourDefinition $definition, Flavour $flavour)
Class StorageHandlerFactory.
testDefinition(ResourceIdentification $rid, FlavourDefinition $definition)
populateFlavourWithExistingStreams(Flavour $flavour)
__construct(private readonly FlavourRepository $flavour_resource_repository, private readonly Factory $flavour_machine_factory, private readonly ResourceBuilder $resource_builder, private readonly StorageHandlerFactory $storage_handler_factory, private readonly StreamAccess $stream_access, private readonly Subject $events)