ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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. <string, Objective>

Definition at line 30 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 91 of file ObjectiveIterator.php.

References ILIAS\Setup\ObjectiveIterator\$current, and null.

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

92  {
93  if ($this->current === null) {
94  throw new \LogicException(
95  "Iterator is finished or wasn't initialized correctly internally."
96  );
97  }
98  return $this->current;
99  }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ detectDependencyCycles()

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

Definition at line 177 of file ObjectiveIterator.php.

References Vendor\Package\$d.

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

177  : void
178  {
179  if (!isset($this->reverse_dependencies[$next])) {
180  return;
181  }
182  if (in_array($cur, $this->reverse_dependencies[$next])) {
183  throw new UnachievableException(
184  "The objectives contain a dependency cycle and won't all be achievable."
185  );
186  }
187  foreach ($this->reverse_dependencies[$next] as $d) {
188  $this->detectDependencyCycles($cur, $d);
189  }
190  }
detectDependencyCycles(string $cur, string $next)
+ Here is the caller graph for this function:

◆ key()

ILIAS\Setup\ObjectiveIterator::key ( )

Definition at line 101 of file ObjectiveIterator.php.

References ILIAS\Setup\ObjectiveIterator\current().

101  : string
102  {
103  return $this->current()->getHash();
104  }
+ Here is the call graph for this function:

◆ markAsFailed()

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

Definition at line 70 of file ObjectiveIterator.php.

References ILIAS\Setup\Objective\getHash().

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

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

◆ next()

ILIAS\Setup\ObjectiveIterator::next ( )

Definition at line 106 of file ObjectiveIterator.php.

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

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

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

◆ rewind()

ILIAS\Setup\ObjectiveIterator::rewind ( )

Definition at line 81 of file ObjectiveIterator.php.

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

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

81  : void
82  {
83  $this->stack = [$this->objective];
84  $this->current = null;
85  $this->returned = [];
86  $this->failed = [];
87  $this->reverse_dependencies = [];
88  $this->next();
89  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 65 of file ObjectiveIterator.php.

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

65  : void
66  {
67  $this->environment = $environment;
68  }
+ Here is the call graph for this function:

◆ setReverseDependency()

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

Definition at line 192 of file ObjectiveIterator.php.

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

192  : void
193  {
194  if (!isset($this->reverse_dependencies[$other])) {
195  $this->reverse_dependencies[$other] = [];
196  }
197  $this->reverse_dependencies[$other][] = $cur;
198  }
+ Here is the caller graph for this function:

◆ valid()

ILIAS\Setup\ObjectiveIterator::valid ( )

Definition at line 172 of file ObjectiveIterator.php.

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

172  : bool
173  {
174  return $this->current !== null;
175  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

Field Documentation

◆ $current

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

Definition at line 40 of file ObjectiveIterator.php.

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

◆ $environment

Environment ILIAS\Setup\ObjectiveIterator::$environment
protected

◆ $failed

array ILIAS\Setup\ObjectiveIterator::$failed
protected

Definition at line 50 of file ObjectiveIterator.php.

◆ $objective

Objective ILIAS\Setup\ObjectiveIterator::$objective
protected

◆ $returned

array ILIAS\Setup\ObjectiveIterator::$returned
protected

Definition at line 45 of file ObjectiveIterator.php.

◆ $reverse_dependencies

array ILIAS\Setup\ObjectiveIterator::$reverse_dependencies
protected

Definition at line 55 of file ObjectiveIterator.php.

◆ $stack

array ILIAS\Setup\ObjectiveIterator::$stack
protected

Definition at line 38 of file ObjectiveIterator.php.


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