[TwigHooks] Add debug command to display hooks and hookables#326
Open
camilleislasse wants to merge 4 commits intoSylius:mainfrom
Open
[TwigHooks] Add debug command to display hooks and hookables#326camilleislasse wants to merge 4 commits intoSylius:mainfrom
camilleislasse wants to merge 4 commits intoSylius:mainfrom
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
loic425
reviewed
Jan 27, 2026
| $hookables = $this->hookablesRegistry->getAllFor($hookName); | ||
| $enabledCount = \count(array_filter( | ||
| $hookables, | ||
| static fn (AbstractHookable $h): bool => !$h instanceof DisabledHookable, |
Member
There was a problem hiding this comment.
Suggested change
| static fn (AbstractHookable $h): bool => !$h instanceof DisabledHookable, | |
| static fn (AbstractHookable $hookable): bool => !$hookable instanceof DisabledHookable, |
| return '{...}'; | ||
| } | ||
|
|
||
| return '[' . implode(', ', array_map($this->formatValue(...), $value)) . ']'; |
Member
There was a problem hiding this comment.
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
loic425
reviewed
Feb 2, 2026
| } | ||
|
|
||
| $parts = []; | ||
| foreach ($configuration as $key => $value) { |
Member
There was a problem hiding this comment.
Could we use VarDumper on the $configuration var itself?
loic425
reviewed
Feb 2, 2026
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->hookablesRegistry = $this->createMock(HookablesRegistry::class); |
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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