forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseStream.php
More file actions
109 lines (97 loc) · 2.07 KB
/
Copy pathParseStream.php
File metadata and controls
109 lines (97 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Class ParseStream | Parse/HttpClients/ParseStream.php
*/
namespace Parse\HttpClients;
/**
* Class ParseStream - Wrapper for abstracted stream usage
*
* @author Ben Friedman <friedman.benjamin@gmail.com>
* @package Parse\HttpClients
*/
class ParseStream
{
/**
* Stream context
*
* @var resource
*/
private $stream;
/**
* Response headers
*
* @var array|null
*/
private $responseHeaders;
/**
* Error message
*
* @var string
*/
private $errorMessage;
/**
* Error code
*
* @var int
*/
private $errorCode;
/**
* Create a stream context
*
* @param array $options Options to pass to our context
*/
public function createContext($options)
{
$this->stream = stream_context_create($options);
}
/**
* Gets the contents from the given url
*
* @param string $url Url to get contents of
* @return string
*/
public function get($url)
{
try {
// get our response
$response = file_get_contents($url, false, $this->stream);
$this->errorMessage = null;
$this->errorCode = null;
} catch (\Exception $e) {
// set our error message/code and return false
$this->errorMessage = $e->getMessage();
$this->errorCode = $e->getCode();
return false;
}
// set response headers
$this->responseHeaders = $http_response_header;
return $response;
}
/**
* Returns the response headers for the last request
*
* @return array
*/
public function getResponseHeaders()
{
return $this->responseHeaders;
}
/**
* Gets the current error message
*
* @return string
*/
public function getErrorMessage()
{
return $this->errorMessage;
}
/**
* Gest the current error code
*
* @return int
*/
public function getErrorCode()
{
return $this->errorCode;
}
}