I'm building a simple Symfony-shell script to test my Symfony app on interactive mode:
# bin/app_dev_cli.php
require __DIR__.'/../app/autoload.php';
$kernel = new AppKernel('dev', true);
// Initialize bundles and container
$kernel->boot();
// Useful global vars
$container = $kernel->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();
Later, opening PHP interactive mode and including the previous script I can do some tasks quickly:
/path/to/symfony/project$ php -a
Interactive mode enabled
# Booting the Symfony-shell app
php > require 'bin/app_dev_cli.php';
# Check if one service has been registered successfully
php > dump( $container->has('some_service') );
# Test some service
php > dump( $container->get('some_service')->run($param) );
# Manage some entities and DB data flow
php > $apple = new AppBundle\Entity\Fruit('Apple');
php > $em->persist($apple);
php > $em->flush();
php > dump( $em->getRepository('AppBundle\Entity\Fluit')->findAll() );
# etc.
The problem here is that the dump() function shows nothing. I was expecting a colored command line output, however I tried this with echo or var_dump() and it works, but for objects mainly the output is dense and unreadable. In this direction the VarDumper Component documentation says:
By default, the output format and destination are selected based on your current PHP SAPI [...] * On the command line (CLI SAPI), the output is written on STDOUT. [...]
That's not working for me by default and I'm sure that PHP_SAPI is cli. Besides, I found a workaround setting debug.dump_destination to php://stderr, BUT:
# php interactive mode:
php > dump("test");
hp shell code on line 1: // <---- show the code line always
"test"
I don't like this output and neither change the config for this purpose only.
Any thoughts what happens with the dump() function and why it shows nothing? Thanks.