ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BuildArtifactObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\Artifact;
22
23use ILIAS\Setup;
24
33abstract class BuildArtifactObjective implements Setup\Objective
34{
35 protected const ARTIFACTS = __DIR__ . "/../../../../../artifacts";
36
40 final public static function PATH(): string
41 {
42 return realpath(self::ARTIFACTS) . "/" . md5(static::class) . ".php";
43 }
44
45 private const COMPONENTS_DIRECTORY = "components";
46
52 abstract public function getArtifactName(): string;
53
58 abstract public function build(): Setup\Artifact;
59
68 public function buildIn(Setup\Environment $env): Setup\Artifact
69 {
70 return $this->build();
71 }
72
78 public function getPreconditions(Setup\Environment $environment): array
79 {
80 return [];
81 }
82
88 public function getHash(): string
89 {
90 return hash("sha256", $this->getArtifactName());
91 }
92
98 public function getLabel(): string
99 {
100 return 'Build ' . $this->getArtifactName() . ' Artifact';
101 }
102
108 public function isNotable(): bool
109 {
110 return true;
111 }
112
113 protected function getPath(): string
114 {
115 return static::PATH();
116 }
117
123 public function achieve(Setup\Environment $environment): Setup\Environment
124 {
125 $artifact = $this->buildIn($environment);
126
127 $path = $this->getPath();
128
129 $this->makeDirectoryFor($path);
130
131 file_put_contents($path, $artifact->serialize());
132
133 return $environment;
134 }
135
136 public function isApplicable(Setup\Environment $environment): bool
137 {
138 return true;
139 }
140
141 protected function makeDirectoryFor(string $path): void
142 {
143 $dir = pathinfo($path)["dirname"];
144 if (!file_exists($dir)) {
145 if (!mkdir($dir, 0755, true) && !is_dir($dir)) {
146 throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
147 }
148 }
149 }
150}
This is an objective to build some artifact.
achieve(Setup\Environment $environment)
Builds the artifact and puts it in its location.
buildIn(Setup\Environment $env)
Builds an artifact in some given Environment.
getPreconditions(Setup\Environment $environment)
Defaults to no preconditions.
getArtifactName()
Get the filename where the builder wants to put its artifact.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...