ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
HasConfigReader.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3 
4 namespace ILIAS\Setup\CLI;
5 
11 
15 trait HasConfigReader
16 {
20  protected $config_reader;
21 
22  protected function readAgentConfig(Agent $agent, InputInterface $input) : ?Config
23  {
24  if (!($this->config_reader instanceof ConfigReader)) {
25  throw new \LogicException("\$this->config_reader not properly initialized.");
26  }
27 
28  if (!$agent->hasConfig()) {
29  return null;
30  }
31 
32  $config_file = $input->getArgument("config");
33  $config_overwrites_raw = $input->getOption("config");
34  $config_overwrites = [];
35  foreach ($config_overwrites_raw as $o) {
36  $vs = explode("=", $o);
37  if (count($vs) !== 2) {
38  throw new \Exception("Cannot read config-option: '$o'");
39  }
40  $config_overwrites[$vs[0]] = $vs[1];
41  }
42 
43  $config_content = $this->config_reader->readConfigFile($config_file, $config_overwrites);
44 
45  $trafo = $agent->getArrayToConfigTransformation();
46  return $trafo->transform($config_content);
47  }
48 
49  protected function addAgentConfigsToEnvironment(
50  Agent $agent,
52  Environment $environment
53  ) : Environment {
54  if ($agent instanceof AgentCollection) {
55  foreach ($config->getKeys() as $k) {
56  $environment = $environment->withConfigFor($k, $config->getConfig($k));
57  }
58  }
59 
60  return $environment;
61  }
62 }
Read a json-formatted config from a file and overwrite some fields.
getArrayToConfigTransformation()
Agents must be able to tell how to create a configuration from a nested array.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
An agent that is just a collection of some other agents.
A agent is some component that performs part of the setup process.
Definition: Agent.php:13
readAgentConfig(Agent $agent, InputInterface $input)
hasConfig()
Does this agent require a configuration?
addAgentConfigsToEnvironment(Agent $agent, Config $config, Environment $environment)
withConfigFor(string $component, $config)
Stores a config for some component in the environment.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:11
A configuration for the setup.
Definition: Config.php:10