- $command = 'curl';
- if ($this->req->getMethod() != 'GET') {
- $command .= ' -X ' . $this->req->getMethod();
- }
- foreach ($this->req->getHeaders() as $key => $val) {
- $caseKey = implode('-', array_map('ucfirst', explode('-', $key)));
- $command .= ' -H ' . escapeshellarg($caseKey . ': ' . $val);
- }
-
- $postParams = $this->req->getPostParams();
-
- if (count($this->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 ($this->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 ($this->dedicatedBody) {
- $command .= ' --data ' . escapeshellarg($this->req->getBody());
- }
-
- $command .= ' ' . escapeshellarg((string) $this->req->getUrl());
-
- Log::msg($command);