ILIAS  release_7 Revision v7.30-3-g800a261c036
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
 
 $objective
 
 $stack
 
 $current
 
 $returned
 
 $failed
 
 $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 13 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 84 of file ObjectiveIterator.php.

85 {
86 if ($this->current === null) {
87 throw new \LogicException(
88 "Iterator is finished or wasn't initialized correctly internally."
89 );
90 }
91 return $this->current;
92 }

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 167 of file ObjectiveIterator.php.

168 {
169 if (!isset($this->reverse_dependencies[$next])) {
170 return;
171 }
172 if (in_array($cur, $this->reverse_dependencies[$next])) {
173 throw new UnachievableException(
174 "The objectives contain a dependency cycle and won't all be achievable."
175 );
176 }
177 foreach ($this->reverse_dependencies[$next] as $d) {
178 $this->detectDependencyCycles($cur, $d);
179 }
180 }
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 94 of file ObjectiveIterator.php.

95 {
96 return $this->current()->getHash();
97 }

References ILIAS\Setup\ObjectiveIterator\current().

+ Here is the call graph for this function:

◆ markAsFailed()

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

Definition at line 63 of file ObjectiveIterator.php.

64 {
65 if (!isset($this->returned[$objective->getHash()])) {
66 throw new \LogicException(
67 "You may only mark objectives as failed that have been returned by this iterator."
68 );
69 }
70
71 $this->failed[$objective->getHash()] = true;
72 }

References ILIAS\Setup\ObjectiveIterator\$objective.

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

+ Here is the caller graph for this function:

◆ next()

ILIAS\Setup\ObjectiveIterator::next ( )

Definition at line 99 of file ObjectiveIterator.php.

100 {
101 if (count($this->stack) === 0) {
102 $this->current = null;
103 return;
104 }
105
106 $cur = array_pop($this->stack);
107 $hash = $cur->getHash();
108
109 if (isset($this->returned[$hash]) || isset($this->failed[$hash])) {
110 $this->next();
111 return;
112 }
113
114 $preconditions = [];
115 $failed_preconditions = [];
116 foreach ($cur->getPreconditions($this->environment) as $p) {
117 $h = $p->getHash();
118 if (!isset($this->returned[$h]) || isset($this->failed[$h])) {
119 $preconditions[] = $p;
120 }
121
122 if (isset($this->failed[$h])) {
123 $failed_preconditions[] = $p;
124 }
125 }
126
127 // We only have preconditions left that we know to have failed.
128 if (
129 count($preconditions) !== 0 &&
130 count($preconditions) === count($failed_preconditions)
131 ) {
132 $this->returned[$hash] = true;
133 $this->markAsFailed($cur);
134 if (count($this->stack) === 0) {
135 throw new UnachievableException(
136 "Objective '" . $cur->getLabel() . "' had failed preconditions:\n - " .
137 implode("\n - ", array_map(function ($o) {
138 return $o->getLabel();
139 }, $failed_preconditions))
140 );
141 }
142 $this->next();
143 return;
144 }
145
146 // No preconditions open, we can proceed with the objective.
147 if (count($preconditions) === 0) {
148 $this->returned[$hash] = true;
149 $this->current = $cur;
150 return;
151 }
152
153 $this->stack[] = $cur;
154 $this->detectDependencyCycles($hash, $hash);
155 foreach (array_reverse($preconditions) as $p) {
156 $this->stack[] = $p;
157 $this->setReverseDependency($p->getHash(), $hash);
158 }
159 $this->next();
160 }
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 74 of file ObjectiveIterator.php.

75 {
76 $this->stack = [$this->objective];
77 $this->current = null;
78 $this->returned = [];
79 $this->failed = [];
80 $this->reverse_dependencies = [];
81 $this->next();
82 }

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 58 of file ObjectiveIterator.php.

58 : void
59 {
61 }

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

+ Here is the call graph for this function:

◆ setReverseDependency()

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

Definition at line 182 of file ObjectiveIterator.php.

183 {
184 if (!isset($this->reverse_dependencies[$other])) {
185 $this->reverse_dependencies[$other] = [];
186 }
187 $this->reverse_dependencies[$other][] = $cur;
188 }

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

+ Here is the caller graph for this function:

◆ valid()

ILIAS\Setup\ObjectiveIterator::valid ( )

Definition at line 162 of file ObjectiveIterator.php.

163 {
164 return $this->current !== null;
165 }

References ILIAS\Setup\ObjectiveIterator\current().

+ Here is the call graph for this function:

Field Documentation

◆ $current

ILIAS\Setup\ObjectiveIterator::$current
protected

Definition at line 33 of file ObjectiveIterator.php.

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

◆ $environment

◆ $failed

ILIAS\Setup\ObjectiveIterator::$failed
protected

Definition at line 43 of file ObjectiveIterator.php.

◆ $objective

ILIAS\Setup\ObjectiveIterator::$objective
protected

◆ $returned

ILIAS\Setup\ObjectiveIterator::$returned
protected

Definition at line 38 of file ObjectiveIterator.php.

◆ $reverse_dependencies

ILIAS\Setup\ObjectiveIterator::$reverse_dependencies
protected

Definition at line 48 of file ObjectiveIterator.php.

◆ $stack

ILIAS\Setup\ObjectiveIterator::$stack
protected

Definition at line 28 of file ObjectiveIterator.php.


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