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

Dumper Bundle Laravel Package

dualhand/dumper-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dualhand/dumper-bundle
    

    Ensure your project uses Symfony 2.x and SonataAdminBundle 2.x (required dependencies).

  2. Enable the Bundle: Add to app/AppKernel.php:

    new Dualhand\DumperBundle\DumperBundle(),
    
  3. First Use Case: In a Twig template, dump an object’s SonataAdmin-exposed properties with:

    {{ prop(your_object) }}
    
    • Outputs only fields defined in the associated SonataAdmin class (ignores unused parent properties).

Implementation Patterns

Core Workflows

  1. Debugging Admin-Exposed Fields:

    • Use {{ prop($post) }} in a SonataAdmin template to inspect only the fields actively used in the admin panel.
    • Example: Debug why a field isn’t rendering in the admin UI.
  2. Translatable Properties:

    • Automatically detects and dumps translatable fields (e.g., translatable: true in YAML config).
    • Useful for verifying translations in templates:
      {{ prop($product, 'translatable') }}
      
  3. Frontend Integration:

    • Pass objects to Twig and dump their full property structure (including non-admin fields) with:
      {{ prop($object, 'all') }}
      
    • Ideal for frontend devs to inspect data before rendering.
  4. Service Integration:

    • Access the dumper in PHP code via the dumper service:
      $dumper = $this->get('dumper');
      $dumper->dump($object); // Returns filtered properties
      
    • Useful in controllers or services for logging/debugging.

Integration Tips

  • SonataAdmin Dependency:

    • The bundle only works with objects managed by SonataAdmin. Ensure your model has a corresponding Admin class (e.g., PostAdmin for Post entity).
    • Example PostAdmin:
      # src/AppBundle/Admin/PostAdmin.yml
      fields:
        - { property: 'title', type: 'text' }
        - { property: 'content', type: 'tinymce' }
      
  • Twig Extensions:

    • The prop filter is Twig-only. For CLI debugging, use the service directly or extend the bundle.
  • Performance:

    • Avoid dumping large objects in production. Use environment checks:
      {% if app.environment == 'dev' %}
          {{ prop($object) }}
      {% endif %}
      

Gotchas and Tips

Pitfalls

  1. No Symfony 3+ Support:

  2. SonataAdmin Required:

    • Fails silently if the object isn’t managed by SonataAdmin. Verify with:
      if (!$this->get('sonata.admin.registry')->getAdminClass($object)) {
          throw new \RuntimeException('Object not registered in SonataAdmin!');
      }
      
  3. Translatable Field Detection:

    • Relies on Sonata’s translatable: true config. If fields aren’t detected:
      • Check your config.yml or Admin class for proper configuration.
      • Manually specify translatable fields in the dumper’s service config (if extended).
  4. Circular References:

    • Deep dumping (prop($object, 'all')) may cause infinite loops with circular references. Use maxDepth in custom extensions:
      $dumper->setMaxDepth(3); // Limit recursion
      

Debugging Tips

  1. Inspect Admin Configuration:

    • Dump the SonataAdmin’s field list to verify expected properties:
      $admin = $this->get('sonata.admin.registry')->getAdminClass($object);
      dump($admin->getFormMapper()->getFormBuilder()->getConfig()->getDataClass());
      
  2. Override Dumper Behavior:

    • Extend the dumper service to add custom logic (e.g., filter specific fields):
      # app/config/services.yml
      services:
          app.custom_dumper:
              class: Dualhand\DumperBundle\Service\Dumper
              arguments:
                  - '@sonata.admin.registry'
                  - ['exclude_field'] # Custom filter
      
  3. Twig Debugging:

    • Use {{ dump(_context) }} to inspect the Twig environment if prop fails.
    • Check for typos in the filter name (prop is case-sensitive).

Extension Points

  1. Custom Filters:

    • Extend the dumper to support additional filters (e.g., prop($object, 'relations')):
      // src/AppBundle/Dumper/DumperExtension.php
      namespace AppBundle\Dumper;
      
      use Dualhand\DumperBundle\Service\Dumper as BaseDumper;
      
      class DumperExtension extends BaseDumper {
          public function dumpRelations($object) {
              // Custom logic
          }
      }
      
  2. Add to SonataAdmin:

    • Integrate the dumper into SonataAdmin’s debug toolbar or action:
      // src/AppBundle/Admin/PostAdmin.php
      protected function configureListFields(ListMapper $listMapper) {
          $listMapper->add('debug', 'string', [
              'template' => '@Dumper/dumper.html.twig',
              'data' => function ($object) {
                  return $this->get('dumper')->dump($object);
              }
          ]);
      }
      
  3. CLI Usage:

    • Create a custom command to dump objects outside Twig:
      // src/AppBundle/Command/DumpObjectCommand.php
      namespace AppBundle\Command;
      
      use Symfony\Component\Console\Command\Command;
      use Symfony\Component\Console\Input\InputInterface;
      use Symfony\Component\Console\Output\OutputInterface;
      
      class DumpObjectCommand extends Command {
          protected function execute(InputInterface $input, OutputInterface $output) {
              $object = $this->getDoctrine()->getRepository('AppBundle:Post')->find(1);
              $output->writeln($this->get('dumper')->dump($object));
          }
      }
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware