ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
BuildArtifactObjective.php
Go to the documentation of this file.
1<?php
2
3
4/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de>, Fabian Schmid <fs@studer-raimann.ch> Extended GPL, see docs/LICENSE */
5
6namespace ILIAS\Setup;
7
11abstract class BuildArtifactObjective implements Objective
12{
18 abstract public function getArtifactPath() : string;
19
24 abstract public function build() : Artifact;
25
34 public function buildIn(Environment $env) : Artifact
35 {
36 return $this->build();
37 }
38
44 public function getPreconditions(Environment $environment) : array
45 {
46 return [];
47 }
48
54 public function getHash() : string
55 {
56 return hash("sha256", $this->getArtifactPath());
57 }
58
64 public function getLabel() : string
65 {
66 return 'Build ' . $this->getArtifactPath();
67 }
68
74 public function isNotable() : bool
75 {
76 return true;
77 }
78
84 public function achieve(Environment $environment) : Environment
85 {
86 $artifact = $this->buildIn($environment);
87
88 // TODO: Do we want to configure this?
89 $base_path = getcwd();
90 $path = $base_path . "/" . $this->getArtifactPath();
91
92 $this->makeDirectoryFor($path);
93
94 file_put_contents($path, $artifact->serialize());
95
96 return $environment;
97 }
98
99 protected function makeDirectoryFor(string $path) : void
100 {
101 $dir = pathinfo($path)["dirname"];
102 if (!file_exists($dir)) {
103 mkdir($dir, 0755, true);
104 }
105 }
106}
An exception for terminatinating execution or to throw for unit testing.
This is an objective to build some artifact.
getPreconditions(Environment $environment)
Defaults to no preconditions.
achieve(Environment $environment)
Builds the artifact and puts it in its location.
getLabel()
Defaults to "Build $this->getArtifactPath()".
buildIn(Environment $env)
Builds an artifact in some given Environment.
getArtifactPath()
Get the filename where the builder wants to put its artifact.
build()
Build the artifact based.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:12
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15