1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Gerrie package. |
4
|
|
|
* |
5
|
|
|
* (c) Andreas Grunwald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Gerrie\Check; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Check if the config file exists. |
15
|
|
|
* |
16
|
|
|
* @author Andreas Grunwald <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class ConfigFileCheck implements CheckInterface |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Filename of config |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $filename = ''; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bool if the file is readable |
30
|
|
|
* |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
private $isReadable; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Bool if the file was found |
37
|
|
|
* |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $isFound; |
41
|
|
|
|
42
|
5 |
|
public function __construct($filename) |
43
|
|
|
{ |
44
|
5 |
|
$this->filename = $filename; |
45
|
5 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Executes the check itselfs |
49
|
|
|
* |
50
|
|
|
* @return boolean |
51
|
|
|
*/ |
52
|
3 |
|
public function check() |
53
|
|
|
{ |
54
|
3 |
|
$this->isFound = file_exists($this->filename); |
55
|
3 |
|
$this->isReadable = is_readable($this->filename); |
56
|
|
|
|
57
|
3 |
|
$result = $this->isFound && $this->isReadable; |
58
|
|
|
|
59
|
3 |
|
return $result; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the message, if the check succeeded |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
1 |
|
public function getSuccessMessage() |
68
|
|
|
{ |
69
|
1 |
|
$message = 'Config file "%s" was found and is readable.'; |
70
|
1 |
|
$message = sprintf($message, $this->filename); |
71
|
1 |
|
return $message; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns the message, if the check fails |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
1 |
|
public function getFailureMessage() |
80
|
|
|
{ |
81
|
1 |
|
$message = ''; |
82
|
1 |
|
if ($this->isFound === false && $this->isReadable === false) { |
83
|
|
|
$message = 'Configuration file'; |
84
|
|
|
if ($this->filename) { |
85
|
|
|
$message .= ' "%s"'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$message .= ' was not found. '; |
89
|
|
|
$message .= 'Please provide the correct path or all settings via command options.'; |
90
|
|
|
|
91
|
1 |
|
} elseif ($this->isFound === true && $this->isReadable === false) { |
92
|
|
|
$message = 'Configuration file "%s" was found, but is not readable. '; |
93
|
|
|
$message .= 'Please change ownerships or all settings via command options.'; |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
$message = sprintf($message, $this->filename); |
97
|
|
|
|
98
|
1 |
|
return $message; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns if this check is optional or required. |
103
|
|
|
* |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
1 |
|
public function isOptional() |
107
|
|
|
{ |
108
|
1 |
|
return true; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|