ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ObjectiveHelper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\CLI;
22
27
31trait ObjectiveHelper
32{
33 protected function achieveObjective(
34 Objective $objective,
35 Environment $environment,
36 ?IOWrapper $io = null
37 ): Environment {
38 $iterator = new ObjectiveIterator($environment, $objective);
39 $current = null;
40
41 register_shutdown_function(static function () use (&$current) {
42 if (null !== $current) {
43 throw new \RuntimeException("Objective '{$current->getLabel()}' failed because it halted the program.");
44 }
45 });
46
47 while ($iterator->valid()) {
48 $current = $iterator->current();
49 if (!$current->isApplicable($environment)) {
50 // reset objective to mark it as processed without halting the program.
51 $current = null;
52 $iterator->next();
53 continue;
54 }
55 if ($io !== null) {
56 $io->startObjective($current->getLabel(), $current->isNotable());
57 }
58 try {
59 $environment = $current->achieve($environment);
60 if ($io !== null) {
61 $io->finishedLastObjective();
62 }
63 $iterator->setEnvironment($environment);
64 } catch (NotExecutableException $e) {
65 throw $e;
66 } catch (\Throwable $e) {
67 $iterator->markAsFailed($current);
68 if ($io !== null) {
69 $message = $e->getMessage();
70 $io->failedLastObjective();
71 if ($io->isVerbose()) {
72 $message .= "\n\n" . $e->getTraceAsString();
73 }
74 $io->error($message);
75 }
76 } finally {
77 // reset objective to mark it as processed without halting the program.
78 $current = null;
79 }
80 $iterator->next();
81 }
82
83 return $environment;
84 }
85}
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:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:31