Completed
Push — master ( 48fb97...1f3568 )
by Auke
03:18
created

http::serverRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
     * Returns a 
23
     */
24
    public static function serverRequest()
25
    {
26
        if (!\arc\context::$serverRequest) {
27
            \arc\context::$serverRequest = new http\serverRequest();
28
        }
29 2
        return \arc\context::$serverRequest;
30
    }
31 2
32
    /**
33 2
     * Send a HTTP request with a specific method, GET, POST, etc.
34
     * @param null  $method The method to use, GET, POST, etc.
35
     * @param null  $url    The URL to request
36
     * @param null  $query  The query string
37
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
38
     * @return string
39
     */
40
    public static function request( $method = null, $url = null, $query = null, $options = [] )
41 2
    {
42
        $client = new http\ClientStream();
43 2
44
        return $client->request( $method, $url, $query, $options );
45
    }
46
47
    /**
48
     * Create a new HTTP client with a default set of stream context options to use in all requests.
49
     * @param array $options Any of the HTTP stream context options, e.g. extra headers.
50
     * @return http\ClientStream
51
     */
52
    public static function client( $options = [] )
53 2
    {
54
        return new http\ClientStream( $options );
55 2
    }
56
57
    /**
58
     * Do a HTTP GET request and return the response.
59
     * @param       $url    The URL to request
60
     * @param mixed  $query  The query parameters
61
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
62
     * @return string
63
     */
64
    public static function get( $url, $query = null, $options = [] )
65
    {
66
        return self::request( 'GET', $url, $query, $options);
67
    }
68
69
    /**
70
     * Do a HTTP POST request and return the response.
71
     * @param       $url    The URL to request
72
     * @param mixed  $query  The query parameters
73
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
74
     * @return string
75
     */
76
    public static function post( $url, $query = null, $options = [] )
77
    {
78
        return self::request( 'POST', $url, $query, $options);
79
    }
80
81
    /**
82
     * Do a HTTP PUT 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
     */
87
    public static function put( $url, $query = null, $options = [] )
88
    {
89
        return self::request( 'PUT', $url, $query, $options);
90
    }
91
92
    /**
93
     * Do a HTTP DELETE request and return the response.
94
     * @param       $url    The URL to request
95
     * @param mixed  $query  The query parameters
96
     * @param array $options    Any of the HTTP stream context options, e.g. extra headers.
97
     * @return string
98
     */
99
    public static function delete( $url, $query = null, $options = [] )
100
    {
101
        return self::request( 'DELETE', $url, $query, $options);
102
    }
103
}
104