POMO_FileReader
云策文档标注
概述
POMO_FileReader 是 WordPress 中用于处理文件读取的类,继承自 POMO_Reader,主要用于国际化(i18n)相关功能。它提供了一系列方法来操作文件指针,如读取、定位和关闭文件。
关键要点
- POMO_FileReader 继承自 POMO_Reader,用于文件读取操作。
- 类中包含文件指针资源属性 $_f,用于存储打开的文件句柄。
- 主要方法包括 __construct(构造函数)、read(读取指定字节)、seekto(定位文件指针)、is_resource(检查资源)、feof(检查文件结束)、close(关闭文件)和 read_all(读取全部内容)。
- PHP4 构造函数 POMO_FileReader 已弃用,建议使用 __construct 替代。
- 类位于 wp-includes/pomo/streams.php 文件中,与 POMO_Reader 相关。
原文内容
Methods
| Name | Description |
|---|---|
| POMO_FileReader::__construct | – |
| POMO_FileReader::close | – |
| POMO_FileReader::feof | – |
| POMO_FileReader::is_resource | – |
| POMO_FileReader::POMO_FileReader | PHP4 constructor. — deprecated |
| POMO_FileReader::read | – |
| POMO_FileReader::read_all | – |
| POMO_FileReader::seekto | – |
Source
class POMO_FileReader extends POMO_Reader {
/**
* File pointer resource.
*
* @var resource|false
*/
public $_f;
/**
* @param string $filename
*/
public function __construct( $filename ) {
parent::__construct();
$this->_f = fopen( $filename, 'rb' );
}
/**
* PHP4 constructor.
*
* @deprecated 5.4.0 Use __construct() instead.
*
* @see POMO_FileReader::__construct()
*/
public function POMO_FileReader( $filename ) {
_deprecated_constructor( self::class, '5.4.0', static::class );
self::__construct( $filename );
}
/**
* @param int $bytes
* @return string|false Returns read string, otherwise false.
*/
public function read( $bytes ) {
return fread( $this->_f, $bytes );
}
/**
* @param int $pos
* @return bool
*/
public function seekto( $pos ) {
if ( -1 === fseek( $this->_f, $pos, SEEK_SET ) ) {
return false;
}
$this->_pos = $pos;
return true;
}
/**
* @return bool
*/
public function is_resource() {
return is_resource( $this->_f );
}
/**
* @return bool
*/
public function feof() {
return feof( $this->_f );
}
/**
* @return bool
*/
public function close() {
return fclose( $this->_f );
}
/**
* @return string
*/
public function read_all() {
return stream_get_contents( $this->_f );
}
}