ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4namespace ILIAS\Setup\CLI;
5
10use Symfony\Component\Console\Input\InputInterface;
11
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}
An exception for terminatinating execution or to throw for unit testing.
An agent that is just a collection of some other agents.
Read a json-formatted config from a file and overwrite some fields.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
A agent is some component that performs part of the setup process.
Definition: Agent.php:14
hasConfig()
Does this agent require a configuration?
getArrayToConfigTransformation()
Agents must be able to tell how to create a configuration from a nested array.
A configuration for the setup.
Definition: Config.php:11
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
withConfigFor(string $component, $config)
Stores a config for some component in the environment.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAgentConfigsToEnvironment(Agent $agent, Config $config, Environment $environment)
readAgentConfig(Agent $agent, InputInterface $input)
trait HasConfigReader
Add this to an Command that has an config reader.