Completed
Push — master ( ae5192...7918b9 )
by Elf
03:26
created

usage.php ➔ dump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use ElfSundae\HttpClient;
4
5
require __DIR__.'/../vendor/autoload.php';
6
7
$client = new HttpClient('https://httpbin.org');
8
9
dump(__LINE__, $client->request('http://icanhazip.com')->getContent());
10
dump(__LINE__, (new HttpClient)->fetchContent('http://icanhazip.com'));
11
12
dump(__LINE__, $client->request('/ip')->getJson());
13
dump(__LINE__, $client->fetchJson('/ip'));
14
15
dump(__LINE__, $client->header('X-FOO', 'bar')->fetchJson('/headers'));
16
17
try {
18
    $client->withExceptions(true)->fetchContent('/status/418');
19
} catch (\Exception $e) {
20
    dump(__LINE__, $e->getCode(), $e->getMessage());
21
}
22
23
dump(__LINE__,
24
    (new HttpClient)
25
    ->formParams(['user' => 'Elf Sundae'])
26
    ->fetchJson('https://httpbin.org/post', 'POST')
27
);
28
29
dump(__LINE__, $client->saveTo(__DIR__.'/image.png')->request('/image/png')->getStatusCode());
30
31
// Options
32
$client->option('cookies', new \GuzzleHttp\Cookie\CookieJar())
33
    ->auth(['username', 'password'])
34
    ->cert('/path/server.pem')
35
    ->debug(true)
36
    ->httpErrors(false)
37
    ->progress(function () {
38
    })
39
    ->verify(false)
40
    ->version(2)
41
    ->acceptJson();
42
dump(__LINE__, $client->getOptions());
43
44
function dump($line, ...$data)
45
{
46
    usleep(300000);
47
    echo "====================  $line  ===========================".PHP_EOL;
48
    var_dump(...$data);
49
}
50