diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php
index 243804ccb5..0c188abcf3 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 @@ class LintCommand extends Command
}
/**
- * Sets the twig environment
+ * Sets the twig environment.
*
* @param \Twig_Environment $twig
*/
@@ -98,7 +94,7 @@ EOF
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 @@ EOF
}
});
- $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 @@ EOF
$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 6565ef85bc..9122dfb96e 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 @@ EOF
}
});
- $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 3bd7633cf6..17f1fa92f9 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 @@ class JsonDescriptor extends Descriptor
*/
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 fea7827498..7ad35184cd 100644
--- a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php
+++ b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php
@@ -13,10 +13,6 @@ namespace Symfony\Component\Translation\Dumper;
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);
}
/**