1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zewa; |
4
|
|
|
|
5
|
|
|
use Sabre\Event\Emitter; |
6
|
|
|
use Sabre\Event\EventEmitter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Abstract class for controller extension |
10
|
|
|
* |
11
|
|
|
* @author Zechariah Walden<zech @ zewadesign.com> |
12
|
|
|
*/ |
13
|
|
|
abstract class Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* System configuration |
17
|
|
|
* |
18
|
|
|
* @var Config |
19
|
|
|
*/ |
20
|
|
|
protected $configuration; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Emitter |
24
|
|
|
*/ |
25
|
|
|
protected $event; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Instantiated router class pointer |
29
|
|
|
* |
30
|
|
|
* @var Router |
31
|
|
|
*/ |
32
|
|
|
protected $router; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Instantiated request class pointer |
36
|
|
|
* |
37
|
|
|
* @var Request |
38
|
|
|
*/ |
39
|
|
|
protected $request; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* League\Container |
43
|
|
|
* |
44
|
|
|
* @var DIContainer |
45
|
|
|
*/ |
46
|
|
|
protected $container; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Instantiated output class pointer |
50
|
|
|
* |
51
|
|
|
* @var object |
52
|
|
|
*/ |
53
|
|
|
protected $output; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var View |
57
|
|
|
*/ |
58
|
|
|
protected $view; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Load up some basic configuration settings. |
62
|
|
|
*/ |
63
|
|
|
public function __construct() |
64
|
|
|
{ |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getEvent() : Emitter |
68
|
|
|
{ |
69
|
|
|
return $this->event; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setEvent(Emitter $eventManager) |
73
|
|
|
{ |
74
|
|
|
$this->event = $eventManager; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setView(View $view) |
78
|
|
|
{ |
79
|
|
|
$this->view = $view; |
80
|
|
|
//@TODO instead of "getview" this needs to be "setResponse" -- set response should receive a view, |
81
|
|
|
//views probably don't need config, router, or request -- but they need access |
82
|
|
|
//to methods inside of there. |
83
|
|
|
// I'm not sure how I want to handle this yet. |
84
|
|
|
// return new View($this->configuration, $this->router, $this->request); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setConfig(Config $config) |
88
|
|
|
{ |
89
|
|
|
$this->configuration = $config; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getConfig() : Config |
93
|
|
|
{ |
94
|
|
|
return $this->configuration; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setRouter(Router $router) |
98
|
|
|
{ |
99
|
|
|
$this->router = $router; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getRouter() : Router |
103
|
|
|
{ |
104
|
|
|
return $this->router; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setRequest(Request $request) |
108
|
|
|
{ |
109
|
|
|
$this->request = $request; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getRequest() : Request |
113
|
|
|
{ |
114
|
|
|
return $this->request; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function setContainer(DIContainer $container) |
118
|
|
|
{ |
119
|
|
|
$this->container = $container; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getContainer() : DIContainer |
123
|
|
|
{ |
124
|
|
|
return $this->container; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function loadModule($name) |
128
|
|
|
{ |
129
|
|
|
$name = ucfirst(strtolower($name)); |
130
|
|
|
$module = $this->container->resolve('\Zewa\App\Modules\\' . $name); |
131
|
|
|
|
132
|
|
|
$module->setRequest($this->request); |
133
|
|
|
$module->setRouter($this->router); |
134
|
|
|
$module->setConfig($this->configuration); |
135
|
|
|
$module->setContainer($this->container); |
136
|
|
|
$module->setView($this->view); |
137
|
|
|
|
138
|
|
|
return $module; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|