-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
65 lines (56 loc) · 1.58 KB
/
index.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
<?php
namespace PMVC\App\error;
use PMVC\MappingBuilder;
use PMVC\Action;
$b = new MappingBuilder();
${_INIT_CONFIG}[_CLASS] = __NAMESPACE__.'\ErrorAction';
${_INIT_CONFIG}[_INIT_BUILDER] = $b;
$b->addAction('index');
$b->addForward('error', [
_PATH=>'error'
,_TYPE=>'view'
]);
class ErrorAction extends Action
{
static function index($m, $f){
$dotenv = \PMVC\plug('dotenv');
$defineds = $dotenv->getUnderscoreToArray(__DIR__.'/.env.errors');
$errors = [];
$hasLastError = false;
if (isset($f['errors'])) {
$errorIds = $f['errors'];
$lastError = $f['lastError'];
foreach ($errorIds as $id) {
if (!empty($defineds[$id])) {
if (isset($defineds[$id]['http']))
{
\PMVC\option('set', 'httpResponseCode', $defineds[$id]['http']);
}
$errorObject = new Error($id, $defineds[$id]);
$errors[] = $errorObject;
if ($lastError === $id) {
$hasLastError = $errorObject;
}
}
}
}
$go = $m['error'];
$go->set('data',[
'errors' => $errors,
'lastError'=> $hasLastError
]);
return $go;
}
}
class Error
{
public $message;
public $field;
public $id;
function __construct($id, $data)
{
$this->id = $id;
$this->message = \PMVC\get($data, 'message');
$this->field = \PMVC\get($data, 'field');
}
}