ILIAS  release_8 Revision v8.24
BuildArtifactObjective.php
Go to the documentation of this file.
1<?php
2
3 declare(strict_types=1);
4
21namespace ILIAS\Setup\Artifact;
22
23use ILIAS\Setup;
24
28abstract class BuildArtifactObjective implements Setup\Objective
29{
35 abstract public function getArtifactPath(): string;
36
41 abstract public function build(): Setup\Artifact;
42
51 public function buildIn(Setup\Environment $env): Setup\Artifact
52 {
53 return $this->build();
54 }
55
61 public function getPreconditions(Setup\Environment $environment): array
62 {
63 return [];
64 }
65
71 public function getHash(): string
72 {
73 return hash("sha256", $this->getArtifactPath());
74 }
75
81 public function getLabel(): string
82 {
83 return 'Build ' . $this->getArtifactPath();
84 }
85
91 public function isNotable(): bool
92 {
93 return true;
94 }
95
101 public function achieve(Setup\Environment $environment): Setup\Environment
102 {
103 $artifact = $this->buildIn($environment);
104
105 // TODO: Do we want to configure this?
106 $base_path = getcwd();
107 $path = $base_path . "/" . $this->getArtifactPath();
108
109 $this->makeDirectoryFor($path);
110
111 file_put_contents($path, $artifact->serialize());
112
113 return $environment;
114 }
115
116 public function isApplicable(Setup\Environment $environment): bool
117 {
118 return true;
119 }
120
121 protected function makeDirectoryFor(string $path): void
122 {
123 $dir = pathinfo($path)["dirname"];
124 if (!file_exists($dir)) {
125 mkdir($dir, 0755, true);
126 }
127 }
128}
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.
getArtifactPath()
Get the filename where the builder wants to put its artifact.
getPreconditions(Setup\Environment $environment)
Defaults to no preconditions.
getLabel()
Defaults to "Build $this->getArtifactPath()".
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:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...