ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ArrayArtifact.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\Setup;
8 
12 class ArrayArtifact implements Setup\Artifact
13 {
17  private $data = [];
18 
22  public function __construct(array $data)
23  {
24  $this->check($data);
25  $this->data = $data;
26  }
27 
28 
29  final public function serialize() : string
30  {
31  return "<?" . "php return " . var_export($this->data, true) . ";";
32  }
33 
34  private function check(array $a)
35  {
36  foreach ($a as $item) {
37  if (is_string($item) || is_int($item) || is_float($item) || is_bool($item) || is_null($item)) {
38  continue;
39  }
40  if (is_array($item)) {
41  $this->check($item);
42  continue;
43  }
44  throw new \InvalidArgumentException(
45  "Array data for artifact may only contain ints, strings, floats, bools or " .
46  "other arrays with this content. Found: " . gettype($item)
47  );
48  }
49  }
50 }
serialize()
This method will be called from the source, which wants to save the artifact.
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:11
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples