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 */
13abstract class FileIterator53 implements \Iterator {
14    /** @var resource */
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
15
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
    protected $fp;
16    /** @var scalar */
17    protected $_key;
18    /** @var mixed */
19    protected $buf;
20
21    /**
22     * @param resource $fp
23     */
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
24
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
    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') {
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
37
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
        $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