Installation:
composer require dualhand/dumper-bundle
Ensure your project uses Symfony 2.x and SonataAdminBundle 2.x (required dependencies).
Enable the Bundle:
Add to app/AppKernel.php:
new Dualhand\DumperBundle\DumperBundle(),
First Use Case: In a Twig template, dump an object’s SonataAdmin-exposed properties with:
{{ prop(your_object) }}
SonataAdmin class (ignores unused parent properties).Debugging Admin-Exposed Fields:
{{ prop($post) }} in a SonataAdmin template to inspect only the fields actively used in the admin panel.Translatable Properties:
translatable: true in YAML config).{{ prop($product, 'translatable') }}
Frontend Integration:
{{ prop($object, 'all') }}
Service Integration:
dumper service:
$dumper = $this->get('dumper');
$dumper->dump($object); // Returns filtered properties
SonataAdmin Dependency:
Admin class (e.g., PostAdmin for Post entity).PostAdmin:
# src/AppBundle/Admin/PostAdmin.yml
fields:
- { property: 'title', type: 'text' }
- { property: 'content', type: 'tinymce' }
Twig Extensions:
prop filter is Twig-only. For CLI debugging, use the service directly or extend the bundle.Performance:
{% if app.environment == 'dev' %}
{{ prop($object) }}
{% endif %}
No Symfony 3+ Support:
symfony/var-dumper for general debugging.stof/doctrine-extensions for translatable fields.SonataAdmin Required:
if (!$this->get('sonata.admin.registry')->getAdminClass($object)) {
throw new \RuntimeException('Object not registered in SonataAdmin!');
}
Translatable Field Detection:
translatable: true config. If fields aren’t detected:
config.yml or Admin class for proper configuration.Circular References:
prop($object, 'all')) may cause infinite loops with circular references. Use maxDepth in custom extensions:
$dumper->setMaxDepth(3); // Limit recursion
Inspect Admin Configuration:
$admin = $this->get('sonata.admin.registry')->getAdminClass($object);
dump($admin->getFormMapper()->getFormBuilder()->getConfig()->getDataClass());
Override Dumper Behavior:
# app/config/services.yml
services:
app.custom_dumper:
class: Dualhand\DumperBundle\Service\Dumper
arguments:
- '@sonata.admin.registry'
- ['exclude_field'] # Custom filter
Twig Debugging:
{{ dump(_context) }} to inspect the Twig environment if prop fails.prop is case-sensitive).Custom Filters:
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
}
}
Add to SonataAdmin:
// 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);
}
]);
}
CLI Usage:
// 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));
}
}
How can I help you explore Laravel packages today?