1: <?php
2: /*
3: pluginHandler.class.php
4: Copyright 2012 Mika Ristolainen/Bmm Solutions
5: */
6:
7:
8: class pluginHandler {
9:
10: protected $objlist = array();
11:
12: public function __construct ($oid = null){
13: $this->initialize();
14: }
15:
16: public function initialize(){}
17:
18: public function enable($id){
19: $obj = $this->objlist[$id];
20: $obj->enableObject(true);
21: }
22:
23: public function register(&$obj){
24: foreach(array_keys($this->objlist) as $key)
25: if (get_class($obj) == get_class($this->objlist[$key])) return false;
26:
27: #error_log("PUSH OBJECT:".get_class($obj));
28: array_push($this->objlist,$obj);
29: }
30:
31: public function getRegisteredPluginObject($class,$method = null){
32: if ($method == null)
33: foreach(array_keys($this->objlist) as $key){
34: if ($method == null)
35: if ($this->objlist[$key] instanceof $class)
36: return $this->objlist[$key];
37: else
38: if ($this->objlist[$key] instanceof $class && method_exists($this->objlist[$key],$method))
39: return $this->objlist[$key];
40: }
41: return null;
42: }
43:
44: public function getEnabledObjectId(){
45:
46: foreach (array_keys($this->objlist) as $key){
47: $obj = $this->objlist[$key];
48: if ($obj->getObjectStatus()) return $key;
49: }
50: return null;
51: }
52:
53: public function getEnabledObjectIdList(){
54: $keylist_arr = array();
55: foreach (array_keys($this->objlist) as $key){
56: $obj = $this->objlist[$key];
57: if ($obj->getObjectStatus()) array_push($keylist_arr,$key);
58: }
59: return $keylist_arr;
60: }
61:
62: public function execPluginMethod($method,$params = array()){
63: $retval = false;
64: foreach (array_keys($this->objlist) as $key){
65: $obj = $this->objlist[$key];
66: if (is_object($obj) && method_exists($obj,$method )){
67: #error_log("CLASS: ".get_class($obj)." METHOD: $method");
68: call_user_func_array(array($obj, $method), $params);
69: $retval = true;
70: break;
71: }
72: unset($obj);
73: }
74: return $retval;
75: }
76:
77: }
78: ?>
79: