forked from avdg/ppi-framework-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.php
242 lines (210 loc) · 6.82 KB
/
App.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* This is the PPI Appliations Configuration class which is used in the Bootstrap
*/
/**
*
* @package Core
* @author Paul Dragoonis <dragoonis@php.net>
* @copyright 2001-2010 Digiflex Development Team
* @license http://opensource.org/licenses/mit-license.php MIT
* @link www.ppiframework.com
*/
class PPI_App {
/**
* The error level to throw via error_reporting()
*
* @var int
*/
protected $_errorLevel = E_ALL;
/**
* Whether to display errors or not. This gets fired into ini_set('display_errors')
*
* @var string
*/
protected $_showErrors = 'On';
/**
* The block in the config file to get the config data from
*
* @var string
*/
protected $_configBlock = 'development';
/**
* The site mode. Default is 'development'. This determines how PPI handles exceptions
*
* @var string
*/
protected $_siteMode = 'development';
/**
* The config object
*
* @var null|PPI_Config
*/
protected $_config = null;
/**
* The PPI_Dispatch object
*
* @var null|PPI_Dispatch
*/
protected $_dispatcher = null;
/**
* The PPI_Router object
*
* @var null|PPI_Router
*/
protected $_router = null;
/**
* The PPI_Session object
*
* @var null|PPI_Session
*/
protected $_session = null;
function __construct($p_aParams = array()) {
if(!empty($p_aParams)) {
foreach ($p_aParams as $key => $value) {
if (method_exists($this, ($sMethod = 'set' . ucfirst($key)))) {
$this->$sMethod($value);
}
}
}
}
/**
* Setter for the environment, passing in options determining how the app will behave
*
* @param array $p_aOptions The options
* @return void
*/
function setEnv(array $p_aOptions) {
if(isset($p_aOptions['config'])) {
$this->_config = $p_aOptions['config'];
unset($p_aOptions['config']);
}
// The sites "mode" this is production or development.
// This is so PPI knows how to handle things like errors and exceptions without implicitly telling it what to do.
if(isset($p_aOptions['siteMode'])) {
if(in_array($p_aOptions['siteMode'], array('development', 'production'))) {
$this->_siteMode = $p_aOptions['siteMode'];
}
unset($p_aOptions['siteMode']);
}
// Any further options passed, eg: it maps; 'errorLevel' to $this->_errorLevel
foreach($p_aOptions as $option) {
$option = '_' . $option;
if(isset($this->$option)) {
$this->$option = $option;
}
}
}
/**
* Set the router object for the app bootup
*
* @param PPI_Router_Interface $p_oRouter The router object
* @return void
*/
function setRouter(PPI_Router_Interface $p_oRouter) {
$this->_router = $p_oRouter;
}
/**
* Set the dispatch object for the app bootup
*
* @param PPI_Dispatch_Interface $p_oDispatch The dispatch object
* @return void
*/
function setDispatcher(PPI_Dispatch_Interface $p_oDispatch) {
$this->_dispatcher = $p_oDispatch;
}
/**
* Set the session object for the app bootup
*
* @param PPI_Session_Interface $p_oSession The session object
* @return void
*/
function setSession(PPI_Session_Interface $p_oSession) {
$this->_session = $p_oSession;
}
/**
* Run the boot process, boot up our app. Call the relevant classes such as:
* config, registry, session, dispatch, router.
*
* @return $this Fluent interface
*/
function boot() {
error_reporting($this->_errorLevel);
ini_set('display_errors', $this->_showErrors);
// Fire up the default config handler
if($this->_config === null) {
$this->_config = new PPI_Config('general.ini', array('block' => $this->_siteMode));
}
$this->_config = $this->_config->getConfig();
$registry = PPI_Registry::getInstance();
// Set the config into the registry for quick read/write
$registry->set('PPI_Config', $this->_config);
// ------------- Initialise the session -----------------
if(!headers_sent()) {
// Fire up the default session handler
if($this->_session === null) {
$this->_session = new PPI_Session();
}
$registry->set('PPI_Session', $this->_session);
}
// -------------- Library Autoloading Process --------------
if(!empty($this->_config->system->autoloadLibs)) {
foreach(explode(',', $this->_config->system->autoloadLibs) as $sLib) {
switch(strtolower(trim($sLib))) {
case 'zf':
PPI_Autoload::add('Zend', array(
'path' => SYSTEMPATH . 'Vendor/',
'prefix' => 'Zend_'
));
break;
case 'github':
$githubAutoloader = SYSTEMPATH . 'Vendor/Github/Autoloader.php';
if(!file_exists($githubAutoloader)) {
throw new PPI_Exception('Unable to autoload github, the github autoloader was no found.');
}
include_once(SYSTEMPATH . 'Vendor/Github/Autoloader.php');
Github_Autoloader::register();
break;
// @todo - test this.
case 'swift':
include_once(SYSTEMPATH . 'Vendor/Swift/swift_required_pear.php');
break;
/*
case 'solar':
PPI_Autoload::add('Solar', array(
'path' => SYSTEMPATH . 'Vendor/',
'prefix' => 'Solar_'
));
Solar::start();
break;
*/
}
}
}
$registry->set('PPI_App', $this);
return $this; // Fluent Interface
}
/**
* Call the dispatch process. Running the dispatcher and dispatching
*
* @return $this Fluent interface
*/
function dispatch() {
// Fire up the default dispatcher
if($this->_dispatcher === null) {
$this->_dispatcher = new PPI_Dispatch_Standard(array('router' => $this->_router));
}
$dispatch = new PPI_Dispatch($this->_dispatcher);
PPI_Registry::getInstance()->set('PPI_Dispatch', $dispatch);
$dispatch->dispatch();
return $this;
}
/**
* Get the current site mode set, such as 'development' or 'production'
*
* @return string
*/
function getSiteMode() {
return $this->_siteMode;
}
}