Completed
Push — master ( ae6482...598fcc )
by Mark
01:22
created

Xhgui_Saver_Upload::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
class Xhgui_Saver_Upload implements Xhgui_Saver_Interface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    protected $uri;
7
8
    public function __construct($uri)
9
    {
10
        $this->uri = $uri;
11
    }
12
13
    public function save($data)
14
    {
15
        $json = json_encode($data);
16
17
        $ch = curl_init($this->uri);
18
19
        $headers = array(
20
            'Accept: application/json',         // Prefer to receive JSON back
21
            'Content-Type: application/json'    // The sent data is JSON
22
        );
23
24
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
25
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
26
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
27
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
28
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
29
30
        curl_exec($ch);
31
32
        curl_close($ch);
33
    }
34
}
35