forked from laravel-shift/curl-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurlCommand.php
46 lines (38 loc) · 1.72 KB
/
CurlCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Shift\CurlConverter\Console\Commands;
use Illuminate\Console\Command;
use Shift\CurlConverter\Support\HttpCall;
class CurlCommand extends Command
{
protected $signature = 'shift:curl {--X|request=} {--G|get} {--H|header=*} {--d|data=*} {--data-raw=*} {--data-urlencode=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--max-timeout=} {--retry=} {--s|silent} {--u|user=} {--L|location} {--compressed} {--insecure} {url}';
protected $description = 'Convert a UNIX curl request to an HTTP Client request';
public function handle()
{
$request = \Shift\CurlConverter\Models\Request::create($this->gatherOptions());
$code = HttpCall::format($request);
$this->newLine();
$this->line($code);
$this->newLine();
return 0;
}
private function gatherOptions()
{
return [
'method' => $this->option('get') ? 'GET' : $this->option('request'),
'url' => $this->argument('url'),
'headers' => $this->option('header'),
'data' => count($this->option('data-raw')) > 0 ? $this->option('data-raw') : $this->option('data'),
'dataUrlEncode' => $this->option('data-urlencode'),
'fields' => $this->option('form'),
'digest' => $this->option('digest'),
'basic' => $this->option('basic'),
'connectTimeout' => $this->option('connect-timeout'),
'maxTimeout' => $this->option('max-timeout'),
'retry' => $this->option('retry'),
'silent' => $this->option('silent'),
'user' => $this->option('user'),
'compressed' => $this->option('compressed'),
'insecure' => $this->option('insecure'),
];
}
}