-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
64 lines (52 loc) · 2.09 KB
/
index.php
File metadata and controls
64 lines (52 loc) · 2.09 KB
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
<?php
define("_uniq_token_", TRUE);
include_once __DIR__."/core/init.php";
//parsing
$params = explode('/', $_GET['p']);
$controller = isset($params[0]) ? $params[0] : \basic\core\Handler::error404("No get datas");
$action = !empty($params[1]) ? $params[1] : 'index';
//including
if($controller == "")
$controller = "home";
$baseControllerName = $controller;
if(!file_exists('controllers/'.$controller.'.php'))
\basic\core\Handler::error404("Unhandled path. Controls doesn't exist");
session_name("yourSessionName");
session_start();
$r = require('controllers/'.$controller.'.php');
$controller = "\basic\controllers\\".$controller."Controller";
$controller = new $controller();
if(!method_exists($controller, $action)){
$params[2] = $action;
$action = "index";
}
if(method_exists($controller, $action)){
unset($params[0]);
unset($params[1]);
try {
$method = new ReflectionMethod($controller, $action);
$numberOfRequiredParams = $method->getNumberOfRequiredParameters ();
$numberOfParams = $method->getNumberOfParameters ();
$nbr = count($params);
}
catch (Exception $e){
\basic\core\Handler::error404("PHP Exception : ".$e);
}
if($nbr >= $numberOfRequiredParams && $nbr <= $numberOfParams){ //lancement app
if(!\basic\models\User::isConnected() && $controller->getConnectedOnly())
\basic\core\Handler::error404("This page is restricted"); // change this with your own logic
call_user_func_array(array($controller, $action), $params);
$controller->render();
}
else if(method_exists($controller, "defaultParamsError")){ // Try to call a default error method if the call fail or if the params number is invalide.
if(!\basic\models\User::isConnected() && $controller->getConnectedOnly())
\basic\core\Handler::error404("This page is restricted"); // change this with your own logic
call_user_func_array(array($controller, "defaultParamsError"), array());
$controller->render();
}
else {
\basic\core\Handler::error404("Error calling function with params");
}
}
else
\basic\core\Handler::error404("Unhandled : the method doesn't exists in the controller => ".Tools::secure($action));