-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
238 lines (189 loc) · 4.97 KB
/
index.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
<?php
/**
*Include the neccesary Class (Init) For intialization of the System
*Note:: This Index will not work without the include file set to the right path!
*/
require 'core/app.php';
require 'vendor/autoload.php';
$app = new Init;
define('ENVIRONMENT', 'development');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
/**
*Run checks for server path
*/
if (isset($_SERVER['PATH_INFO']))
{
/**
*Set var $path to Predefined $_SERVER['PATH_INFO']
*/
$path = $_SERVER['PATH_INFO'];
/**
*Split result or Sever path request into Array
*@return $path;
*/
$server = $app->path_split($path);
}
/*
Assign default '/' if previous check result to False
*/
else
{
/**
*Set path to '/'
*/
$server = '/';
}
switch (Init::is_slash($server))
{
case true:
require_once __DIR__.'/Models/indexModel.php';
require_once __DIR__.'/Controllers/indexController.php';
$app->req_model = new IndexModel();
$app->req_controller = new IndexController($app->req_model);
/**
*Model and Controller assignment with first letter as UPPERCASE
*@return Class;
*/
$model = $app->req_model;
$controller = $app->req_controller;
/**
*Creating an Instance of the the model and the controller each
*@return Object;
*/
$ModelObj = new $model;
$ControllerObj = new $controller($app->req_model);
/**
*Assigning Object of Class Init to a Variable, to make it Usable
*@return Method Name;
*/
$method = $app->req_method;
/**
*Check if Controller Exist is not empty, then performs an
*action on the method;
*@return true;
*/
if ($app->req_method != '')
{
/**
*Outputs The Required controller and the req *method respectively
*@return Required Method;
*/
print $ControllerObj->$method($app->req_param);
}
else
{
/**
*This works in only when the Url doesnt have a parameter
*@return void;
*/
print $ControllerObj->index();
}
break;
case false:
/**
*Set Required Controller name ;
*@return controller;
*
*/
$app->req_controller = $server[1];
/**
*Set Required Model name
*@return model;
*/
$app->req_model = $server[1];
/**
*Set Required Method name
*@return method;
*/
$app->req_method = isset($server[2])? $server[2] :'';
/**
*Set Required Params
*@return params;
*/
$app->req_param = array_slice($server, 3);
/**
*Check if Controller Exist
*@return void;
*/
$req_controller_exists = __DIR__.'/Controllers/'.$app->req_controller.'Controller.php';
if (file_exists($req_controller_exists))
{
/**
*Requiring all the files needed i.e The Corresponding Model and Controller
*@return corresponding class respectively;
*/
require_once __DIR__.'/Models/'.$app->req_model.'Model.php';
require_once __DIR__.'/Controllers/'.$app->req_controller.'Controller.php';
/**
*Model and Controller assignment with first letter as UPPERCASE
*@return Class;
*/
$model = ucfirst($app->req_model).'Model';
$controller = ucfirst($app->req_controller).'Controller';
/**
*Creating an Instance of the the model and the controller each
*@return Object;
*/
$ModelObj = new $model;
$ControllerObj = new $controller(ucfirst($app->req_model.'Model'));
/**
*Assigning Object of Class Init to a Variable, to make it Usable
*@return Method Name;
*/
$method = $app->req_method;
/**
*Check if Controller Exist is not empty, then performs an
*action on the method;
*@return true;
*/
if ($app->req_method != '')
{
/**
*Outputs The Required controller and the req *method respectively
*@return Required Method;
*/
print $ControllerObj->$method($app->req_param);
}
else
{
/**
*This works in only when the Url doesnt have a parameter
*@return void;
*/
print $ControllerObj->index();
}
}
else
{
header('HTTP/1.1 404 Not Found');
die('404 - The file - '.$app->req_controller.' - not found');
//require the 404 controller and initiate it
//Display its view
}
break;
default:
print 'An Error Occured';
break;
}