|
20 | 20 | */
|
21 | 21 | class SplCaster
|
22 | 22 | {
|
| 23 | + private static $splFileObjectFlags = array( |
| 24 | + \SplFileObject::DROP_NEW_LINE => 'DROP_NEW_LINE', |
| 25 | + \SplFileObject::READ_AHEAD => 'READ_AHEAD', |
| 26 | + \SplFileObject::SKIP_EMPTY => 'SKIP_EMPTY', |
| 27 | + \SplFileObject::READ_CSV => 'READ_CSV', |
| 28 | + ); |
| 29 | + |
23 | 30 | public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested)
|
24 | 31 | {
|
25 | 32 | $prefix = Caster::PREFIX_VIRTUAL;
|
@@ -122,6 +129,55 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
|
122 | 129 | return $a;
|
123 | 130 | }
|
124 | 131 |
|
| 132 | + public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested) |
| 133 | + { |
| 134 | + static $map = array( |
| 135 | + 'csvControl' => 'getCsvControl', |
| 136 | + 'flags' => 'getFlags', |
| 137 | + 'maxLineLen' => 'getMaxLineLen', |
| 138 | + 'fstat' => 'fstat', |
| 139 | + 'eof' => 'eof', |
| 140 | + 'key' => 'key', |
| 141 | + ); |
| 142 | + |
| 143 | + $prefix = Caster::PREFIX_VIRTUAL; |
| 144 | + |
| 145 | + foreach ($map as $key => $accessor) { |
| 146 | + try { |
| 147 | + $a[$prefix.$key] = $c->$accessor(); |
| 148 | + } catch (\Exception $e) { |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + if (isset($a[$prefix.'flags'])) { |
| 153 | + $flagsArray = array(); |
| 154 | + foreach (self::$splFileObjectFlags as $value => $name) { |
| 155 | + if ($a[$prefix.'flags'] & $value) { |
| 156 | + $flagsArray[] = $name; |
| 157 | + } |
| 158 | + } |
| 159 | + $a[$prefix.'flags'] = new ConstStub(implode('|', $flagsArray), $a[$prefix.'flags']); |
| 160 | + } |
| 161 | + |
| 162 | + |
| 163 | + if (isset($a[$prefix.'fstat'])) { |
| 164 | + $fstat = $a[$prefix.'fstat']; |
| 165 | + $fstat = array( |
| 166 | + 'dev' => $fstat['dev'], |
| 167 | + 'ino' => $fstat['ino'], |
| 168 | + 'nlink' => $fstat['nlink'], |
| 169 | + 'rdev' => $fstat['rdev'], |
| 170 | + 'blksize' => $fstat['blksize'], |
| 171 | + 'blocks' => $fstat['blocks'], |
| 172 | + '…' => '…'.(count($fstat) - 6), |
| 173 | + ); |
| 174 | + |
| 175 | + $a[$prefix.'fstat'] = $fstat; |
| 176 | + } |
| 177 | + |
| 178 | + return $a; |
| 179 | + } |
| 180 | + |
125 | 181 | public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
|
126 | 182 | {
|
127 | 183 | $a += array(
|
|
0 commit comments