/
Event.php
71 lines (56 loc) · 1.68 KB
/
Event.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
<?php
/**
* Created by zhouzhongyuan.
* User: zhouzhongyuan
* Date: 2015/11/28
* Time: 17:50
*/
namespace shiwolang\event;
class Event
{
protected static $definedClasses = [];
protected static $_instance = [];
protected $events = [];
protected function __construct($events = null)
{
if ($events !== null) {
$this->events = $events;
return;
}
static::$definedClasses = get_declared_classes();
$allClass = static::$definedClasses;
foreach ($allClass as $key => $className) {
$reflectionClass = new \ReflectionClass($className);
if (!in_array(EventHander::class, $reflectionClass->getInterfaceNames())) {
var_dump($reflectionClass->getInterfaceNames());
}
}
}
public static function init($name = "default", $events = null, $reinit = false)
{
if (!isset(static::$_instance[$name]) || $reinit) {
static::$_instance[$name] = new static($events);
} else {
throw new EventException("The Proxy name of (" . $name . ") does exist");
}
return static::$_instance[$name];
}
/**
* @param string $name
* @return self
* @throws EventException
*/
public static function instance($name = "default")
{
if (isset(static::$_instance[$name])) {
return static::$_instance[$name];
} else {
throw new EventException("The Proxy name of (" . $name . ") does not exist");
}
}
public function proxy(&$object, &$objectCopy)
{
$objectCopy = $object;
return $object = new ProxyObject($object);
}
}