Skip to content

Conversation

@camilleislasse
Copy link

Summary

Add sylius:debug:twig-hooks console command to list and inspect Twig hooks configuration.

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 with status column
  • --config option to display hookable configuration
  • Shell autocompletion for hook names

Usage

# List all hooks                                                                                                                                                               
bin/console sylius:debug:twig-hooks                                                                                                                                            
                                                                                                                                                                               
# Filter by name                                                                                                                                                               
bin/console sylius:debug:twig-hooks sylius_admin                                                                                                                               
                                                                                                                                                                               
# Show details for a specific hook                                                                                                                                             
bin/console sylius:debug:twig-hooks sylius_admin.common.component.sidebar                                                                                                      
                                                                                                                                                                               
# Include disabled hookables                                                                                                                                                   
bin/console sylius:debug:twig-hooks sylius_admin.common.component.sidebar --all                                                                                                
                                                                                                                                                                               
# Show configuration                                                                                                                                                           
bin/console sylius:debug:twig-hooks sylius_admin.common.component.sidebar --config                                                                                             

Changes

  • Add DebugTwigHooksCommand class
  • Add getHookNames() and getAllFor() methods to HookablesRegistry
  • Register command as service

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) . ']';
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants