forked from CraryPrimitiveMan/phpMongoAdmin
/
App.php
53 lines (49 loc) · 1.18 KB
/
App.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
<?php
use controllers\MongoController;
/**
* The project base path
*/
defined('BASE_PATH') or define('BASE_PATH',dirname(__FILE__));
/**
* The project base class
*/
Class App
{
/**
* The app object for global
* @var App
*/
private static $_app = null;
/**
* Define the app config
* @var array
*/
public static $config;
/**
* Get the app. It's a singleton.
* @param array $config The default config
* @return App
*/
public static function getApp($config) {
if (self::$_app === null) {
self::$config = include_once($config);
self::$_app = new App();
}
return self::$_app;
}
/**
* Run the application with the action
*/
public function run()
{
// Add the default action index
$action = (!isset($_GET['action']) || empty($_GET['action'])) ? 'index' : $_GET['action'];
$controller = new MongoController();
$action = 'action' . ucwords($action);
if(method_exists($controller, $action)) {
$controller->$action();
} else {
throw new Exception("$action doesn't exist.");
}
}
}