ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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 (?string $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

string $base_dir
 

Detailed Description

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

Definition at line 34 of file ConfigReader.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 38 of file ConfigReader.php.

39 {
40 $this->base_dir = $base_dir ?? getcwd();
41 }

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

Member Function Documentation

◆ applyOverwrites()

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

Definition at line 75 of file ConfigReader.php.

75 : array
76 {
77 $replacer = null;
78 $replacer = function ($subject, $path, $value) use (&$replacer) {
79 if (count($path) === 0) {
80 return $value;
81 }
82 $cur = array_shift($path);
83 $subject[$cur] = $replacer($subject[$cur] ?? [], $path, $value);
84 return $subject;
85 };
86
87 foreach ($overwrites as $path => $value) {
88 $path = explode(".", (string) $path);
89 $json = $replacer($json, $path, $value);
90 }
91
92 return $json;
93 }
$path
Definition: ltiservices.php:30

References $path.

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

+ Here is the caller graph for this function:

◆ getRealFilename()

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

Definition at line 95 of file ConfigReader.php.

95 : string
96 {
97 if (in_array($name[0], ["/", "\\"])) {
98 return $name;
99 }
100 return $this->base_dir . "/" . $name;
101 }

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

+ 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 52 of file ConfigReader.php.

52 : array
53 {
54 $name = $this->getRealFilename($name);
55 if (!is_readable($name)) {
56 throw new \InvalidArgumentException(
57 "Config-file '$name' does not exist or is not readable."
58 );
59 }
60 $json = json_decode(
61 file_get_contents($name),
62 true,
63 512,
64 JSON_THROW_ON_ERROR
65 );
66
67 if (!is_array($json)) {
68 throw new \InvalidArgumentException(
69 "Could not find JSON-array in '$name'."
70 );
71 }
72 return $this->applyOverwrites($json, $overwrites);
73 }
applyOverwrites(array $json, array $overwrites)

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

+ Here is the call graph for this function:

Field Documentation

◆ $base_dir

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

Definition at line 36 of file ConfigReader.php.

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


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