-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
100 lines (83 loc) · 2.28 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
<?php
/**
* Mown Framework 3.0
* Cyway Digital - 2023
*
* @author M. Vulcano
* @link https://cyway.it
* @location Italy
*
*/
// Load Configuration files
require 'conf/config.php';
require 'conf/database.php';
require 'conf/mail.php';
require 'libs/MownException.php';
$permittedIPs = [
'xxx.xxx.xxx.xxx'
];
// Handle Maintenance mode
if (MAINTENANCE_MODE && !in_array($_SERVER['REMOTE_ADDR'],$permittedIPs)) {
http_response_code(503); // Service Unavailable
echo "<h1>SISTEMA IN MANUTENZIONE - torna più tardi!</h1>";
exit;
}
// Define Error reporting settings
if (defined('SYS_STAGE') && SYS_STAGE != 'PROD') {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
// Define autoloader function
function autoloader($class) {
try {
$package = array('MVC','static');
$path = LIBS_PATH . $class .".php";
if (file_exists($path)) {
require_once $path;
return true;
} else {
foreach ($package as $dir) {
$path = LIBS_PATH . $dir . "/" . $class .".php";
if (file_exists($path)) {
require_once $path;
return true;
}
}
}
throw new mownException("Autoloader: Unable to load $class class.");
} catch (mownException $e) {
$e->errorMessage();
}
}
// Set Uncaugth Exception Handler
set_exception_handler(array('mownException', 'unhandledException'));
// Set autoloader
spl_autoload_register('autoloader');
// Check PHP Compatibility
try{
if ( !version_compare(phpversion(), SYS_PHPVER, '>') ) {
throw new mownException("ERROR: System check not passed. Use PHP >= ".SYS_PHPVER);
}
} catch (mownException $e) {
$e->errorMessage();
}
// Invoke route engine
try {
if (class_exists('Routes')) {
$routes = new Routes();
} else {
throw new mownException('Class "Routes" not callable in '.basename(__FILE__).' on line'.__LINE__);
}
} catch (mownException $e) {
$e->errorMessage();
}
// set Optional Path Settings
//$routes->setControllerPath();
//$routes->setModelPath();
//$routes->setDefaultFile();
//$routes->setErrorFile();
// Start the session
Session::init();
// Let magic starts!
$routes->init();