1 <?php
2
3 namespace rpf\system\module;
4 use rpf\system\rpf;
5
6 7 8 9 10 11 12 13 14 15 16 17 18
19 class moduleManager
20 {
21 22 23
24 protected $module = array();
25
26 public function __construct()
27 {
28 if (!isset($GLOBALS['rpfModule']) || $this != $GLOBALS['rpfModule'])
29 {
30
31 }
32 if (!isset($this->module['rpf\system\rpf']))
33 {
34
35 }
36 }
37
38 public function get($name)
39 {
40 if (!is_string($name))
41 {
42 $type = gettype($name);
43 throw new exception("Name (=string) of object expected, $type given");
44 }
45 if (!isset($this->module[$name]))
46 {
47 $this->add($name);
48 }
49 return $this->module[$name];
50 }
51
52 53 54 55 56 57 58
59 public function add($nameOrObject)
60 {
61 if (is_string($nameOrObject))
62 {
63 if (!isset($this->module[$nameOrObject]))
64 {
65 log::debug("Instantiating $nameOrObject()", __METHOD__."($nameOrObject)");
66 $this->module[$nameOrObject] = new $nameOrObject();
67 }
68 else
69 {
70 throw new exception("Can't set object by name '$nameOrObject' because it already exists");
71 }
72 }
73 else if (is_object($nameOrObject))
74 {
75 $name = get_class($nameOrObject);
76 if (!isset($this->module[$name]))
77 {
78 $this->module[$name] = new $nameOrObject;
79 }
80 else
81 {
82 throw new exception("Can't set object by instance of '$name' because it already exists");
83 }
84 }
85 else
86 {
87 $type = gettype($nameOrObject);
88 throw new exception("I've no idea what you're trying, but I'm sure that you can't add a $type to the global module-class");
89 }
90 return true;
91 }
92
93 public function __destruct()
94 {
95 log::debug("Shutdown moduleManager\n\n\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n", __METHOD__);
96 }
97 }