10
10
11
11
namespace Go \Instrument \Transformer ;
12
12
13
- use ArrayObject ;
14
13
use Go \Instrument \PathResolver ;
15
14
use InvalidArgumentException ;
16
15
17
16
/**
18
17
* Stream metadata object
19
- *
20
- * @property bool $timed_out TRUE if the stream timed out while waiting for data on the last call to fread() or fgets().
21
- * @property bool $blocked TRUE if the stream is in blocking IO mode
22
- * @property bool $eof TRUE if the stream has reached end-of-file.
23
- * @property int $unread_bytes The number of bytes currently contained in the PHP's own internal buffer.
24
- * @property string $stream_type A label describing the underlying implementation of the stream.
25
- * @property string $wrapper_type A label describing the protocol wrapper implementation layered over the stream.
26
- * @property mixed $wrapper_data Wrapper-specific data attached to this stream.
27
- * @property array $filters Array containing the names of any filters that have been stacked onto this stream.
28
- * @property string $mode The type of access required for this stream
29
- * @property bool $seekable Whether the current stream can be seeked.
30
- * @property string $uri The URI/filename associated with this stream.
31
- * @property string $source The contents of the stream.
32
18
*/
33
- class StreamMetaData extends ArrayObject
19
+ class StreamMetaData
34
20
{
21
+ /**
22
+ * Mapping between array keys and properties
23
+ *
24
+ * @var array
25
+ */
26
+ private static $ propertyMap = [
27
+ 'timed_out ' => 'isTimedOut ' ,
28
+ 'blocked ' => 'isBlocked ' ,
29
+ 'eof ' => 'isEOF ' ,
30
+ 'unread_bytes ' => 'unreadBytesCount ' ,
31
+ 'stream_type ' => 'streamType ' ,
32
+ 'wrapper_type ' => 'wrapperType ' ,
33
+ 'wrapper_data ' => 'wrapperData ' ,
34
+ 'filters ' => 'filterList ' ,
35
+ 'mode ' => 'mode ' ,
36
+ 'seekable ' => 'isSeekable ' ,
37
+ 'uri ' => 'uri ' ,
38
+ ];
39
+
40
+ /**
41
+ * TRUE if the stream timed out while waiting for data on the last call to fread() or fgets().
42
+ *
43
+ * @var bool
44
+ */
45
+ public $ isTimedOut ;
46
+
47
+ /**
48
+ * TRUE if the stream has reached end-of-file.
49
+ *
50
+ * @var bool
51
+ */
52
+ public $ isBlocked ;
53
+
54
+ /**
55
+ * TRUE if the stream has reached end-of-file.
56
+ *
57
+ * @var bool
58
+ */
59
+ public $ isEOF ;
60
+
61
+ /**
62
+ * The number of bytes currently contained in the PHP's own internal buffer.
63
+ *
64
+ * @var integer
65
+ */
66
+ public $ unreadBytesCount ;
67
+
68
+ /**
69
+ * A label describing the underlying implementation of the stream.
70
+ *
71
+ * @var string
72
+ */
73
+ public $ streamType ;
74
+
75
+ /**
76
+ * A label describing the protocol wrapper implementation layered over the stream.
77
+ *
78
+ * @var string
79
+ */
80
+ public $ wrapperType ;
81
+
82
+ /**
83
+ * Wrapper-specific data attached to this stream.
84
+ *
85
+ * @var mixed
86
+ */
87
+ public $ wrapperData ;
88
+
89
+ /**
90
+ * Array containing the names of any filters that have been stacked onto this stream.
91
+ *
92
+ * @var array
93
+ */
94
+ public $ filterList ;
95
+
96
+ /**
97
+ * The type of access required for this stream
98
+ *
99
+ * @var string
100
+ */
101
+ public $ mode ;
102
+
103
+ /**
104
+ * Whether the current stream can be seeked.
105
+ *
106
+ * @var bool
107
+ */
108
+ public $ isSeekable ;
109
+
110
+ /**
111
+ * The URI/filename associated with this stream.
112
+ *
113
+ * @var string
114
+ */
115
+ public $ uri ;
116
+
117
+ /**
118
+ * The contents of the stream.
119
+ *
120
+ * @var string
121
+ */
122
+ public $ source ;
123
+
35
124
/**
36
125
* Creates metadata object from stream
37
126
*
@@ -44,13 +133,14 @@ public function __construct($stream, $source = null)
44
133
if (!is_resource ($ stream )) {
45
134
throw new InvalidArgumentException ("Stream should be valid resource " );
46
135
}
47
- $ metadata = stream_get_meta_data ($ stream );
48
- if ($ source ) {
49
- $ metadata ['source ' ] = $ source ;
50
- }
136
+ $ metadata = stream_get_meta_data ($ stream );
137
+ $ this ->source = $ source ;
51
138
if (preg_match ('/resource=(.+)$/ ' , $ metadata ['uri ' ], $ matches )) {
52
139
$ metadata ['uri ' ] = PathResolver::realpath ($ matches [1 ]);
53
140
}
54
- parent ::__construct ($ metadata , ArrayObject::ARRAY_AS_PROPS );
141
+ foreach ($ metadata as $ key =>$ value ) {
142
+ $ mappedKey = self ::$ propertyMap [$ key ];
143
+ $ this ->$ mappedKey = $ value ;
144
+ }
55
145
}
56
146
}
0 commit comments