-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
feat: introduce hook services #790
base: 2.x
Are you sure you want to change the base?
Conversation
fab6978
to
2b0f3a1
Compare
|
||
namespace Zenstruck\Foundry\Hooks; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a first time, I think this is enough.
Maybe in a second time, if someone needs it, we could implement TARGET_METHOD
and IS_REPEATABLE
, but this will complexify a lot the DI
foreach ($container->findTaggedServiceIds('foundry.hook') as $id => $tags) { | ||
$index = isset($tags[0]['class']) | ||
? HooksRegistry::hookClassSpecificIndex($tags[0]['hook'], $tags[0]['class']) | ||
: $tags[0]['hook']; | ||
|
||
$iterators[$index] ??= []; | ||
$iterators[$index][] = new Reference($id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're kinda missing a priority here. But that's not straightforward to do, because "global hook" and "hook specific to a class" are not in the same iterator.
I propose to leave this like this, and see if someone ever asks for it :)
#[AsAfterInstantiateFoundryHook(class: EntityForHooks::class)] | ||
final class ObjectAfterInstantiateHook | ||
{ | ||
/** | ||
* @param AfterInstantiate<EntityForHooks> $hook | ||
*/ | ||
public function __invoke(AfterInstantiate $hook): void | ||
{ | ||
$hook->object->name = "{$hook->object->name}\nObjectAfterInstantiateHook"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is an example of a hook.
another syntax is possible:
#[AsFoundryHook(event: AfterInstantiate::class(, class: EntityForHooks::class))]
final class AddressAfterInstantiateHook
{
public function __invoke(AfterInstantiate $hook): void;
}
it would be clear then, that you should pass a AfterInstantiate
to the __invoke()
method.
I also wondered if we should not introduce an interface, but, that would mean 3 interfaces. And an attribute AND an interface seems redundant.
WDYT?
No description provided.