-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
179 lines (135 loc) · 4.63 KB
/
init.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
<?php
/**
File name: init.php
Version: 1.0
Author: Chris White
Description:
This file is the default init script.
VERSION HISTORY
1.0 - file created
*/
//start the output buffer.
ob_start();
/*
* APP_ROOT is the directory on the server that the application is run from.
* This is not necessarily the same as the DOCUMENT_ROOT of the server, for example
* where the application is run in a subfolder of the doc root.
*/
$APP_ROOT = substr(__FILE__, 0, strrpos(__FILE__,'/'));
set_include_path(get_include_path() . PATH_SEPARATOR . $APP_ROOT . '/system/includes/');
//session management
//ini_set('session.save_path', $APP_ROOT . '/system/sessions/');
ini_set('session.gc_maxlifetime', 2000);
ini_set('session.gc_divisor', 100);
ini_set('session.gc_probability', 20);
//Tell PHP to detect the line endings of text not just to assume it
// This is required to cope with Machintosh line endings.
ini_set ("auto_detect_line_endings","1");
/******************************************
START Utility Functions
*******************************************/
/**
* findPath($dirPath, $className)
*
* Used by __autoload to find the file that contains the class definition.
* scans the directory structure taking $dirPath as the root from which to scan
* looking for a file with the name $className.php. returns the path to the file.
*
* This functions assumes that the file containing the class is named exactly as the
* class it contains with a .php extension. For example a class called TestClass would
* be contained in a file called TestClass.php.
*
* @param : $dirPath - The root path to search from
* @param : $className - The $className.php file to look for
*
* @return : The path to the searched file or NULL if not found.
*/
function findPath($dirPath, $className) {
global $APP_ROOT;
if (file_exists($APP_ROOT.'/'.$dirPath.'/'.$className.'.php'))
return $dirPath.'/'.$className.'.php';
$dir = dir($APP_ROOT."/".$dirPath);
while ($file = $dir->read()) {
if (is_dir($dir->path."/".$file) && ($file != ".") && ($file != "..")) {
$inc = findPath($dirPath."/".$file, $className);
if (strpos($inc, "$className.php")) {
return $inc;
}
}
}
return null;
}
/**
* --autoload($className)
*
* Used by the system to 'include' the file containing the class definition of a class
* refered to in the script but has not be described yet.
*
* @param : $className - The name of the class
*
*/
function __autoload($className) {
global $APP_ROOT;
$class_roots[] = "system/classes";
foreach($class_roots as $root) {
$inc = findPath($root, $className);
if (strpos($inc, "$className.php")) {
require_once $APP_ROOT . '/' . $inc;
return;
}
}
}
/**************************************
END Utility Functions
***************************************/
/**************************************
Start Global Config setup
***************************************/
Config::setConfDir($APP_ROOT."/system/config");
$URL_ROOT = Config::get('system.URL.root');
/***********************************
End Global Config setup
* ************************************/
/**********************************
Start logging setup
***********************************/
$LOG_TYPE = 'file';
if (Config::get('system.loglevel') == 'NONE')
$LOG_TYPE = 'null';
$system_log = &Log::factory($LOG_TYPE, $APP_ROOT . Config::get("system.logfiledir") . "/" . $_SERVER['REMOTE_ADDR'] . ".log", "SID=".session_id(), array(), constant('PEAR_LOG_'.Config::get("system.loglevel")));
$system_log->info("Log file initialised");
/****************************
End Logging setup
*****************************/
$initParams = new SimpleXMLElement(file_get_contents("$APP_ROOT/system/config/init_params.xml"));
$system_log->info("Loaded init_params");
/****************************
* START INCLUDES
****************************/
foreach ($initParams->includes->include as $include) {
switch ((string)$include['type']) {
case 'require':
$system_log->info("requiring ... $include");
require_once($include);
break;
case 'include':
$system_log->info("including ... $include");
include_once($include);
break;
}
}
/****************************
* END INCLUDES
****************************/
/****************************
* START DB setup
****************************/
//$DB = DatabaseFactory::getConnection();
/****************************
* END DB setup
****************************/
// We need to call this in order to be able to access the session object.
session_start();
$system_log->info("Request started");
$system_log->debug('Initial setup complete');
?>