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

Add support for disallowing things when used inside class with certain attribute #180

Open
ruudk opened this issue Apr 3, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@ruudk
Copy link
Contributor

ruudk commented Apr 3, 2023

Example use case, I want to prevent the usage of a certain class / method, inside a class that has #[Entity] attribute.

@spaze spaze closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2023
@spaze spaze reopened this Apr 12, 2023
@spaze
Copy link
Owner

spaze commented Apr 12, 2023

(I've misunderstood, #179 is about a different thing, reopening)

@spaze spaze added the enhancement New feature or request label Apr 12, 2023
@ruudk
Copy link
Contributor Author

ruudk commented Apr 29, 2023

Another example:

<?php

final class CreateUserHandler 
{
    public function __construct(private EventRecorder $recorder)
    {
    }

    #[AsCommandHandler]
    public function handle(CreateUserCommand $command)
    {

    }
}

I want to forbid the usage of EventRecorder everywhere, except when it's used in a class that has the AsCommandHandler attribute (somewhere defined).

So in this case, the attribute is put on the handle method (not on the class) and the EventRecorder is used in the __construct. It should therefore be accepted because the attribute is used within or on the class.

@spaze
Copy link
Owner

spaze commented Jan 13, 2024

Hey @ruudk I'm now considering implementing this next(-ish). Would you still find it useful or you don't need it anymore?

@ruudk
Copy link
Contributor Author

ruudk commented Jun 3, 2024

@spaze Sorry for not getting back to you. That's a bit rude of me.

Yes, I would totally use this. As a matter of fact, today I needed it again.

New use case: I want to disallow RequestStack, but allow it inside a TwigComponent. It's the only way to get the request within a component.

#[AsTwigComponent]
final class Table
{
    public function __construct(
        private RequestStack $requestStack,
    ) {}
}

@spaze
Copy link
Owner

spaze commented Jun 19, 2024

Ok, got it, let me see what I can do :-)

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

No branches or pull requests

2 participants