object(A_Proxy)#3 (2) { ["proxified:private"]=> object(A)#4 (0) { } ["locator:private"]=> object(ServiceLocator)#1 (1) { ["listeners"]=> array(1) { ["A"]=> object(EventListener)#2 (0) { } } } } array(3) { [0]=> string(7) "proxify" [1]=> string(10) "setLocator" [2]=> string(6) "__call" } 0.0615470409393
0.00180101394653
proxified = new \$name;
foreach(get_class_methods(\$name) as \$method) {
runkit_method_remove($proxy, \$method);
}
}
public function setLocator(ServiceLocator \$locator) {
\$this->locator = \$locator;
}
public function __call(\$m, \$a) {
\$this->locator->before(\$this->proxified, \$m);
\$result = call_user_func_array(array(\$this->proxified, \$m), \$a);
\$this->locator->after(\$this->proxified, \$m);
return \$result;
}
}");
$obj = new $proxy();
$obj->proxify($name);
$obj->setLocator($this);
return $obj;
}
public function before($obj, $method) {
$name = get_class($obj);
$method = 'before'.$method;
if(isset($this->listeners[$name]))
$this->listeners[$name]->$method($obj);
}
public function after($obj, $method) {
$name = get_class($obj);
$method = 'after'.$method;
if(isset($this->listeners[$name]))
$this->listeners[$name]->$method($obj);
}
public function setListener($name, EventListener $listener) {
$this->listeners[$name] = $listener;
}
}
class EventListener {
public function __call($m, $a) {
//print $m."
";
}
}
function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); }
$l = new ServiceLocator;
$l->setListener('A', new EventListener());
$obj = $l->get("A");
var_dump($obj);
var_dump(get_class_methods($obj));
$m = getmicrotime();
$n = 1000;
while($n--) {
$obj->foo();
}
print (getmicrotime() - $m)."
";
$m = getmicrotime();
$n = 1000;
$obj = new A;
while($n--) {
$obj->foo();
}
print (getmicrotime() - $m)."
";
show_source(__FILE__);
?>