-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectories.php
More file actions
88 lines (66 loc) · 2.46 KB
/
Directories.php
File metadata and controls
88 lines (66 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace Snicco\Component\Kernel\ValueObject;
use Webmozart\Assert\Assert;
use function sprintf;
use const DIRECTORY_SEPARATOR;
/**
* This class represents a simple value object that holds references to all
* relevant directories the app needs. All directories are validated to be
* readable and don't end with a trailing slash.
*
* @psalm-immutable
*/
final class Directories
{
private string $config_dir;
private string $cache_dir;
private string $log_dir;
private string $base_directory;
public function __construct(string $base_directory, string $config_dir, string $cache_dir, string $log_dir)
{
Assert::readable($base_directory, sprintf('$base_directory [%s] is not readable.', $base_directory));
Assert::readable($config_dir, sprintf('$config_dir [%s] is not readable.', $config_dir));
Assert::readable($cache_dir, sprintf('$cache_dir [%s] is not readable.', $cache_dir));
Assert::writable($cache_dir, sprintf('$cache_dir [%s] is not writable.', $cache_dir));
Assert::readable($log_dir, sprintf('$log_dir [%s] is not readable.', $log_dir));
Assert::writable($log_dir, sprintf('$log_dir [%s] is not writable.', $log_dir));
$this->config_dir = rtrim($config_dir, DIRECTORY_SEPARATOR);
$this->cache_dir = rtrim($cache_dir, DIRECTORY_SEPARATOR);
$this->log_dir = rtrim($log_dir, DIRECTORY_SEPARATOR);
$this->base_directory = rtrim($base_directory, DIRECTORY_SEPARATOR);
}
public static function fromDefaults(string $base_directory): Directories
{
$config_dir = rtrim($base_directory, DIRECTORY_SEPARATOR) .
DIRECTORY_SEPARATOR .
'config';
$cache_dir = rtrim($base_directory, DIRECTORY_SEPARATOR)
. DIRECTORY_SEPARATOR
. 'var'
. DIRECTORY_SEPARATOR
. 'cache';
$log_dir = rtrim($base_directory, DIRECTORY_SEPARATOR)
. DIRECTORY_SEPARATOR
. 'var'
. DIRECTORY_SEPARATOR
. 'log';
return new self($base_directory, $config_dir, $cache_dir, $log_dir);
}
public function configDir(): string
{
return $this->config_dir;
}
public function baseDir(): string
{
return $this->base_directory;
}
public function cacheDir(): string
{
return $this->cache_dir;
}
public function logDir(): string
{
return $this->log_dir;
}
}