|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routeless Fail Responder |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (C) 2016 Jake Johns |
|
8
|
|
|
* |
|
9
|
|
|
* This software may be modified and distributed under the terms |
|
10
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
11
|
|
|
* |
|
12
|
|
|
* @category Config |
|
13
|
|
|
* @package Jnjxp\Routeless |
|
14
|
|
|
* @author Jake Johns <[email protected]> |
|
15
|
|
|
* @copyright 2016 Jake Johns |
|
16
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
17
|
|
|
* @link http://github.com/jnjxp/jnjxp.routeless |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Jnjxp\Routeless; |
|
21
|
|
|
|
|
22
|
|
|
use Aura\Di\Container; |
|
23
|
|
|
use Aura\Di\ContainerConfig; |
|
24
|
|
|
|
|
25
|
|
|
use Radar\Adr\Handler\RoutingHandler; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Config |
|
29
|
|
|
* |
|
30
|
|
|
* @category Config |
|
31
|
|
|
* @package Jnjxp\Routeless |
|
32
|
|
|
* @author Jake Johns <[email protected]> |
|
33
|
|
|
* @license http://jnj.mit-license.org/ MIT License |
|
34
|
|
|
* @link http://github.com/jnjxp/jnjxp.routeless |
|
35
|
|
|
*/ |
|
36
|
|
|
class Config extends ContainerConfig |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Rules |
|
40
|
|
|
* |
|
41
|
|
|
* @var array |
|
42
|
|
|
* |
|
43
|
|
|
* @access protected |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $rules = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* __construct |
|
49
|
|
|
* |
|
50
|
|
|
* @param array $rules Map of rules |
|
51
|
|
|
* |
|
52
|
|
|
* @access public |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function __construct(array $rules = null) |
|
55
|
|
|
{ |
|
56
|
3 |
|
if ($rules) { |
|
57
|
3 |
|
$this->setRules($rules); |
|
58
|
3 |
|
} |
|
59
|
3 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* SetRules |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $rules Map of rules |
|
65
|
|
|
* |
|
66
|
|
|
* @return mixed |
|
67
|
|
|
* |
|
68
|
|
|
* @access public |
|
69
|
|
|
*/ |
|
70
|
3 |
|
public function setRules(array $rules) |
|
71
|
|
|
{ |
|
72
|
3 |
|
$this->rules = $rules; |
|
73
|
3 |
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Define |
|
78
|
|
|
* |
|
79
|
|
|
* @param Container $di DI Container |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
* |
|
83
|
|
|
* @access public |
|
84
|
|
|
* |
|
85
|
|
|
* @SuppressWarnings(PHPMD.ShortVariable) |
|
86
|
|
|
*/ |
|
87
|
3 |
|
public function define(Container $di) |
|
88
|
|
|
{ |
|
89
|
3 |
|
$di->params[RoutingHandler::class] |
|
90
|
3 |
|
['failResponder'] = RoutingFailedResponder::class; |
|
91
|
|
|
|
|
92
|
3 |
|
foreach ($this->rules as $rule => $responder) { |
|
93
|
3 |
|
$di->params[RoutingFailedResponder::class] |
|
94
|
3 |
|
['factories'][$rule] = $di->lazyNew($responder); |
|
95
|
3 |
|
} |
|
96
|
3 |
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|