/
StreamWrapper.php
109 lines (93 loc) · 2.11 KB
/
StreamWrapper.php
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
/**
* This file is part of the bakame.psr7-csv-factory library
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/bakame-php/psr7-csv-factory
* @version 1.0.0
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace LeagueTest\Csv;
final class StreamWrapper
{
const PROTOCOL = 'leaguetest';
public $context;
private $stream;
public static function register()
{
if (!in_array(self::PROTOCOL, stream_get_wrappers(), true)) {
stream_wrapper_register(self::PROTOCOL, __CLASS__);
}
}
/**
* {@inheritdoc}
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
$options = stream_context_get_options($this->context);
if (!isset($options[self::PROTOCOL]['stream'])) {
return false;
}
$this->stream = $options[self::PROTOCOL]['stream'];
return true;
}
/**
* {@inheritdoc}
*/
public function stream_read($count)
{
return fread($this->stream, $count);
}
/**
* {@inheritdoc}
*/
public function stream_write($data)
{
return fwrite($this->stream, $data);
}
/**
* {@inheritdoc}
*/
public function stream_tell()
{
return ftell($this->stream);
}
/**
* {@inheritdoc}
*/
public function stream_eof()
{
return feof($this->stream);
}
/**
* {@inheritdoc}
*/
public function stream_seek($offset, $whence)
{
fseek($this->stream, $whence);
return true;
}
/**
* {@inheritdoc}
*/
public function stream_stat()
{
return [
'dev' => 0,
'ino' => 0,
'mode' => 33206,
'nlink' => 0,
'uid' => 0,
'gid' => 0,
'rdev' => 0,
'size' => 0,
'atime' => 0,
'mtime' => 0,
'ctime' => 0,
'blksize' => 0,
'blocks' => 0,
];
}
}