ILIAS  release_8 Revision v8.24
ILIAS\Setup\ObjectiveIterator Class Reference

Tries to enumerate all preconditions for the given objective, where the ones that can be achieved (i.e. More...

+ Inheritance diagram for ILIAS\Setup\ObjectiveIterator:
+ Collaboration diagram for ILIAS\Setup\ObjectiveIterator:

Public Member Functions

 __construct (Environment $environment, Objective $objective)
 
 setEnvironment (Environment $environment)
 
 markAsFailed (Objective $objective)
 
 rewind ()
 
 current ()
 
 key ()
 
 next ()
 
 valid ()
 

Protected Member Functions

 detectDependencyCycles (string $cur, string $next)
 
 setReverseDependency (string $other, string $cur)
 

Protected Attributes

Environment $environment
 
Objective $objective
 
array $stack
 
Objective $current = null
 
array $returned
 
array $failed
 
array $reverse_dependencies
 

Detailed Description

Tries to enumerate all preconditions for the given objective, where the ones that can be achieved (i.e.

have no further preconditions on their own) will be returned first. Will also attempt to only return every objective once. This thus expects, that returned objectives will be achieved somehow.

Definition at line 29 of file ObjectiveIterator.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\ObjectiveIterator::__construct ( Environment  $environment,
Objective  $objective 
)

Member Function Documentation

◆ current()

ILIAS\Setup\ObjectiveIterator::current ( )

Definition at line 90 of file ObjectiveIterator.php.

91 {
92 if ($this->current === null) {
93 throw new \LogicException(
94 "Iterator is finished or wasn't initialized correctly internally."
95 );
96 }
97 return $this->current;
98 }
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31

References ILIAS\Setup\ObjectiveIterator\$current, and ILIAS\Setup\ObjectiveIterator\current().

Referenced by ILIAS\Setup\ObjectiveIterator\current(), ILIAS\Setup\ObjectiveIterator\key(), ILIAS\Setup\ObjectiveIterator\next(), ILIAS\Setup\ObjectiveIterator\rewind(), and ILIAS\Setup\ObjectiveIterator\valid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ detectDependencyCycles()

ILIAS\Setup\ObjectiveIterator::detectDependencyCycles ( string  $cur,
string  $next 
)
protected

Definition at line 176 of file ObjectiveIterator.php.

176 : void
177 {
178 if (!isset($this->reverse_dependencies[$next])) {
179 return;
180 }
181 if (in_array($cur, $this->reverse_dependencies[$next])) {
182 throw new UnachievableException(
183 "The objectives contain a dependency cycle and won't all be achievable."
184 );
185 }
186 foreach ($this->reverse_dependencies[$next] as $d) {
187 $this->detectDependencyCycles($cur, $d);
188 }
189 }
detectDependencyCycles(string $cur, string $next)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $d, and ILIAS\Setup\ObjectiveIterator\detectDependencyCycles().

Referenced by ILIAS\Setup\ObjectiveIterator\detectDependencyCycles(), and ILIAS\Setup\ObjectiveIterator\next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ key()

ILIAS\Setup\ObjectiveIterator::key ( )

Definition at line 100 of file ObjectiveIterator.php.

101 {
102 return $this->current()->getHash();
103 }

References ILIAS\Setup\ObjectiveIterator\current().

+ Here is the call graph for this function:

◆ markAsFailed()

ILIAS\Setup\ObjectiveIterator::markAsFailed ( Objective  $objective)

Definition at line 69 of file ObjectiveIterator.php.

69 : void
70 {
71 if (!isset($this->returned[$objective->getHash()])) {
72 throw new \LogicException(
73 "You may only mark objectives as failed that have been returned by this iterator."
74 );
75 }
76
77 $this->failed[$objective->getHash()] = true;
78 }
getHash()
Get a hash for this objective.

References ILIAS\Setup\ObjectiveIterator\$objective, and ILIAS\Setup\Objective\getHash().

Referenced by ILIAS\Setup\ObjectiveIterator\next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ next()

ILIAS\Setup\ObjectiveIterator::next ( )

Definition at line 105 of file ObjectiveIterator.php.

105 : void
106 {
107 if ($this->stack === []) {
108 $this->current = null;
109 return;
110 }
111
112 $cur = array_pop($this->stack);
113 $hash = $cur->getHash();
114
115 if (isset($this->returned[$hash]) || isset($this->failed[$hash])) {
116 $this->next();
117 return;
118 }
119
120 $preconditions = [];
121 $failed_preconditions = [];
122 foreach ($cur->getPreconditions($this->environment) as $p) {
123 $h = $p->getHash();
124 if (!isset($this->returned[$h]) || isset($this->failed[$h])) {
125 $preconditions[] = $p;
126 }
127
128 if (isset($this->failed[$h])) {
129 $failed_preconditions[] = $p;
130 }
131 }
132
133 // We only have preconditions left that we know to have failed.
134 if (
135 $preconditions !== [] &&
136 count($preconditions) === count($failed_preconditions)
137 ) {
138 $this->returned[$hash] = true;
139 $this->markAsFailed($cur);
140 if ($this->stack === []) {
141 // Since the current objective doesn't need to be achieved,
142 // we are fine and can simply stop here.
143 if ($cur instanceof Objective\Tentatively) {
144 return;
145 }
146 throw new UnachievableException(
147 "Objective '" . $cur->getLabel() . "' had failed preconditions:\n - " .
148 implode("\n - ", array_map(fn ($o) => $o->getLabel(), $failed_preconditions))
149 );
150 }
151 $this->next();
152 return;
153 }
154
155 // No preconditions open, we can proceed with the objective.
156 if ($preconditions === []) {
157 $this->returned[$hash] = true;
158 $this->current = $cur;
159 return;
160 }
161
162 $this->stack[] = $cur;
163 $this->detectDependencyCycles($hash, $hash);
164 foreach (array_reverse($preconditions) as $p) {
165 $this->stack[] = $p;
166 $this->setReverseDependency($p->getHash(), $hash);
167 }
168 $this->next();
169 }
markAsFailed(Objective $objective)
setReverseDependency(string $other, string $cur)

References ILIAS\Setup\ObjectiveIterator\current(), ILIAS\Setup\ObjectiveIterator\detectDependencyCycles(), ILIAS\Setup\ObjectiveIterator\markAsFailed(), ILIAS\Setup\ObjectiveIterator\next(), and ILIAS\Setup\ObjectiveIterator\setReverseDependency().

Referenced by ILIAS\Setup\ObjectiveIterator\next(), and ILIAS\Setup\ObjectiveIterator\rewind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rewind()

ILIAS\Setup\ObjectiveIterator::rewind ( )

Definition at line 80 of file ObjectiveIterator.php.

80 : void
81 {
82 $this->stack = [$this->objective];
83 $this->current = null;
84 $this->returned = [];
85 $this->failed = [];
86 $this->reverse_dependencies = [];
87 $this->next();
88 }

References ILIAS\Setup\ObjectiveIterator\$objective, ILIAS\Setup\ObjectiveIterator\current(), and ILIAS\Setup\ObjectiveIterator\next().

Referenced by ILIAS\Setup\ObjectiveIterator\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setEnvironment()

ILIAS\Setup\ObjectiveIterator::setEnvironment ( Environment  $environment)

Definition at line 64 of file ObjectiveIterator.php.

64 : void
65 {
67 }

References ILIAS\Setup\ObjectiveIterator\$environment, and ILIAS\UI\examples\Table\Presentation\environment().

+ Here is the call graph for this function:

◆ setReverseDependency()

ILIAS\Setup\ObjectiveIterator::setReverseDependency ( string  $other,
string  $cur 
)
protected

Definition at line 191 of file ObjectiveIterator.php.

191 : void
192 {
193 if (!isset($this->reverse_dependencies[$other])) {
194 $this->reverse_dependencies[$other] = [];
195 }
196 $this->reverse_dependencies[$other][] = $cur;
197 }

Referenced by ILIAS\Setup\ObjectiveIterator\next().

+ Here is the caller graph for this function:

◆ valid()

ILIAS\Setup\ObjectiveIterator::valid ( )

Definition at line 171 of file ObjectiveIterator.php.

171 : bool
172 {
173 return $this->current !== null;
174 }

References ILIAS\Setup\ObjectiveIterator\current().

+ Here is the call graph for this function:

Field Documentation

◆ $current

Objective ILIAS\Setup\ObjectiveIterator::$current = null
protected

Definition at line 39 of file ObjectiveIterator.php.

Referenced by ILIAS\Setup\ObjectiveIterator\current().

◆ $environment

◆ $failed

array ILIAS\Setup\ObjectiveIterator::$failed
protected

Definition at line 49 of file ObjectiveIterator.php.

◆ $objective

Objective ILIAS\Setup\ObjectiveIterator::$objective
protected

◆ $returned

array ILIAS\Setup\ObjectiveIterator::$returned
protected

Definition at line 44 of file ObjectiveIterator.php.

◆ $reverse_dependencies

array ILIAS\Setup\ObjectiveIterator::$reverse_dependencies
protected

Definition at line 54 of file ObjectiveIterator.php.

◆ $stack

array ILIAS\Setup\ObjectiveIterator::$stack
protected

Definition at line 37 of file ObjectiveIterator.php.


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