ILIAS  release_7 Revision v7.30-3-g800a261c036
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
7
9
13abstract class BuildArtifactObjective implements Setup\Objective
14{
20 abstract public function getArtifactPath() : string;
21
26 abstract public function build() : Setup\Artifact;
27
36 public function buildIn(Setup\Environment $env) : Setup\Artifact
37 {
38 return $this->build();
39 }
40
46 public function getPreconditions(Setup\Environment $environment) : array
47 {
48 return [];
49 }
50
56 public function getHash() : string
57 {
58 return hash("sha256", $this->getArtifactPath());
59 }
60
66 public function getLabel() : string
67 {
68 return 'Build ' . $this->getArtifactPath();
69 }
70
76 public function isNotable() : bool
77 {
78 return true;
79 }
80
86 public function achieve(Setup\Environment $environment) : Setup\Environment
87 {
88 $artifact = $this->buildIn($environment);
89
90 // TODO: Do we want to configure this?
91 $base_path = getcwd();
92 $path = $base_path . "/" . $this->getArtifactPath();
93
94 $this->makeDirectoryFor($path);
95
96 file_put_contents($path, $artifact->serialize());
97
98 return $environment;
99 }
100
101 public function isApplicable(Setup\Environment $environment) : bool
102 {
103 return true;
104 }
105
106 protected function makeDirectoryFor(string $path) : void
107 {
108 $dir = pathinfo($path)["dirname"];
109 if (!file_exists($dir)) {
110 mkdir($dir, 0755, true);
111 }
112 }
113}
An exception for terminatinating execution or to throw for unit testing.
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: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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...