ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Factory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
31{
35 protected array $machines_string = [];
39 protected array $machines_instances = [];
40
41 public function __construct(
42 private \ILIAS\ResourceStorage\Flavour\Engine\Factory $engines,
43 array $machines_string = []
44 ) {
45 $default_machines = new DefaultMachines();
46 $this->machines_string = array_merge($default_machines->get(), $machines_string);
47 }
48
49 public function get(FlavourDefinition $definition): FlavourMachine
50 {
51 $null_machine = new NullMachine();
52 $definition_id = $definition->getFlavourMachineId();
53
54 $machine_string = $this->machines_string[$definition_id] ?? null;
55 if ($machine_string === null) {
56 return $null_machine->withReason('No machine found for definition ' . $definition->getId());
57 }
58 if (isset($this->machines_instances[$definition_id])) {
59 return $this->machines_instances[$definition_id];
60 }
61 try {
62 $machine = new $machine_string();
63 } catch (\Throwable) {
64 return $null_machine->withReason('Could not instantiate machine ' . $machine_string);
65 }
66
67 if (!$machine instanceof FlavourMachine) {
68 return $null_machine->withReason('Machine ' . $machine_string . ' does not implement FlavourMachine');
69 }
70
71 $engine = $this->engines->get($machine);
72
73 if (!$engine instanceof Engine || !$engine->isRunning()) {
74 return $null_machine->withReason(
75 'Machine ' . $machine_string . ' depends on engine ' .
76 $machine->dependsOnEngine()
77 . ' which is not running or available.'
78 );
79 }
80
81 $machine = $machine->withEngine($engine);
82
83 return $this->machines_instances[$definition_id] = $machine;
84 }
85}
__construct(private \ILIAS\ResourceStorage\Flavour\Engine\Factory $engines, array $machines_string=[])
Definition: Factory.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.