ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
AMFReader.php
Go to the documentation of this file.
1<?php
2
4
7// available at http://getid3.sourceforge.net //
8// or http://www.getid3.org //
9// //
10// AMFReader //
11// by Seth Kaufman <seth@whirl-i-gig.com> //
12// //
14// //
15// dependencies: None //
16// ///
18
28{
29 public $stream;
30
35 public function __construct(&$stream)
36 {
37 $this->stream = & $stream;
38 }
39
44 public function readData()
45 {
46 $value = null;
47
48 $type = $this->stream->readByte();
49 switch ($type) {
50
51 // Double
52 case 0:
53 $value = $this->readDouble();
54 break;
55
56 // Boolean
57 case 1:
58 $value = $this->readBoolean();
59 break;
60
61 // String
62 case 2:
63 $value = $this->readString();
64 break;
65
66 // Object
67 case 3:
68 $value = $this->readObject();
69 break;
70
71 // null
72 case 6:
73 return null;
74 break;
75
76 // Mixed array
77 case 8:
78 $value = $this->readMixedArray();
79 break;
80
81 // Array
82 case 10:
83 $value = $this->readArray();
84 break;
85
86 // Date
87 case 11:
88 $value = $this->readDate();
89 break;
90
91 // Long string
92 case 13:
93 $value = $this->readLongString();
94 break;
95
96 // XML (handled as string)
97 case 15:
98 $value = $this->readXML();
99 break;
100
101 // Typed object (handled as object)
102 case 16:
103 $value = $this->readTypedObject();
104 break;
105
106 // Long string
107 default:
108 $value = '(unknown or unsupported data type)';
109 break;
110 }
111
112 return $value;
113 }
114
119 public function readDouble()
120 {
121 return $this->stream->readDouble();
122 }
123
128 public function readBoolean()
129 {
130 return $this->stream->readByte() == 1;
131 }
132
137 public function readString()
138 {
139 return $this->stream->readUTF();
140 }
141
146 public function readObject()
147 {
148 // Get highest numerical index - ignored
149// $highestIndex = $this->stream->readLong();
150
151 $data = array();
152
153 while ($key = $this->stream->readUTF()) {
154 $data[$key] = $this->readData();
155 }
156 // Mixed array record ends with empty string (0x00 0x00) and 0x09
157 if (($key == '') && ($this->stream->peekByte() == 0x09)) {
158 // Consume byte
159 $this->stream->readByte();
160 }
161
162 return $data;
163 }
164
169 public function readMixedArray()
170 {
171 // Get highest numerical index - ignored
172 $highestIndex = $this->stream->readLong();
173
174 $data = array();
175
176 while ($key = $this->stream->readUTF()) {
177 if (is_numeric($key)) {
178 $key = (float) $key;
179 }
180 $data[$key] = $this->readData();
181 }
182 // Mixed array record ends with empty string (0x00 0x00) and 0x09
183 if (($key == '') && ($this->stream->peekByte() == 0x09)) {
184 // Consume byte
185 $this->stream->readByte();
186 }
187
188 return $data;
189 }
190
195 public function readArray()
196 {
197 $length = $this->stream->readLong();
198 $data = array();
199
200 for ($i = 0; $i < $length; $i++) {
201 $data[] = $this->readData();
202 }
203
204 return $data;
205 }
206
211 public function readDate()
212 {
213 $timestamp = $this->stream->readDouble();
214 $timezone = $this->stream->readInt();
215
216 return $timestamp;
217 }
218
223 public function readLongString()
224 {
225 return $this->stream->readLongUTF();
226 }
227
232 public function readXML()
233 {
234 return $this->stream->readLongUTF();
235 }
236
241 public function readTypedObject()
242 {
243 $className = $this->stream->readUTF();
244
245 return $this->readObject();
246 }
247}
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: AMFReader.php:28