Skip to content

Commit 74ba114

Browse files
dostenfabpot
authored andcommitted
Do not override PHP constants, only use when available
1 parent bc6d53b commit 74ba114

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Command/YamlLintCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14-
if (!defined('JSON_PRETTY_PRINT')) {
15-
define('JSON_PRETTY_PRINT', 128);
16-
}
17-
1814
use Symfony\Component\Console\Command\Command;
1915
use Symfony\Component\Console\Input\InputInterface;
2016
use Symfony\Component\Console\Input\InputOption;
@@ -156,7 +152,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
156152
}
157153
});
158154

159-
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT));
155+
$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
160156

161157
return min($errors, 1);
162158
}

Console/Descriptor/JsonDescriptor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

14-
if (!defined('JSON_PRETTY_PRINT')) {
15-
define('JSON_PRETTY_PRINT', 128);
16-
}
17-
1814
use Symfony\Component\DependencyInjection\Alias;
1915
use Symfony\Component\DependencyInjection\ContainerBuilder;
2016
use Symfony\Component\DependencyInjection\Definition;
@@ -174,7 +170,13 @@ protected function describeContainerParameter($parameter, array $options = array
174170
*/
175171
private function writeData(array $data, array $options)
176172
{
177-
$this->write(json_encode($data, (isset($options['json_encoding']) ? $options['json_encoding'] : 0) | JSON_PRETTY_PRINT)."\n");
173+
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
174+
175+
if (defined('JSON_PRETTY_PRINT')) {
176+
$flags |= JSON_PRETTY_PRINT;
177+
}
178+
179+
$this->write(json_encode($data, $flags)."\n");
178180
}
179181

180182
/**

0 commit comments

Comments
 (0)