ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ExternalConditionObjective.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
7use ILIAS\UI;
8
17{
21 protected $label;
22
26 protected $condition;
27
31 protected $message;
32
36 public function __construct(string $label, callable $condition, string $message = null)
37 {
38 $this->condition = $condition;
39 $this->label = $label;
40 $this->message = $message;
41 }
42
46 public function getHash() : string
47 {
48 return hash(
49 "sha256",
50 get_class($this) . "::" . $this->label
51 );
52 }
53
57 public function getLabel() : string
58 {
59 return $this->label;
60 }
61
65 public function isNotable() : bool
66 {
67 return true;
68 }
69
73 public function getPreconditions(Environment $environment) : array
74 {
75 return [];
76 }
77
81 public function achieve(Environment $environment) : Environment
82 {
83 if (($this->condition)($environment)) {
84 return $environment;
85 }
86
87 if ($this->message) {
88 $admin_interaction = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
89 $admin_interaction->inform($this->message);
90 }
91
92 throw new UnachievableException(
93 "An external condition was not met: {$this->label}"
94 );
95 }
96}
An exception for terminatinating execution or to throw for unit testing.
A condition that can't be met by ILIAS itself needs to be met by some external means.
achieve(Environment $environment)
Objectives can be achieved.They might add resources to the environment when they have been achieved....
getLabel()
Get a label that describes this objective.
getPreconditions(Environment $environment)
Objectives might depend on other objectives.Objective[]
__construct(string $label, callable $condition, string $message=null)
isNotable()
Get to know if this is an interesting objective for a human.
getHash()
Get a hash for this objective.The hash of two objectives must be the same, if they are the same objec...
Signals that some goal won't be achievable by actions of the system ever.
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15