ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 (JsonParser $json_parser, ?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

JsonParser $json_parser
 
string $base_dir
 

Detailed Description

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

Definition at line 35 of file ConfigReader.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 40 of file ConfigReader.php.

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

41  {
42  $this->json_parser = $json_parser;
43  $this->base_dir = $base_dir ?? getcwd();
44  }

Member Function Documentation

◆ applyOverwrites()

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

Definition at line 76 of file ConfigReader.php.

References $path, and null.

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

76  : array
77  {
78  $replacer = null;
79  $replacer = function ($subject, $path, $value) use (&$replacer) {
80  if (count($path) === 0) {
81  return $value;
82  }
83  $cur = array_shift($path);
84  $subject[$cur] = $replacer($subject[$cur] ?? [], $path, $value);
85  return $subject;
86  };
87 
88  foreach ($overwrites as $path => $value) {
89  $path = explode(".", (string) $path);
90  $json = $replacer($json, $path, $value);
91  }
92 
93  return $json;
94  }
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ getRealFilename()

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

Definition at line 96 of file ConfigReader.php.

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

96  : string
97  {
98  if (in_array($name[0], ["/", "\\"])) {
99  return $name;
100  }
101  return $this->base_dir . "/" . $name;
102  }
+ 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 55 of file ConfigReader.php.

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

55  : array
56  {
57  $name = $this->getRealFilename($name);
58  if (!is_readable($name)) {
59  throw new \InvalidArgumentException(
60  "Config-file '$name' does not exist or is not readable."
61  );
62  }
63  $json = $this->json_parser->parse(
64  file_get_contents($name),
65  JsonParser::PARSE_TO_ASSOC | JsonParser::DETECT_KEY_CONFLICTS
66  );
67 
68  if (!is_array($json)) {
69  throw new \InvalidArgumentException(
70  "Could not find JSON-array in '$name'."
71  );
72  }
73  return $this->applyOverwrites($json, $overwrites);
74  }
applyOverwrites(array $json, array $overwrites)
+ Here is the call graph for this function:

Field Documentation

◆ $base_dir

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

Definition at line 38 of file ConfigReader.php.

◆ $json_parser

JsonParser ILIAS\Setup\CLI\ConfigReader::$json_parser
protected

Definition at line 37 of file ConfigReader.php.

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


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