ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilResourceStorageFlavourArtifact.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
28 
34 {
35  public const PATH = './Services/ResourceStorage/artifacts/flavour_data.php';
36 
37  public function getArtifactPath(): string
38  {
39  return self::PATH;
40  }
41 
42  public function build(): Artifact
43  {
44  $machines = (new DefaultMachines())->get();
45 
46  $finder = new ImplementationOfInterfaceFinder();
47 
48  foreach ($finder->getMatchingClassNames(FlavourMachine::class) as $machine_name) {
50  $machine = new $machine_name();
51  $machine_id = $machine->getId();
52 
53  if ($machine_name === $machine_id) {
54  throw new LogicException(
55  "PLEASE beware that class-related magic constants are not recommended. Altering the implementation-name may result in lost flavours."
56  );
57  }
58 
59  if (64 < strlen($machine_id)) {
60  throw new LogicException("ID of machine '$machine_name' exceeds 64 characters.");
61  }
62 
63  if (isset($machines[$machine_id]) && $machines[$machine_id] !== $machine_name) {
64  throw new LogicException(
65  "Machine '$default_machine_ids[$machine_id]' and '$machine_name' implement the same ID ($machine_id)."
66  );
67  }
68 
69  $machines[$machine_id] = $machine_name;
70  }
71 
72  $definitions = (new DefaultDefinitions())->get();
73 
74  foreach ($finder->getMatchingClassNames(FlavourDefinition::class) as $definition_name) {
77  // create instance without calling constructor using reflection class
78  try {
79  $reflection = new ReflectionClass($definition_name);
80  $definition = $reflection->newInstanceWithoutConstructor();
81  $definition_id = $definition->getId();
82  } catch (ReflectionException $e) {
83  continue;
84  }
85 
86 
87  if ($definition_name === $definition_id) {
88  throw new LogicException(
89  "PLEASE beware that class-related magic constants are not recommended. Altering the implementation-name may result in lost flavours."
90  );
91  }
92 
93  if (64 < strlen($definition_id)) {
94  throw new LogicException("ID of definition '$definition_name' exceeds 64 characters.");
95  }
96 
97  if (isset($definitions[$definition_id]) && $definitions[$definition_id] !== $definition_name) {
98  throw new LogicException(
99  "Definition '$definitions[$definition_id]' and '$definition_name' implement the same ID ($definition_id)."
100  );
101  }
102 
103  $definitions[$definition_id] = $definition_name;
104  }
105 
106  return new ArrayArtifact([
107  'machines' => $machines,
108  'definitions' => $definitions
109  ]);
110  }
111 }
build()
Build the artifact based.
This is an objective to build some artifact.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An array as an artifact.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27