-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
112 lines (68 loc) · 2.33 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
<?php
/**
* ✨💥✨ </SPARK> ✨💥✨
* Simple.PHP.Ajax.Request.Kit
*
* Bootstrap and routing functions
*
* @author Caspius Labs💖
* @link https://github.com/CaspiusLabs/SPARK
* @version 2.0.1
* @package Core
*/
require_once 'config.php'; // must run as first (best to place in safe unreadable directory!)
include_once 'spark.php'; // must run as second
// check if development environment is turned on
if ( APP_DEV_ENV ) {
// if yes display all erros
ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors', 0 );
// and turn on custom error handlers
set_error_handler( array( 'Spark', 'ErrorHandler' ) );
set_exception_handler( array( 'Spark', 'ExceptionHandler' ) );
register_shutdown_function( array( 'Spark', 'FatalErrorHandler' ) );
} else {
// if not display nothing
ini_set( 'error_reporting', 0 );
ini_set( 'display_errors', 0 );
}
// parse uri request
$url = parse_url( trim( $_SERVER['REQUEST_URI'], '/') );
// check if pretty urls are used
if ( !empty($url['path']) && $url['path'] != 'index.php' ) {
$arguments = explode('/', $url['path'] );
// if not try with standard urls
} else if ( !empty($url['query']) ) {
parse_str($url['query'], $query);
foreach ( $query as $key => $val ) {
$arguments[] = $key;
$arguments[] = $val;
}
// if no url given fallback to default request
} else {
$arguments = $_REQUEST;
}
// define call hook arguments
$class = isset( $arguments[0] ) ? $arguments[0] : APP_CALLHOOK;
$method = isset( $arguments[1] ) ? $arguments[1] : APP_INDEXHOOK;
// init call hook class
if ( class_exists( $class ) ) {
callHook( $class, $method, $arguments );
} else if ( class_exists( APP_CALLHOOK ) ) {
callHook( APP_CALLHOOK, $method, $arguments );
} else {
trigger_error( "Call hook '".APP_CALLHOOK."' class missing! Check config file or reinstall.", E_USER_ERROR );
}
// launch call hook class function
function callHook( $call, $hook, $params ) {
$app = new $call();
$ajax = Spark::IsAjax() ? APP_AJAXHOOK : '';
call_user_func_array( array( $app, $ajax.$hook), $params );
}
// autoload call hook class function
function __autoload( $className ) {
$class = strtolower( $className ).'.php';
if ( file_exists( $class ) ) {
include_once $class;
}
}