ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BuildStaticConfigStoredObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
31{
32 protected static function saveName(string $name): string
33 {
34 return strtolower((string) preg_replace('/[^a-zA-Z0-9_]/', '_', $name));
35 }
36
37 final public static function PATH(): string
38 {
39 return realpath(__DIR__ . '/../../../../../public/data/')
40 . '/' . self::saveName((new static())->getArtifactName()) . ".php";
41 }
42
43 abstract public function getArtifactName(): string;
44
45 abstract public function build(): Artifact;
46
47 public function buildIn(Environment $env): Artifact
48 {
49 return $this->build();
50 }
51
52 public function getPreconditions(Environment $environment): array
53 {
54 return [];
55 }
56
57 public function getHash(): string
58 {
59 return hash("sha256", $this->getArtifactName());
60 }
61
62 public function getLabel(): string
63 {
64 return 'Build ' . $this->getArtifactName() . ' Ststic Config';
65 }
66
67 public function isNotable(): bool
68 {
69 return true;
70 }
71
72 final protected function getPath(): string
73 {
74 return static::PATH();
75 }
76
77 public function achieve(Environment $environment): Environment
78 {
79 $artifact = $this->buildIn($environment);
80
81 $path = $this->getPath();
82
83 $this->makeDirectoryFor($path);
84
85 file_put_contents($path, $artifact->serialize());
86
87 return $environment;
88 }
89
90 public function isApplicable(Environment $environment): bool
91 {
92 return true;
93 }
94
95 protected function makeDirectoryFor(string $path): void
96 {
97 $dir = pathinfo($path)["dirname"];
98 if (!file_exists($dir) && (!mkdir($dir, 0755, true) && !is_dir($dir))) {
99 throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
100 }
101 }
102}
isNotable()
Get to know if this is an interesting objective for a human.
isApplicable(Environment $environment)
Get to know whether the objective is applicable.
getPreconditions(Environment $environment)
Objectives might depend on other objectives.
achieve(Environment $environment)
Objectives can be achieved.
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