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

Provide specific objects on individual invocation #140

Closed
g105b opened this issue Oct 18, 2023 · 3 comments · Fixed by #141
Closed

Provide specific objects on individual invocation #140

g105b opened this issue Oct 18, 2023 · 3 comments · Fixed by #141
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@g105b
Copy link
Member

g105b commented Oct 18, 2023

We already have this:
https://github.com/PhpGt/ServiceContainer/blob/master/src/Injector.php#L26C24-L26C24

This $extraArgs parameter is currently not used anywhere, as I've never found a use for matching a parameter by string.

I think we should drop this functionality completely, and replace the function of $extraArgs.

At the point of invocation, I would like to be able to pass a specific object, so we can have DomTemplate Components with their own PHP, solving the issue described in phpgt/DomTemplate#331

When a DomTemplate Component is detected, the invoke function of the Injector should be called with a few extra indices of $extraArgs: The Gt\Dom\Element of the component, and a new ComponentBinder (the same as a DocumentBinder, but with a pre-constrained context element of the current component).

This would be a fabulous addition to WebEngine development!

@g105b g105b added enhancement New feature or request question Further information is requested labels Oct 18, 2023
@g105b g105b self-assigned this Oct 18, 2023
@g105b
Copy link
Member Author

g105b commented Oct 18, 2023

It would be useful if the extraArgs overwrote the Injector when looking for a matching class instance. If there was already a XYZ class in the ServiceContainer, providing a new instance of XYZ to extraArgs would prefer to use this one.

This means we could provide one of two things:

  1. provide a default instance of the ComponentBinder so when there's no specific instance provided, an exception is thrown saying something like "A ComponentBinder can only be used within a Component element's go/do functions".
  2. Rename the DocumentBinder completely to just be a Binder... then the Binder itself can be overridden when in the context of a Component.

@g105b
Copy link
Member Author

g105b commented Oct 18, 2023

I like how just using a Binder everywhere enforces encapsulation, but maybe some components should be able to bind data outside of their own component element? Maybe? Maybe not... maybe they should just have access to the HTMLDocument if they need to be heavy handed with their encapsulation... (?)

@g105b
Copy link
Member Author

g105b commented Oct 18, 2023

More details on the above at phpgt/DomTemplate#470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant