Xhgui_Saver_Upload::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
class Xhgui_Saver_Upload implements Xhgui_Saver_Interface
4
{
5
6
    protected $uri, $timeout;
7
8
    public function __construct($uri, $timeout)
9
    {
10
        $this->uri = $uri;
11
        $this->timeout = $timeout;
12
    }
13
14
    public function save(array $data)
15
    {
16
        $json = json_encode($data);
17
18
        $ch = curl_init($this->uri);
19
20
        $headers = array(
21
            'Accept: application/json',         // Prefer to receive JSON back
22
            'Content-Type: application/json'    // The sent data is JSON
23
        );
24
25
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
26
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
27
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
28
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
29
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
30
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
31
32
        curl_exec($ch);
33
34
        curl_close($ch);
35
    }
36
}
37