1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jaeger |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2016, mithra62 |
6
|
|
|
* @link http://jaeger-app.com |
7
|
|
|
* @version 1.0 |
8
|
|
|
* @filesource ./Errors.php |
9
|
|
|
*/ |
10
|
|
|
namespace JaegerApp; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Jaeger - Error Object |
14
|
|
|
* |
15
|
|
|
* Checks the base system to ensure everything's in place for use |
16
|
|
|
* |
17
|
|
|
* @package Errors |
18
|
|
|
* @author Eric Lamb <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class Errors |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The system settings |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $settings = array(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Contains an array of the errors found |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $errors = array(); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The Validation object |
39
|
|
|
* |
40
|
|
|
* @var \JaegerApp\Validate |
41
|
|
|
*/ |
42
|
|
|
protected $validation = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the total number of errors |
46
|
|
|
* |
47
|
|
|
* @return int |
48
|
|
|
*/ |
49
|
|
|
public function totalErrors() |
50
|
|
|
{ |
51
|
|
|
return count($this->getErrors()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns just a single error |
56
|
|
|
* |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public function getError() |
60
|
|
|
{ |
61
|
|
|
$errors = $this->getErrors(); |
62
|
|
|
return array_pop($errors); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns all the errors found |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
public function getErrors() |
71
|
|
|
{ |
72
|
|
|
return $this->errors; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets the settings to check |
77
|
|
|
* |
78
|
|
|
* @param array $settings |
79
|
|
|
* @return \JaegerApp\Errors |
80
|
|
|
*/ |
81
|
|
|
public function setSettings(array $settings) |
82
|
|
|
{ |
83
|
|
|
$this->settings = $settings; |
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the set settings array |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function getSettings() |
93
|
|
|
{ |
94
|
|
|
return $this->settings; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Clears out any errors that were added |
99
|
|
|
* |
100
|
|
|
* @return \JaegerApp\Errors |
101
|
|
|
*/ |
102
|
|
|
public function clearErrors() |
103
|
|
|
{ |
104
|
|
|
$this->errors = array(); |
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Sets the Validation object |
110
|
|
|
* |
111
|
|
|
* @param \JaegerApp\Validate $val |
112
|
|
|
* @return \JaegerApp\Errors |
113
|
|
|
*/ |
114
|
|
|
public function setValidation(\JaegerApp\Validate $val) |
115
|
|
|
{ |
116
|
|
|
$this->validation = $val; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns an instance of the validation object |
122
|
|
|
* |
123
|
|
|
* @return \JaegerApp\Validate |
124
|
|
|
*/ |
125
|
|
|
public function getValidation() |
126
|
|
|
{ |
127
|
|
|
return $this->validation; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Sets an error |
132
|
|
|
* |
133
|
|
|
* @param string $name |
134
|
|
|
* The key the error will be placed at in the error array |
135
|
|
|
* @param string $error |
136
|
|
|
* The error message language key |
137
|
|
|
*/ |
138
|
|
|
public function setError($name, $error) |
139
|
|
|
{ |
140
|
|
|
$this->errors[$name] = $error; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Verifies the license key is valid |
145
|
|
|
* |
146
|
|
|
* @param string $license_key |
147
|
|
|
* @param \JaegerApp\License $license |
148
|
|
|
* @return \JaegerApp\Errors |
149
|
|
|
*/ |
150
|
|
|
public function licenseCheck($license_key, \JaegerApp\License $license) |
151
|
|
|
{ |
152
|
|
|
if ($license_key == '') { |
153
|
|
|
$this->setError('license_number', 'missing_license_number'); |
154
|
|
|
} else { |
155
|
|
|
if (! $license->validLicense($license_key)) { |
156
|
|
|
$this->setError('license_number', 'invalid_license_number'); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
} |