This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.php
162 lines (125 loc) · 2.98 KB
/
seed.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
<?php
/**
* Bootstrap code for the framework
*
* Includes require libraries
*
* @package seed
*/
// We prefer E_ALL error reporting
if(defined('E_DEPRECATED')) { // PHP 5.3+
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
} else {
error_reporting(E_ALL);
}
// CONSTANTS //
// Probably not the best way to detect if we're on the command line
/**
* If the request was made via the command line
*/
define('COMMAND_LINE', isset($_SERVER['PWD']) && true);
/**
* Major php version
*/
define('SEED_PHP_VERSION', substr(phpversion(), 0, 1));
/**
* Path to the framework
*/
define('FRAMEWORK_PATH', dirname(__FILE__).'/');
/**
* Path to the called script
*/
if (COMMAND_LINE) {
define('SCRIPT_PATH', realpath($_SERVER['PWD'].'/'.$_SERVER['SCRIPT_FILENAME']));
} else {
define('SCRIPT_PATH', $_SERVER['SCRIPT_FILENAME']);
}
/**
* The current request URI
*/
if (isset($_SERVER['REQUEST_URI'])) {
define('REQUEST_URI', $_SERVER['REQUEST_URI']);
} else {
define('REQUEST_URI', '');
}
// INCLUDES //
/**
* Base files
*/
seed_include('library/base');
/**
* Custom error handler
*/
seed_include('error/error');
// FUNCTIONS //
/**
* Includes a seed class or packages
*
* @param string $path The class (e.g. "library/error") or package (e.g. "library") to include
* @return bool
*/
function seed_include($path) {
$path = strtolower($path);
$path_parts = explode('/', $path);
if (!count($path_parts) || count($path_parts) > 2) {
trigger_error("Inavlid path", E_USER_WARNING);
return false;
}
$path = dirname(__FILE__).'/'.$path_parts[0].'/';
if (isset($path_parts[1])) {
$path .= '/lib/'.$path_parts[1].'.php';
} else {
$path .= $path_parts[0].'.php';
}
if (!file_exists($path)) {
trigger_error("Couldn't find required class in '$path'", E_USER_WARNING);
return false;
}
require_once($path);
return true;
}
function seed_vendor_include($path) {
$path = strtolower($path);
$path = dirname(__FILE__).'/vendor/'.$path.'.php';
if (!file_exists($path)) {
trigger_error("Couldn't find required class in '$path'", E_USER_WARNING);
return false;
}
require_once($path);
return true;
}
/**
* Includes all the files in a given dir
*
* @param string $path
* @return bool
*/
function seed_require_dir($path, $load_first = null) {
if (!file_exists($path) || !is_dir($path)) {
trigger_error("'$path' is not a directory", E_USER_WARNING);
return false;
}
if (!is_null($load_first)) {
if (!is_array($load_first)) $load_first = array($load_first);
foreach($load_first as $file) {
if (file_exists($path.$file)) {
require_once($path.$file);
}
}
} else {
$load_first = array();
}
$dir = dir($path);
while(($file = $dir->read()) !== false ) {
// ignore directories, hidden files, and files whose extension is not php
if (substr($file, 0, 1) == '.' || substr($file, -4) != '.php' || in_array($file, $load_first)) {
continue;
}
// make sure the file exists
if(is_file($path.$file)) {
require_once($path.$file);
}
}
return true;
}
?>