-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRequirement.php
103 lines (90 loc) · 2.01 KB
/
Requirement.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace York;
/**
* Requirement checking class
*
* @package \York
* @version $version$
* @author wolxXx
*/
class Requirement
{
/**
* @var string[]
*/
protected $files = array(
'Application/Configuration/Host.php',
'Application/Configuration/Application.php',
'Application/Configuration/Bootstrap.php'
);
/**
* @var string[]
*/
protected $directories = array(
'log',
'tmp'
);
/**
* @var string[]
*/
protected $messages = array();
/***
* @return $this
*/
protected function checkFiles()
{
foreach ($this->files as $file) {
try {
new \York\FileSystem\File($file);
} catch (\Exception $exception) {
$this->messages[] = 'required file does not exist: ' . $file;
}
}
return $this;
}
/**
* @return $this
*/
protected function checkDirectories()
{
foreach ($this->directories as $directory) {
try {
new \York\FileSystem\Directory($directory);
} catch (\Exception $exception) {
$this->messages[] = 'required directory does not exist: ' . $directory;
}
}
return $this;
}
/**
* @return $this
*
* @throws \York\Exception\Requirement
*/
protected function checkMessages()
{
if (false === empty($this->messages)) {
$this->messages = array_merge(array('some files and / or directories are missing. please fix.'), $this->messages);
throw new \York\Exception\Requirement($this->messages);
}
return $this;
}
/**
* @return $this
*/
public static function Factory()
{
return new self();
}
/**
* @return $this
*/
public function check()
{
$this
->checkFiles()
->checkDirectories()
->checkMessages();
return $this;
}
}