Skip to content
Snippets Groups Projects
Commit 629d8f77 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

sandbox : can define dynamic methods on Class_Entity

parent 030332df
1 merge request!1715Master
......@@ -21,9 +21,14 @@
class Class_Entity {
protected $_attribs = [];
protected
$_attribs = [],
$_methods = [];
public function __call($name, $params) {
if (array_key_exists($name, $this->_methods))
return call_user_func_array($this->_methods[$name], $params);
if (!preg_match('/(get|set)(\w+)/', $name, $matches))
throw new RuntimeException('Call to unknown method ' . $name);
......@@ -62,4 +67,10 @@ class Class_Entity {
public function toArray() {
return $this->_attribs;
}
public function whenCalledDo($name, $closure) {
$this->_methods[$name] = $closure;
return $this;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment