-
Notifications
You must be signed in to change notification settings - Fork 2
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
Introduce Gate service #12
Comments
+1 from me. Mainly for this reason:
I've encountered cases where a service is expensive to create, and due to how it gets wired into the application, it would get created even when it is not necessary. Personally though, I'd vote to have the predicate be the first argument so that the structure is similar to that of a ternary expression. I find that to be more intuitive. 'app.view' => new Gate(
'app.is-frontend',
'app.view.frontend',
'app.view.backend'
) Regarding nesting: this has been on my mind a number of times, although not nesting itself, but its "superset" of allowing arbitrary values and service hierarchies to be passed as dependencies. For instance, a common thing that I find myself doing is using the I have a couple of solutions in the works that would allow services to work with anything, not just service IDs. So for now I'd be hesitant to add a one-off for the |
Heya! Sorry for delay. Will look into this soon! Good to see you, guys :) |
Here are my thoughts on this.
|
By the way, just found this interesting NEON format, which is excellent for service definitions thanks to entities feature. |
If you don't want your dependency graph to change under those situations, then don't wire your services that way. But imposing that vision into this package's design is, in my opinion, unhealthy for a package whose sole purpose is to offer an alternative to plain closures. We should aim to provide options to consumers, with a focus on ease of use, clean code, and low friction when writing services. Configs, NEON, standards, and personal vision should have their own place; this package ain't it. On that same note, I'll be opening a couple of issues shortly that address some of the pain points I've found after using this package in a commercial product for over 2 years. For this issue, I think we should offer a |
Hello everyone.
In my projects, it is quite common to use a generic service ID to delegate to one of many specific services based on some context.
While this is workable, it is not as concise as it could be and -worse- it needs to create all instances before making the descision which one to actually return.
I think at least for the A/B scenario this could be greatly improved by the introduction of a simple
class Gate( string $service1, string $service2, callable $predicate )
:This service would call the
$predicate
function and grab either the first or the second ID from the container based on the result.Spinning this a bit further,
$predicate
could also bestring|callable
so that it optionally accepts another service ID pointing at the actual predicate (which is expected to returnbool
)Then you could write extremely compact
Gate
definitions like this.Turning this idea around, even the services themselves could be
string|callable
for prototyping service definitions really quickly:And this would also allow nesting Gates for staggeringly flexible and powerful definitions:
What do you think about this idea? Would you accept a PR for this?
The text was updated successfully, but these errors were encountered: