X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/ff771ba0eca9e65b9cf6e06f50ff4e2b7d8da1ae..96196413bef5ffb4ec3e09770b4e6847090dd71e:/src/shpub/CurlPrinter.php diff --git a/src/shpub/CurlPrinter.php b/src/shpub/CurlPrinter.php new file mode 100644 index 0000000..cd2ccaa --- /dev/null +++ b/src/shpub/CurlPrinter.php @@ -0,0 +1,59 @@ +getMethod() != 'GET') { + $command .= ' -X ' . $httpReq->getMethod(); + } + foreach ($httpReq->getHeaders() as $key => $val) { + $caseKey = implode('-', array_map('ucfirst', explode('-', $key))); + $command .= ' -H ' . escapeshellarg($caseKey . ': ' . $val); + } + + $postParams = $httpReq->getPostParams(); + + if (count($uploadsInfo) == 0) { + foreach ($postParams as $k => $v) { + if (!is_array($v)) { + $command .= ' -d ' . escapeshellarg($k . '=' . $v); + } else { + foreach ($v as $ak => $av) { + $command .= ' -d ' . escapeshellarg( + $k . '[' . $ak . ']=' . $av + ); + } + } + } + } else { + foreach ($postParams as $k => $v) { + $command .= ' -F ' . escapeshellarg($k . '=' . $v); + } + foreach ($uploadsInfo as $fieldName => $fileName) { + if (!is_array($fileName)) { + $command .= ' -F ' . escapeshellarg( + $fieldName . '=@' . $fileName + ); + } else { + foreach ($fileName as $k => $realFilename) { + $command .= ' -F ' . escapeshellarg( + $fieldName . '[' . $k . ']=@' . $realFilename + ); + } + } + } + } + + if ($dedicatedBody) { + $command .= ' --data ' . escapeshellarg($httpReq->getBody()); + } + + $command .= ' ' . escapeshellarg((string) $httpReq->getUrl()); + + Log::msg($command); + } +} +?>