ILIAS  release_7 Revision v7.30-3-g800a261c036
ArrayEnvironment.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5namespace ILIAS\Setup;
6
8
10{
14 protected $resources;
15
19 protected $configs;
20
21 public function __construct(array $resources)
22 {
23 $this->resources = $resources;
24 }
25
29 public function getResource(string $id)
30 {
31 if (!isset($this->resources[$id])) {
32 return null;
33 }
34 return $this->resources[$id];
35 }
36
40 public function withResource(string $id, $resource) : Environment
41 {
42 if (isset($this->resources[$id])) {
43 throw new \RuntimeException(
44 "Resource '$id' is already contained in the environment"
45 );
46 }
47 $clone = clone $this;
48 $clone->resources[$id] = $resource;
49 return $clone;
50 }
51
55 public function withConfigFor(string $component, $config) : Environment
56 {
57 if (isset($this->configs[$component])) {
58 throw new \RuntimeException(
59 "Config for '$component' is already contained in the environment"
60 );
61 }
62 $clone = clone $this;
63 $clone->configs[$component] = $config;
64 return $clone;
65 }
66
70 public function getConfigFor(string $component)
71 {
72 if (!isset($this->configs[$component])) {
73 throw new \RuntimeException(
74 "Config for '$component' is not contained in the environment"
75 );
76 }
77 return $this->configs[$component];
78 }
79
83 public function hasConfigFor(string $component) : bool
84 {
85 return isset($this->configs[$component]);
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
withResource(string $id, $resource)
RuntimeException if this resource is already in the environment.
withConfigFor(string $component, $config)
Stores a config for some component in the environment.RuntimeException if this config is already in t...
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.implements some known in...
hasConfigFor(string $component)
getConfigFor(string $component)
RuntimeException if there is no config for the component mixed
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
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...