ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DirectoryCreatedObjective.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
12{
14
18 protected $path;
19
23 protected $permissions;
24
25 public function __construct(
26 string $path,
27 int $permissions = self::DEFAULT_DIRECTORY_PERMISSIONS
28 ) {
29 if ($path == "") {
30 throw new \InvalidArgumentException(
31 "Path is empty."
32 );
33 }
34 $this->path = $path;
35 $this->permissions = $permissions;
36 }
37
43 public function getHash() : string
44 {
45 return hash("sha256", self::class . "::" . $this->path);
46 }
47
51 public function getLabel() : string
52 {
53 return "Create directory '{$this->path}'";
54 }
55
61 public function isNotable() : bool
62 {
63 return true;
64 }
65
69 public function getPreconditions(Environment $environment) : array
70 {
71 if (file_exists($this->path)) {
72 return [];
73 }
74 return [
75 new CanCreateDirectoriesInDirectoryCondition(dirname($this->path))
76 ];
77 }
78
82 public function achieve(Environment $environment) : Environment
83 {
84 if (!file_exists($this->path)) {
85 mkdir($this->path, $this->permissions);
86 }
87 if (!is_dir($this->path)) {
88 throw new UnachievableException(
89 "Could not create directory '{$this->path}'"
90 );
91 }
92 return $environment;
93 }
94}
An exception for terminatinating execution or to throw for unit testing.
achieve(Environment $environment)
@inheritdocs
__construct(string $path, int $permissions=self::DEFAULT_DIRECTORY_PERMISSIONS)
getPreconditions(Environment $environment)
@inheritdocs
Signals that some goal won't be achievable by actions of the system ever.
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