Skip to content

Commit 4b12625

Browse files
committed
Allow use of --json option with lower curl versions
1 parent 85d10da commit 4b12625

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Service/CurlCli.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,22 @@ public function run($baseUrl, InputInterface $input, OutputInterface $output) {
6767
}
6868
}
6969

70-
$singleValueOptions = ['request', 'json', 'data'];
71-
foreach ($singleValueOptions as $valueOption) {
72-
if ($value = $input->getOption($valueOption)) {
73-
$commandline .= ' --' . $valueOption . ' ' . escapeshellarg($value);
70+
if ($requestMethod = $input->getOption('request')) {
71+
$commandline .= ' --request ' . escapeshellarg($requestMethod);
72+
}
73+
74+
if ($data = $input->getOption('json')) {
75+
if (\json_decode($data) === null && \json_last_error() !== JSON_ERROR_NONE) {
76+
$stdErr->writeln('The value of --json contains invalid JSON.');
77+
return 1;
7478
}
79+
$commandline .= ' --data ' . escapeshellarg($data);
80+
$commandline .= ' --header ' . escapeshellarg('Content-Type: application/json');
81+
$commandline .= ' --header ' . escapeshellarg('Accept: application/json');
82+
}
83+
84+
if ($data = $input->getOption('data')) {
85+
$commandline .= ' --data ' . escapeshellarg($data);
7586
}
7687

7788
if (!$input->getOption('disable-compression')) {

0 commit comments

Comments
 (0)