ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\Setup\CLI\ConfigReader Class Reference

Read a json-formatted config from a file and overwrite some fields. More...

+ Collaboration diagram for ILIAS\Setup\CLI\ConfigReader:

Public Member Functions

 __construct ($base_dir=null)
 
 readConfigFile (string $name, array $overwrites=[])
 TODO: We could use the "give me a transformation and I'll give you your result" pattern from the input paper here. More...
 

Protected Member Functions

 applyOverwrites (array $json, array $overwrites)
 
 getRealFilename (string $name)
 

Protected Attributes

 $base_dir
 

Detailed Description

Read a json-formatted config from a file and overwrite some fields.

Definition at line 17 of file ConfigReader.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\CLI\ConfigReader::__construct (   $base_dir = null)

Definition at line 24 of file ConfigReader.php.

References ILIAS\Setup\CLI\ConfigReader\$base_dir.

25  {
26  $this->base_dir = $base_dir ?? getcwd();
27  }

Member Function Documentation

◆ applyOverwrites()

ILIAS\Setup\CLI\ConfigReader::applyOverwrites ( array  $json,
array  $overwrites 
)
protected

Definition at line 55 of file ConfigReader.php.

Referenced by ILIAS\Setup\CLI\ConfigReader\readConfigFile().

55  : array
56  {
57  $replacer = null;
58  $replacer = function ($subject, $path, $value) use (&$replacer) {
59  if (count($path) === 0) {
60  return $value;
61  }
62  $cur = array_shift($path);
63  $subject[$cur] = $replacer($subject[$cur], $path, $value);
64  return $subject;
65  };
66 
67  foreach ($overwrites as $path => $value) {
68  $path = explode(".", $path);
69  $json = $replacer($json, $path, $value);
70  }
71 
72  return $json;
73  }
+ Here is the caller graph for this function:

◆ getRealFilename()

ILIAS\Setup\CLI\ConfigReader::getRealFilename ( string  $name)
protected

Definition at line 75 of file ConfigReader.php.

References $name.

Referenced by ILIAS\Setup\CLI\ConfigReader\readConfigFile().

75  : string
76  {
77  if (in_array($name[0], ["/", "\\"])) {
78  return $name;
79  }
80  return $this->base_dir . "/" . $name;
81  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the caller graph for this function:

◆ readConfigFile()

ILIAS\Setup\CLI\ConfigReader::readConfigFile ( string  $name,
array  $overwrites = [] 
)

TODO: We could use the "give me a transformation and I'll give you your result" pattern from the input paper here.

Parameters
array$overwritesis a list of fields that should be overwritten with with the contained variables. The keys define which field (e.g. "a.b.c") should be overwritten with which value.

Definition at line 38 of file ConfigReader.php.

References ILIAS\Setup\CLI\ConfigReader\applyOverwrites(), and ILIAS\Setup\CLI\ConfigReader\getRealFilename().

38  : array
39  {
40  $name = $this->getRealFilename($name);
41  if (!file_exists($name) || !is_readable($name)) {
42  throw new \InvalidArgumentException(
43  "Config-file '$name' does not exist or is not readable."
44  );
45  }
46  $json = json_decode(file_get_contents($name), JSON_OBJECT_AS_ARRAY);
47  if (!is_array($json)) {
48  throw new \InvalidArgumentException(
49  "Could not find JSON-array in '$name'."
50  );
51  }
52  return $this->applyOverwrites($json, $overwrites);
53  }
applyOverwrites(array $json, array $overwrites)
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

Field Documentation

◆ $base_dir

ILIAS\Setup\CLI\ConfigReader::$base_dir
protected

Definition at line 22 of file ConfigReader.php.

Referenced by ILIAS\Setup\CLI\ConfigReader\__construct().


The documentation for this class was generated from the following file: