diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php
index 243804ccb546..0c188abcf386 100644
--- a/src/Symfony/Bridge/Twig/Command/LintCommand.php
+++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php
@@ -11,10 +11,6 @@
namespace Symfony\Bridge\Twig\Command;
-if (!defined('JSON_PRETTY_PRINT')) {
- define('JSON_PRETTY_PRINT', 128);
-}
-
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -40,7 +36,7 @@ public function __construct($name = 'twig:lint')
}
/**
- * Sets the twig environment
+ * Sets the twig environment.
*
* @param \Twig_Environment $twig
*/
@@ -98,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$filename) {
if (0 !== ftell(STDIN)) {
- throw new \RuntimeException("Please provide a filename or pipe template content to STDIN.");
+ throw new \RuntimeException('Please provide a filename or pipe template content to STDIN.');
}
$template = '';
@@ -190,7 +186,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
}
});
- $output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT));
+ $output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
return min($errors, 1);
}
@@ -200,14 +196,14 @@ private function renderException(OutputInterface $output, $template, \Twig_Error
$line = $exception->getTemplateLine();
if ($file) {
- $output->writeln(sprintf("KO in %s (line %s)", $file, $line));
+ $output->writeln(sprintf('KO in %s (line %s)', $file, $line));
} else {
- $output->writeln(sprintf("KO (line %s)", $line));
+ $output->writeln(sprintf('KO (line %s)', $line));
}
foreach ($this->getContext($template, $line) as $no => $code) {
$output->writeln(sprintf(
- "%s %-6s %s",
+ '%s %-6s %s',
$no == $line ? '>>' : ' ',
$no,
$code
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php
index 6565ef85bc84..9122dfb96e2f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php
@@ -11,10 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
-if (!defined('JSON_PRETTY_PRINT')) {
- define('JSON_PRETTY_PRINT', 128);
-}
-
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -156,7 +152,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
}
});
- $output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT));
+ $output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
return min($errors, 1);
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
index 3bd7633cf69d..17f1fa92f914 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
@@ -11,10 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
-if (!defined('JSON_PRETTY_PRINT')) {
- define('JSON_PRETTY_PRINT', 128);
-}
-
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
@@ -174,7 +170,13 @@ protected function describeContainerParameter($parameter, array $options = array
*/
private function writeData(array $data, array $options)
{
- $this->write(json_encode($data, (isset($options['json_encoding']) ? $options['json_encoding'] : 0) | JSON_PRETTY_PRINT)."\n");
+ $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
+
+ if (defined('JSON_PRETTY_PRINT')) {
+ $flags |= JSON_PRETTY_PRINT;
+ }
+
+ $this->write(json_encode($data, $flags)."\n");
}
/**
diff --git a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php
index fea7827498f0..7ad35184cd55 100644
--- a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php
+++ b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php
@@ -13,10 +13,6 @@
use Symfony\Component\Translation\MessageCatalogue;
-if (!defined('JSON_PRETTY_PRINT')) {
- define('JSON_PRETTY_PRINT', 128);
-}
-
/**
* JsonFileDumper generates an json formatted string representation of a message catalogue.
*
@@ -29,7 +25,7 @@ class JsonFileDumper extends FileDumper
*/
public function format(MessageCatalogue $messages, $domain = 'messages')
{
- return json_encode($messages->all($domain), JSON_PRETTY_PRINT);
+ return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0);
}
/**