1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pheanstalk\Socket; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Wrapper around PHP stream functions. |
7
|
|
|
* |
8
|
|
|
* Facilitates mocking/stubbing stream operations in unit tests. |
9
|
|
|
* |
10
|
|
|
* @author Paul Annesley |
11
|
|
|
* @package Pheanstalk |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
13
|
|
|
*/ |
14
|
|
|
class StreamFunctions |
15
|
|
|
{ |
16
|
|
|
private static $_instance; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Singleton accessor. |
20
|
|
|
*/ |
21
|
24 |
|
public static function instance() |
22
|
|
|
{ |
23
|
24 |
|
if (empty(self::$_instance)) { |
24
|
1 |
|
self::$_instance = new self(); |
25
|
|
|
} |
26
|
|
|
|
27
|
24 |
|
return self::$_instance; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// ---------------------------------------- |
31
|
|
|
|
32
|
|
|
public function feof($handle) |
33
|
|
|
{ |
34
|
|
|
return feof($handle); |
35
|
|
|
} |
36
|
|
|
|
37
|
22 |
|
public function fgets($handle, $length = null) |
38
|
|
|
{ |
39
|
22 |
|
if (isset($length)) { |
40
|
|
|
return fgets($handle, $length); |
41
|
|
|
} else { |
42
|
22 |
|
return fgets($handle); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function fopen($filename, $mode) |
47
|
|
|
{ |
48
|
|
|
return fopen($filename, $mode); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function fread($handle, $length) |
52
|
|
|
{ |
53
|
|
|
return fread($handle, $length); |
54
|
|
|
} |
55
|
|
|
|
56
|
23 |
|
public function fsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null) |
57
|
|
|
{ |
58
|
23 |
|
return @fsockopen($hostname, $port, $errno, $errstr, $timeout); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function pfsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null) |
62
|
|
|
{ |
63
|
1 |
|
return @pfsockopen($hostname, $port, $errno, $errstr, $timeout); |
64
|
|
|
} |
65
|
|
|
|
66
|
22 |
|
public function fwrite($handle, $string, $length = null) |
67
|
|
|
{ |
68
|
22 |
|
if (isset($length)) { |
69
|
|
|
return fwrite($handle, $string, $length); |
70
|
|
|
} else { |
71
|
22 |
|
return fwrite($handle, $string); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
public function fclose($handle) |
76
|
|
|
{ |
77
|
1 |
|
fclose($handle); |
78
|
|
|
} |
79
|
|
|
|
80
|
22 |
|
public function stream_set_timeout($stream, $seconds, $microseconds = 0) |
|
|
|
|
81
|
|
|
{ |
82
|
22 |
|
return stream_set_timeout($stream, $seconds, $microseconds); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|