Open ruudk opened 1 year ago
(I've misunderstood, #179 is about a different thing, reopening)
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.
Hey @ruudk I'm now considering implementing this next(-ish). Would you still find it useful or you don't need it anymore?
@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,
) {}
}
Ok, got it, let me see what I can do :-)
Example use case, I want to prevent the usage of a certain class / method, inside a class that has
#[Entity]
attribute.