Open talss89 opened 1 year ago
May need to refactor HookProxy
a bit for this. Detecting calls doesn't require a proxy, but detecting property access does.
Need to ensure HookProxy
can proxy another HookProxy
recursively too. Unsure if this works currently - not tested.
Recursive HookProxy
test now in branch, and is passing.
public function testRecursiveProxy() {
$obj = new MockClass(3);
$proxy_1 = new HookProxy(function($input) {return $input . '-proxy_1';}, $obj);
$proxy_2 = new HookProxy(function($input) {return $input . '-proxy_2' . '-' . $this->{'id'};}, $proxy_1);
$this->assertEquals("test-proxy_2-3", $proxy_2->___cb("test"));
}
}
It should be possible to intercept calls / accesses made by a handler to
$this
, without replacing the original handler.This means we can register
on_call
type events that are fired when a filter / action handler tries to access it's own$this
. We can then either return a new value to skip execution of the$this->some_method()
call, or returnnull
to allow the call to continue.This is a huge rabbit hole, and will need some thought. In theory we could pre and post process any object accessor similar to how we
inject()
.HookProxy
works (ie. proxying-a-proxy should proxy the original object)Branch feature/intercept tracks this feature.