Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

adds new output format #279

Closed
wants to merge 1 commit into from

4 participants

@schmittjoh

The output of the ::dump method is very unstable (depends on platform/PHP version/installed extensions).

This pull request adds a new format which is more suitable for machine consumption.

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-456

@schmittjoh schmittjoh referenced this pull request in doctrine/doctrine2
Closed

adds a new output format #598

@Majkl578 Majkl578 commented on the diff
...Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php
((12 lines not shown))
- $output->write($message);
+ $output->write($message);
+ break;
+
+ case 'jms-serializer-json':
+ $serializer = SerializerBuilder::create()->build();
@Majkl578
Majkl578 added a note

This class is not part of DBAL. It's also not pulled by composer, since it's not in require or suggest sections. This will just fail if someone uses this.

You're right, this will fail when the library is not required as part of the root project's composer.json.

We should probably add it to the suggest section.

@stof
stof added a note

it should indeed be added in the suggest section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@schmittjoh

Closing as per discussion on the related PR.

@schmittjoh schmittjoh closed this
@schmittjoh schmittjoh deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2013
  1. @schmittjoh

    adds new output format

    schmittjoh authored
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 5 deletions.
  1. +19 −5 lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php
View
24 lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php
@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Tools\Console\Command;
+use JMS\Serializer\SerializerBuilder;
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
@@ -47,7 +48,8 @@ protected function configure()
->setDescription('Executes arbitrary SQL directly from the command line.')
->setDefinition(array(
new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'),
- new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7)
+ new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7),
+ new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format. Available: doctrine-debug (default), jms-serializer-json', 'doctrine-debug'),
))
->setHelp(<<<EOT
Executes arbitrary SQL directly from the command line.
@@ -78,10 +80,22 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$resultSet = $conn->executeUpdate($sql);
}
- ob_start();
- \Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth);
- $message = ob_get_clean();
+ switch ($input->getOption('format')) {
+ case 'doctrine-debug':
+ ob_start();
+ \Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth);
+ $message = ob_get_clean();
- $output->write($message);
+ $output->write($message);
+ break;
+
+ case 'jms-serializer-json':
+ $serializer = SerializerBuilder::create()->build();
@Majkl578
Majkl578 added a note

This class is not part of DBAL. It's also not pulled by composer, since it's not in require or suggest sections. This will just fail if someone uses this.

You're right, this will fail when the library is not required as part of the root project's composer.json.

We should probably add it to the suggest section.

@stof
stof added a note

it should indeed be added in the suggest section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $output->write($serializer->serialize($resultSet, 'json'));
+ break;
+
+ default:
+ throw new \LogicException(sprintf('The output format "%s" is unknown. Available: doctrine-debug, jms-serializer-json', $input->getOption('format')));
+ }
}
}
Something went wrong with that request. Please try again.