ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
CallableObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Setup\Objective;
22 
23 use ILIAS\Setup;
24 
32 {
36  protected $callable;
37 
38  protected string $label;
39 
40  protected bool $is_notable;
41 
45  protected array $preconditions;
46 
47  public function __construct(callable $callable, string $label, bool $is_notable, Setup\Objective ...$preconditions)
48  {
49  $this->callable = $callable;
50  $this->label = $label;
51  $this->is_notable = $is_notable;
52  $this->preconditions = $preconditions;
53  }
54 
55  public function getHash(): string
56  {
57  return hash(
58  "sha256",
59  spl_object_hash($this)
60  );
61  }
62 
63  public function getLabel(): string
64  {
65  return $this->label;
66  }
67 
68  public function isNotable(): bool
69  {
70  return $this->is_notable;
71  }
72 
73  public function getPreconditions(Setup\Environment $environment): array
74  {
75  return $this->preconditions;
76  }
77 
78  public function achieve(Setup\Environment $environment): Setup\Environment
79  {
80  $res = call_user_func($this->callable, $environment);
81  if ($res instanceof Setup\Environment) {
82  return $res;
83  }
84  return $environment;
85  }
86 
87  public function isApplicable(Setup\Environment $environment): bool
88  {
89  return true;
90  }
91 }
$res
Definition: ltiservices.php:69
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
__construct(callable $callable, string $label, bool $is_notable, Setup\Objective ... $preconditions)
getPreconditions(Setup\Environment $environment)
getHash()
Get a hash for this objective.
getLabel()
Get a label that describes this objective.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isNotable()
Get to know if this is an interesting objective for a human.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
achieve(Setup\Environment $environment)
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
isApplicable(Setup\Environment $environment)
A callable objective wraps a callable into an objective.