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
|
27 |
|
public static function instance() |
22
|
|
|
{ |
23
|
27 |
|
if (empty(self::$_instance)) { |
24
|
1 |
|
self::$_instance = new self(); |
25
|
|
|
} |
26
|
|
|
|
27
|
27 |
|
return self::$_instance; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// ---------------------------------------- |
31
|
|
|
|
32
|
24 |
|
public function fgets($handle, $length = null) |
33
|
|
|
{ |
34
|
24 |
|
if (isset($length)) { |
35
|
2 |
|
return fgets($handle, $length); |
36
|
|
|
} else { |
37
|
22 |
|
return fgets($handle); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
23 |
|
public function fsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null) |
42
|
|
|
{ |
43
|
23 |
|
return @fsockopen($hostname, $port, $errno, $errstr, $timeout); |
44
|
|
|
} |
45
|
|
|
|
46
|
4 |
|
public function pfsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null) |
47
|
|
|
{ |
48
|
4 |
|
return @pfsockopen($hostname, $port, $errno, $errstr, $timeout); |
49
|
|
|
} |
50
|
|
|
|
51
|
23 |
|
public function fwrite($handle, $string) |
52
|
|
|
{ |
53
|
23 |
|
return fwrite($handle, $string); |
54
|
|
|
} |
55
|
|
|
|
56
|
2 |
|
public function fclose($handle) |
57
|
|
|
{ |
58
|
2 |
|
fclose($handle); |
59
|
|
|
} |
60
|
|
|
|
61
|
25 |
|
public function stream_set_timeout($stream, $seconds, $microseconds = 0) |
|
|
|
|
62
|
|
|
{ |
63
|
25 |
|
return stream_set_timeout($stream, $seconds, $microseconds); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|