Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Kint Bundle Laravel Package

cg/kint-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require cg/kint-bundle
    

    Ensure Cg\KintBundle\CgKintBundle::class is registered in config/bundles.php under the dev environment.

  2. Enable in Dev Environment:

    # config/packages/dev/cg_kint.yaml
    cg_kint:
        enabled: true
    
  3. First Use Case: In any Twig template, replace {{ dump(var) }} with:

    {{ kint(user) }}
    

    Refresh the page to see a structured, collapsible dump of the user variable.


Implementation Patterns

Debugging Workflows

  1. Variable Inspection: Use {{ kint(variable) }} in templates to inspect objects, arrays, or complex data structures. Group related variables:

    {{ kint(user, request, app.container.get('service')) }}
    
  2. Conditional Debugging: Wrap Kint in Twig if blocks for environment-specific debugging:

    {% if app.environment == 'dev' %}
        {{ kint(form.vars.data) }}
    {% endif %}
    
  3. Controller Integration: Pass data from controllers to templates for debugging:

    // src/Controller/DebugController.php
    public function showDebug(DebugInterface $debugService)
    {
        return $this->render('debug/index.html.twig', [
            'debugData' => $debugService->getData(),
        ]);
    }
    
  4. Custom Twig Extensions: Extend Kint functionality by creating a custom Twig extension:

    // src/Twig/AppExtension.php
    public function getFunctions()
    {
        return [
            new \Twig\TwigFunction('custom_kint', [$this, 'customKintDump']),
        ];
    }
    
    public function customKintDump($var, $label = null)
    {
        return \Kint::dump($var, $label);
    }
    

    Register the extension in services.yaml:

    services:
        App\Twig\AppExtension:
            tags: ['twig.extension']
    

Gotchas and Tips

Pitfalls

  1. Performance Overhead:

    • Kint adds significant rendering time. Never use in production (disabled by default in non-dev environments).
    • Avoid dumping large datasets (e.g., {{ kint($allUsers) }} where $allUsers is a 10k-record collection).
  2. Twig Cache Conflicts:

    • Clear Twig cache after enabling/disabling Kint:
      php bin/console cache:clear
      
  3. Recursive Data Limits:

    • Kint truncates deeply nested structures (e.g., recursive arrays/objects) to prevent browser hangs. Adjust depth via config:
      cg_kint:
          max_depth: 5  # Default is 3
      
  4. Resource Handling:

    • Open file resources (e.g., fopen()) may display raw paths. Use kint() cautiously with untrusted data to avoid leaks.

Debugging Tips

  1. Filtering Output: Use Kint’s built-in filters for cleaner output:

    {{ kint(user|slice(0, 5)) }}  {# Show first 5 items of a collection #}
    
  2. Grouping Variables: Group related dumps for clarity:

    {{ kint([
        'User Data': user,
        'Request Data': request.attributes,
        'Session Data': app.session.all()
    ]) }}
    
  3. Command-Line Debugging: Combine with Symfony’s debug:container or debug:router for deeper inspection:

    php bin/console debug:container App\Service\DebugService
    
  4. Extension Points:

    • Override Kint’s default renderer by binding a custom Kint\Renderer\RendererInterface in services.yaml:
      services:
          App\Kint\CustomRenderer:
              tags: ['kint.renderer']
      
  5. Legacy Symfony Versions:

  6. Styling Conflicts:

    • Kint’s CSS may clash with your theme. Override styles in your base template:
      /* assets/css/kint-override.css */
      .kint-container { background: #f8f8f8; }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament