-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebCore.php
89 lines (77 loc) · 2.2 KB
/
WebCore.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
<?php
/**
* Created by Daniel Vidmar.
* User: Daniel
* Date: 5/10/2016
* Time: 6:45 PM
* Version: Beta 1
* Last Modified: 5/10/2016 at 6:45 PM
* Last Modified by Daniel Vidmar.
*/
class WebCore {
/**
* The instance of the WebCore Registry class.
* @var
*/
private static $instance;
/**
* An array controller all controller instances.
* @var array
*/
private static $controllers = array();
/**
* Override the constructor class.
*/
private function __construct() {
}
private function load_core() {
$this->add("db", "Database");
$this->add("form", "Form");
$this->add("template", "Template");
$this->add("oauth", "OAuth");
$this->add("secure", "Authentication");
}
/**
* Returns an instance of the WebCore Registry class, or creates and returns a new one if needed.
* @return mixed
*/
public static function instance(): WebCore {
if (!isset(self::$instance)) {
$class = __CLASS__;
$singleton = new $class;
if ($singleton instanceof WebCore) {
$singleton->load_core();
self::$instance = $singleton;
}
}
return self::$instance;
}
public function auto_loader($class) {
}
/**
* Override, to ensure we don't allow new instances.
*/
private function __clone() {
}
/**
* Used to get the instance of controller with name "@param $name".
* @param $name - The name of the controller to get
* @return mixed - Returns the controller's instance if it exists.
* @throws Exception - Throws if controller with name "@param $name" doesn't exists.
*/
public function get($name): Controller {
if (is_object(self::$controllers[$name])) {
return self::$controllers[$name];
}
throw new Exception("Unable to get controller with name of \"" . $name . "\".");
}
/**
* Used to add a controller with name "@param $name" to the controllers array.
* @param $name - The file name of the controller to add.
* @param $controller - The class name of the controller to add.
*/
public function add(string $name, Controller $controller) {
require_once('Controllers/' . $controller . '.php');
self::$controllers[$name] = new $controller(self::$instance);
}
}