ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ArrayArtifact.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
23 use ILIAS\Setup;
24 
28 class ArrayArtifact implements Setup\Artifact
29 {
30  private array $data = [];
31 
35  public function __construct(array $data)
36  {
37  $this->check($data);
38  $this->data = $data;
39  }
40 
41 
42  final public function serialize(): string
43  {
44  return "<?" . "php return " . var_export($this->data, true) . ";";
45  }
46 
47  private function check(array $a): void
48  {
49  foreach ($a as $item) {
50  if (is_string($item) || is_int($item) || is_float($item) || is_bool($item) || is_null($item)) {
51  continue;
52  }
53  if (is_array($item)) {
54  $this->check($item);
55  continue;
56  }
57  throw new \InvalidArgumentException(
58  "Array data for artifact may only contain ints, strings, floats, bools or " .
59  "other arrays with this content. Found: " . gettype($item)
60  );
61  }
62  }
63 }
serialize()
This method will be called from the source, which wants to save the artifact.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An array as an artifact.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples