ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DirectoryCreatedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\Objective;
22
23use ILIAS\Setup;
24
29{
30 public const DEFAULT_DIRECTORY_PERMISSIONS = 0755;
31
32 protected string $path;
33 protected int $permissions;
34
35 public function __construct(
36 string $path,
37 int $permissions = self::DEFAULT_DIRECTORY_PERMISSIONS
38 ) {
39 if ($path == "") {
40 throw new \InvalidArgumentException(
41 "Path is empty."
42 );
43 }
44 $this->path = $path;
45 $this->permissions = $permissions;
46 }
47
53 public function getHash(): string
54 {
55 return hash("sha256", self::class . "::" . $this->path);
56 }
57
63 public function getLabel(): string
64 {
65 return "Create directory '$this->path'";
66 }
67
73 public function isNotable(): bool
74 {
75 return true;
76 }
77
81 public function getPreconditions(Setup\Environment $environment): array
82 {
83 if (file_exists($this->path)) {
84 return [];
85 }
86 return [
88 ];
89 }
90
94 public function achieve(Setup\Environment $environment): Setup\Environment
95 {
96 @mkdir($this->path, $this->permissions);
97
98 if (!is_dir($this->path)) {
100 "Could not create directory '$this->path'"
101 );
102 }
103 return $environment;
104 }
105
109 public function isApplicable(Setup\Environment $environment): bool
110 {
111 return !file_exists($this->path);
112 }
113}
getPreconditions(Setup\Environment $environment)
@inheritdocs
getLabel()
Defaults to "Build $this->getArtifactPath()".
isApplicable(Setup\Environment $environment)
@inheritDoc
achieve(Setup\Environment $environment)
@inheritdocs
__construct(string $path, int $permissions=self::DEFAULT_DIRECTORY_PERMISSIONS)
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:28
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...