ILIAS  release_7 Revision v7.30-3-g800a261c036
ObjectiveHelper.php
Go to the documentation of this file.
1<?php
2
18namespace ILIAS\Setup\CLI;
19
24
28trait ObjectiveHelper
29{
30 protected function achieveObjective(
31 Objective $objective,
32 Environment $environment,
33 IOWrapper $io = null
34 ) : Environment {
35 $iterator = new ObjectiveIterator($environment, $objective);
36 $current = null;
37
38 register_shutdown_function(static function () use (&$current) {
39 if (null !== $current) {
40 throw new \RuntimeException("Objective '{$current->getLabel()}' failed because it halted the program.");
41 }
42 });
43
44 while ($iterator->valid()) {
45 $current = $iterator->current();
46 if (!$current->isApplicable($environment)) {
47 // reset objective to mark it as processed without halting the program.
48 $current = null;
49 $iterator->next();
50 continue;
51 }
52 if ($io) {
53 $io->startObjective($current->getLabel(), $current->isNotable());
54 }
55 try {
56 $environment = $current->achieve($environment);
57 if ($io) {
58 $io->finishedLastObjective();
59 }
60 $iterator->setEnvironment($environment);
61 } catch (NotExecutableException $e) {
62 throw $e;
63 } catch (\Throwable $e) {
64 $iterator->markAsFailed($current);
65 if ($io) {
66 $message = $e->getMessage();
67 $io->failedLastObjective();
68 if ($io->isVerbose()) {
69 $message .= "\n\n" . $e->getTraceAsString();
70 }
71 $io->error($message);
72 }
73 } finally {
74 // reset objective to mark it as processed without halting the program.
75 $current = null;
76 }
77 $iterator->next();
78 }
79
80 return $environment;
81 }
82}
An exception for terminatinating execution or to throw for unit testing.
Signals that the setup is not executable at all.
Tries to enumerate all preconditions for the given objective, where the ones that can be achieved (i....
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:14