-
Notifications
You must be signed in to change notification settings - Fork 16
/
pegasus.php
237 lines (209 loc) · 7.87 KB
/
pegasus.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
<?php
define('PEGASUS_VERSION', '0.9.0 BETA');
/**
* Pegasus PHP Application Framework
*
* The Pegasus PHP Application Framework...
*
* @copyright TBA
* @license TBA
* @version CVS: $Id: pegasus.php,v 1.37 2012/10/05 21:34:15 cbschuld Exp $
* @link
* @since
*/
// Smarty requires magic_quotes_runtime to be turned off to operate properly
if (get_magic_quotes_runtime() != 0) {
exit('ERROR: PegasusPHP requires magic_quotes_runtime to be turned off to operate properly');
}
if (!defined('PROJECT_NAME')) {
define('PROJECT_NAME', 'pegasus_app');
}
if (!defined('BASE_PATH')) {
define('BASE_PATH', __DIR__);
}
if (!defined('FRAMEWORK_PATH')) {
define('FRAMEWORK_PATH', __DIR__ . '/');
}
if (!defined('CACHE_PATH')) {
define('CACHE_PATH', constant('BASE_PATH') . '/cache/');
}
if (!defined('URL_PATH')) {
define('URL_PATH', '/pegasus');
}
if (!defined('URL_VAR')) {
define('URL_VAR', 'pq');
}
if (!defined('USER_VAR')) {
define('USER_VAR', 'user');
}
if (!defined('USER_STATUS_VAR')) {
define('USER_STATUS_VAR', 'pegasusUserLoggedIn');
}
if (!defined('OFFICE_VAR')) {
define('OFFICE_VAR', 'office');
}
if (!defined('COMPANY_VAR')) {
define('COMPANY_VAR', 'company');
}
if (!defined('ASSERT_ENABLED')) {
define('ASSERT_ENABLED', true);
}
if (!defined('SMARTY_CONTAINER_PAGE')) {
define('SMARTY_CONTAINER_PAGE', 'container.tpl');
}
if (!defined('SMARTY_CONTAINER_VALUE')) {
define('SMARTY_CONTAINER_VALUE', 'content');
}
if (!defined('DISABLE_PROPEL')) {
define('DISABLE_PROPEL', false);
}
if (!defined('PROPEL_NAME')) {
define('PROPEL_NAME', strtolower(constant('PROJECT_NAME')));
}
if (!defined('PROPEL_BUILD_PATH')) {
define('PROPEL_BUILD_PATH', constant('BASE_PATH') . '/propel/build');
}
if (!defined('PROPEL_CONF_NAME')) {
define('PROPEL_CONF_NAME', strtolower(constant('PROPEL_NAME')) . '-conf.php');
}
if (!defined('FPDF_FONTPATH')) {
define('FPDF_FONTPATH', constant('FRAMEWORK_PATH') . '/includes/fpdf153/font/');
}
if (!defined('TTF_DIR')) {
define('TTF_DIR', constant('FRAMEWORK_PATH') . '/includes/fonts/');
}
if (!defined('DATELONG')) {
define('DATELONG', 'l, F jS, Y');
}
if (!defined('TIMELONG')) {
define('TIMELONG', 'g:i A');
}
date_default_timezone_set('America/Phoenix');
spl_autoload_register('include_object');
require_once constant('FRAMEWORK_PATH') . 'objects/BasicObject.php';
require_once constant('FRAMEWORK_PATH') . 'objects/Pegasus.php';
Pegasus::timeStart();
if (Pegasus::isDebug()) {
$__DEBUG = new Debug();
}
// -------------------------------------------------------------------------
// Validate our Propel Configuration file is in the defined location
//
if (!constant('DISABLE_PROPEL')) {
if (!file_exists(constant('PROPEL_BUILD_PATH') . '/conf/' . constant('PROPEL_CONF_NAME'))) {
Pegasus::error(
'Propel Include Error',
'Unable to locate Propel Configuration File (' . constant('PROPEL_BUILD_PATH') . '/conf/' . constant('PROPEL_CONF_NAME') . ')',
"(You may desire to disable propel for this project. If so add the following to your project: define('DISABLE_PROPEL',true); Or you can alter the value of constant 'PROPEL_BUILD_PATH' to point to the propel 'build' directory in your project.)"
);
} else {
// -------------------------------------------------------------------------
// NOTE: Internally propel assumes all of their runtime objects will be including using relative paths based on the include_path.
set_include_path(get_include_path() .
constant('PATH_SEPARATOR') .
constant('PROPEL_BUILD_PATH') . '/classes/'
);
if (!defined('PROPEL_RUNTIME_PATH') || constant('PROPEL_RUNTIME_PATH') == '') {
define('PROPEL_RUNTIME_PATH', 'propel');
}
require_once constant('PROPEL_RUNTIME_PATH') . '/Propel.php';
Propel::init(constant('PROPEL_BUILD_PATH') . '/conf/' . constant('PROPEL_CONF_NAME'));
}
}
// Request, Session and View require access to the global _PEGASUS object
require_once constant('FRAMEWORK_PATH') . 'objects/Request.php';
require_once constant('FRAMEWORK_PATH') . 'objects/Session.php';
if (defined('USE_DWOO') && constant('USE_DWOO')) {
require_once constant('FRAMEWORK_PATH') . 'objects/ViewDwoo.php';
} else {
require_once __DIR__ . '/includes/Smarty-3.1.30/libs/Smarty.class.php';
require_once constant('FRAMEWORK_PATH') . 'objects/View.php';
}
function class_basename($class)
{
$class = is_object($class) ? get_class($class) : $class;
return basename(str_replace('\\', '/', $class));
}
/*
* Convenience include function which allows users to easily include their
* objects within the framework. The include_object() function
* looks a specific include locations in order to determine where the object
* exists. When the object is found it is included. The function looks for
* objects in the following order:
*
* 1) Within the framework under the FRAMEWORK_PATH/objects/<br/>
*
*
* @param string $strObjectName The name of the object to include
* @param boolean $bDisplayError If True the execution will stop and
* display an error. If False no message is displayed and the object
* was not included. (If False check return value).
* @return boolean True if the object was included, otherwise false.
*/
function include_object($strObjectName)
{
global $__INCLUDES;
if (!is_array($__INCLUDES)) {
$__INCLUDES = [];
}
$classObjectName = str_replace('\\', '/', $strObjectName);
if (!array_key_exists($classObjectName, $__INCLUDES)) {
$baseName = class_basename($strObjectName);
$aIncludePath = [];
$aIncludePath[] = constant('BASE_PATH') . '/src/' . $classObjectName . '.php';
$aIncludePath[] = constant('BASE_PATH') . '/objects/' . $classObjectName . '.php';
$aIncludePath[] = constant('BASE_PATH') . '/src/' .
strtolower(str_replace($baseName, '', $classObjectName)) . $baseName . '.php';
$aIncludePath[] = constant('FRAMEWORK_PATH') . '/objects/' . $classObjectName . '.php';
// Check each path/filename for a valid include
foreach ($aIncludePath as $path) {
if (file_exists($path)) {
require_once $path;
$__INCLUDES[$path] = true;
return true;
}
}
}
return false;
}
/**
* Convenience function to dump debug information into the browser based on
* the results of var_dump().
* @var $mixed mixed variable to dump via var_dump()
*/
if (!function_exists('dump')) {
function dump($mixed)
{
echo '<pre>';
var_dump($mixed);
echo '</pre>';
}
}
/**
* assertWorker is an assert callback to manage the errors within the
* framework.
* @param string $file The filename that caused the popped assert
* @param integer $line The line number where the popped assert is at
* @param string $strTrigger The code that caused the assert to pop
*
*/
function assertWorker($file, $line, $strTrigger)
{
if ($strTrigger === '') {
$strTrigger = 'WARNING: do not forget to wrap your assert ' .
' conditions with single quotes. ' .
'ex assert(\'$bValue\')';
}
$strMessage = "ASSERT Failed at line {$line} in '{$file}' ( {$strTrigger} )";
if (Pegasus::isDebug()) {
Pegasus::error('ASSERT Failed', $strMessage);
} else {
die($strMessage);
}
}
// Activate assert and make it quiet
assert_options(ASSERT_ACTIVE, constant('ASSERT_ENABLED'));
assert_options(ASSERT_WARNING, constant('ASSERT_ENABLED'));
assert_options(ASSERT_QUIET_EVAL, constant('ASSERT_ENABLED'));
// Set up the assert callback
assert_options(ASSERT_CALLBACK, 'assertWorker');