-
Notifications
You must be signed in to change notification settings - Fork 30
[TwigHooks] Add debug command to display hooks and hookables #326
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
base: main
Are you sure you want to change the base?
[TwigHooks] Add debug command to display hooks and hookables #326
Conversation
Add `sylius:debug:twig-hooks` command to list and inspect Twig hooks. Features: - List all hooks with hookable count - Filter hooks by name (case-insensitive) - Show hook details with hookables (name, type, target, priority) - `--all` option to include disabled hookables - `--config` option to display hookable configuration - Shell autocompletion for hook names
| $hookables = $this->hookablesRegistry->getAllFor($hookName); | ||
| $enabledCount = \count(array_filter( | ||
| $hookables, | ||
| static fn (AbstractHookable $h): bool => !$h instanceof DisabledHookable, |
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.
| static fn (AbstractHookable $h): bool => !$h instanceof DisabledHookable, | |
| static fn (AbstractHookable $hookable): bool => !$hookable instanceof DisabledHookable, |
| return '{...}'; | ||
| } | ||
|
|
||
| return '[' . implode(', ', array_map($this->formatValue(...), $value)) . ']'; |
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.
I think you can use the VarDumper from Symfony instead.
Usage example I use in a future package:
private function formatValue(mixed $value): string
{
if (is_string($value) && str_ends_with($value, '::class')) {
$stringValue = $value;
} else {
$stringValue = VarExporter::export($value);
}
$indentedValue = preg_replace(
'/^/m',
str_repeat(' ', $this->indentLevel), // 4 spaces per indent level
$stringValue,
);
return ltrim($indentedValue);
}- Rename $h to $hookable for clarity - Use VarExporter instead of custom formatValue logic
| } | ||
|
|
||
| $parts = []; | ||
| foreach ($configuration as $key => $value) { |
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.
Could we use VarDumper on the $configuration var itself?
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->hookablesRegistry = $this->createMock(HookablesRegistry::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.
Could you try not to use mocks please?
Use a real HookablesRegistry with real hookables inside. So instantiating the objects into the tests instead of mocking.
Summary
Add
sylius:debug:twig-hooksconsole command to list and inspect Twig hooks configuration.Features
--alloption to include disabled hookables with status column--configoption to display hookable configurationUsage
Changes
DebugTwigHooksCommandclassgetHookNames()andgetAllFor()methods toHookablesRegistry