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