| File: FileIterator53.php Lines 6 to 47 | 
 | 
6 |  * | 
 | 
7 |  * php-5.5以降であればGeneratorを使った方がパフォーマンスがよい。 | 
 | 
8 |  * 5.5.11以降であればSplFileObjectもバイナリファイルに対応されている。 | 
 | 
9 |  * | 
 | 
10 |  * @uses >= php-5.3 | 
 | 
11 |  * @version 0.1.0 | 
 | 
12 |  */ | 
 | 
13 | abstract class FileIterator53 implements \Iterator { | 
 | 
14 |     /** @var resource */ | 
 |  |     protected $fp; | 
 | 
16 |     /** @var scalar */ | 
 | 
17 |     protected $_key; | 
 | 
18 |     /** @var mixed */ | 
 | 
19 |     protected $buf; | 
 | 
20 |  | 
 | 
21 |     /** | 
 | 
22 |      * @param resource $fp | 
 | 
23 |      */ | 
 |  |     public function __construct($fp) { | 
 | 
25 |         if(!is_resource($fp)) { | 
 | 
26 |             throw new \InvalidArgumentException(); | 
 | 
27 |         } | 
 | 
28 |         $this->fp = $fp; | 
 | 
29 |     } | 
 | 
30 |  | 
 | 
31 |     /** | 
 | 
32 |      * @param string $fullpath | 
 | 
33 |      * @param string $mode | 
 | 
34 |      * @return static | 
 | 
35 |      */ | 
 | 
36 |     static public function createByPath($fullpath, $mode='rb') { | 
 |  |         $fp = @fopen($fullpath, $mode); | 
 | 
38 |         if(!is_resource($fp)) { | 
 | 
39 |             throw new \RuntimeException("cannot open stream: $fullpath"); | 
 | 
40 |         } | 
 | 
41 |         return new static($fp); | 
 | 
42 |     } | 
 | 
43 |  | 
 | 
44 |     public function __destruct() { | 
 | 
45 |         @fclose($this->fp); | 
 | 
46 |     } | 
 | 
47 |  | 
|   |