ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables 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
 
 $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 17 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 88 of file ObjectiveIterator.php.

References ILIAS\Setup\ObjectiveIterator\$current.

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

89  {
90  if ($this->current === null) {
91  throw new \LogicException(
92  "Iterator is finished or wasn't initialized correctly internally."
93  );
94  }
95  return $this->current;
96  }
+ Here is the caller graph for this function:

◆ detectDependencyCycles()

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

Definition at line 162 of file ObjectiveIterator.php.

References $d.

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

163  {
164  if (!isset($this->reverse_dependencies[$next])) {
165  return;
166  }
167  if (in_array($cur, $this->reverse_dependencies[$next])) {
168  throw new UnachievableException(
169  "The objectives contain a dependency cycle and won't all be achievable."
170  );
171  }
172  foreach ($this->reverse_dependencies[$next] as $d) {
173  $this->detectDependencyCycles($cur, $d);
174  }
175  }
detectDependencyCycles(string $cur, string $next)
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the caller graph for this function:

◆ key()

ILIAS\Setup\ObjectiveIterator::key ( )

Definition at line 98 of file ObjectiveIterator.php.

References ILIAS\Setup\ObjectiveIterator\current().

99  {
100  return $this->current()->getHash();
101  }
+ Here is the call graph for this function:

◆ markAsFailed()

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

Definition at line 67 of file ObjectiveIterator.php.

References ILIAS\Setup\Objective\getHash().

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

◆ next()

ILIAS\Setup\ObjectiveIterator::next ( )

Definition at line 103 of file ObjectiveIterator.php.

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

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

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

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

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

79  {
80  $this->stack = [$this->objective];
81  $this->current = null;
82  $this->returned = [];
83  $this->failed = [];
84  $this->reverse_dependencies = [];
85  $this->next();
86  }
+ 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 62 of file ObjectiveIterator.php.

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

62  : void
63  {
64  $this->environment = $environment;
65  }
environment()
Definition: environment.php:3
+ Here is the call graph for this function:

◆ setReverseDependency()

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

Definition at line 177 of file ObjectiveIterator.php.

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

178  {
179  if (!isset($this->reverse_dependencies[$other])) {
180  $this->reverse_dependencies[$other] = [];
181  }
182  $this->reverse_dependencies[$other][] = $cur;
183  }
+ Here is the caller graph for this function:

◆ valid()

ILIAS\Setup\ObjectiveIterator::valid ( )

Definition at line 157 of file ObjectiveIterator.php.

References ILIAS\Setup\ObjectiveIterator\current().

158  {
159  return $this->current !== null;
160  }
+ Here is the call graph for this function:

Field Documentation

◆ $current

ILIAS\Setup\ObjectiveIterator::$current
protected

Definition at line 37 of file ObjectiveIterator.php.

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

◆ $environment

ILIAS\Setup\ObjectiveIterator::$environment
protected

◆ $failed

ILIAS\Setup\ObjectiveIterator::$failed
protected

Definition at line 47 of file ObjectiveIterator.php.

◆ $objective

ILIAS\Setup\ObjectiveIterator::$objective
protected

◆ $returned

ILIAS\Setup\ObjectiveIterator::$returned
protected

Definition at line 42 of file ObjectiveIterator.php.

◆ $reverse_dependencies

ILIAS\Setup\ObjectiveIterator::$reverse_dependencies
protected

Definition at line 52 of file ObjectiveIterator.php.

◆ $stack

ILIAS\Setup\ObjectiveIterator::$stack
protected

Definition at line 32 of file ObjectiveIterator.php.


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