-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.php
109 lines (93 loc) · 3.53 KB
/
Application.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
<?php
require_once ROOT_DIR . DS . 'classes' . DS . 'libs' . DS . 'smarty-3.1.29' . DS . 'libs' . DS . 'Smarty.class.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'libs' . DS . 'smarty-3.1.29' . DS . 'libs' . DS . 'sysplugins'. DS . 'smarty_internal_resource_file.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'libs' . DS . 'PHPMailer' . DS . 'class.phpmailer.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'libs' . DS . 'PHPMailer' . DS . 'class.smtp.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'Database.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'SmartyInstance.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'FrontController.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'IController.php';
require_once ROOT_DIR . DS . 'classes' . DS . 'UserHelper.php';
/**
* Class Application our entrypoint for our OOP orientated website
*
* This class ha no Constructor and should be used statically.
* It holds all necessary Objects.
*
* @author Mario Kellner <mario.kellner@studmail.w-ha.de>
* @author Jan Markus Momper <jan-markus.momper@studmail.w-hs.de>
* @author Philipp Miller <philipp.miller@studmail.w-hs.de>
* @author Mark Friedrich <mark.friedrich@studmail.w-hs.de>
* @version 1.0
*/
class Application
{
/**
* @var SmartyInstance
*/
public static $smarty;
/**
* @var Database
*/
public static $database;
/**
* @var boolean
*/
public static $hasValidDatabaseConnection;
/**
* @var FrontController
*/
public static $frontController;
/**
* This static function will initialize the App.
*/
public static function Initialize() {
//register classloader for dynamic classloading
spl_autoload_register(function ($class) {
if(file_exists(ROOT_DIR . DS . 'classes' . DS . 'controller' . DS . $class . '.class.php')) {
include ROOT_DIR . DS . 'classes' . DS . 'controller' . DS . $class . '.class.php';
return true;
}
return false;
});
// Set our template
self::$smarty = SmartyInstance::getInstance();
// Connect to Database
self::$database = new Database();
self::$database->setServerInformation(Config::$databaseSettings['host'], Config::$databaseSettings['user'],
Config::$databaseSettings['password'] , Config::$databaseSettings['database']
);
try {
self::$database->connectToDatabase();
self::$hasValidDatabaseConnection = true;
}
catch (Exception $err) {
}
// create our moduleloader (Frontcontroller)
self::$frontController = new FrontController();
}
/**
* This function is our main function like "static void main(String[] args)" in java.
*
* @param $mainModule String Controller that should be loaded
*/
public static function Run($mainModule) {
if(self::$hasValidDatabaseConnection) {
if(self::$frontController->ControllerExists($mainModule)) {
self::$frontController->runController($mainModule);
}
else {
self::$frontController->runController(self::$frontController->defaultController);
}
}
else {
self::$frontController->runController("databaseerror");
}
}
/**
* Flush tells this class that everything should be outputed to the browser
*/
public static function Flush() {
self::$smarty->display('index.tpl');
}
}