Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: intercept object access #57

Open
3 of 6 tasks
talss89 opened this issue May 3, 2023 · 2 comments
Open
3 of 6 tasks

feature: intercept object access #57

talss89 opened this issue May 3, 2023 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@talss89
Copy link
Member

talss89 commented May 3, 2023

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 return null 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().

  • Create event trigger / handler subsystem
  • Intercept object method calls
  • Override and skip object method calls
  • Intercept property accesses
  • Intercept property writes
  • Recursive HookProxy works (ie. proxying-a-proxy should proxy the original object)

Branch feature/intercept tracks this feature.

@talss89 talss89 self-assigned this May 3, 2023
@talss89 talss89 added documentation Improvements or additions to documentation enhancement New feature or request labels May 3, 2023
@talss89
Copy link
Member Author

talss89 commented May 3, 2023

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.

talss89 added a commit that referenced this issue May 3, 2023
@talss89
Copy link
Member Author

talss89 commented May 3, 2023

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"));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant