Completed
Push — master ( cee824...b1d97d )
by Robbert
06:12 queued 02:02
created

http::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 6
Bugs 1 Features 1
Metric Value
c 6
b 1
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc;
13
14
/**
15
 * Class http
16
 * Basic HTTP client.
17
 * @package arc
18
 */
19
final class http
20
{
21
    /**
22
     * Send a HTTP request with a specific method, GET, POST, etc.
23
     * @param null  $method The method to use, GET, POST, etc.
24
     * @param null  $url    The URL to request
25
     * @param null  $query  The query string
26
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
27
     * @return string
28
     */
29 1
    public static function request( $method = null, $url = null, $query = null, $options = [] )
30
    {
31 1
        $client = new http\ClientStream();
32
33 1
        return $client->request( $method, $url, $query, $options );
34
    }
35
36
    /**
37
     * Create a new HTTP client with a default set of stream context options to use in all requests.
38
     * @param array $options Any of the HTTP stream context options, e.g. extra headers.
39
     * @return http\ClientStream
40
     */
41 1
    public static function client( $options = [] )
42
    {
43 1
        return new http\ClientStream( $options );
44
    }
45
46
    /**
47
     * Do a HTTP GET request and return the response.
48
     * @param       $url    The URL to request
49
     * @param mixed  $query  The query parameters
50
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
51
     * @return string
52
     */
53 1
    public static function get( $url, $query = null, $options = [] )
54
    {
55 1
        return self::request( 'GET', $url, $query, $options);
56
    }
57
58
    /**
59
     * Do a HTTP POST request and return the response.
60
     * @param       $url    The URL to request
61
     * @param mixed  $query  The query parameters
62
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
63
     * @return string
64
     */
65
    public static function post( $url, $query = null, $options = [] )
66
    {
67
        return self::request( 'POST', $url, $query, $options);
68
    }
69
70
    /**
71
     * Do a HTTP PUT request and return the response.
72
     * @param       $url    The URL to request
73
     * @param mixed  $query  The query parameters
74
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
75
     */
76
    public static function put( $url, $query = null, $options = [] )
77
    {
78
        return self::request( 'PUT', $url, $query, $options);
79
    }
80
81
    /**
82
     * Do a HTTP DELETE request and return the response.
83
     * @param       $url    The URL to request
84
     * @param mixed  $query  The query parameters
85
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
86
     * @return string
87
     */
88
    public static function delete( $url, $query = null, $options = [] )
89
    {
90
        return self::request( 'DELETE', $url, $query, $options);
91
    }
92
}
93