POMO_CachedFileReader
云策文档标注
概述
POMO_CachedFileReader 是一个 WordPress 类,用于在初始化时读取文件内容到内存中,继承自 POMO_StringReader,提供类似文件操作的字符串处理方法。
关键要点
- 类继承自 POMO_StringReader,位于 wp-includes/pomo/streams.php 文件中。
- 提供两个构造函数:PHP5 的 __construct() 和已弃用的 PHP4 构造函数 POMO_CachedFileReader()。
- __construct() 使用 file_get_contents() 读取文件内容到 _str 属性,失败时返回 false,并初始化 _pos 为 0。
- PHP4 构造函数在 WordPress 5.4.0 后弃用,调用 _deprecated_constructor() 并转发到 __construct()。
- 被 POMO_CachedIntFileReader 类使用,用于类似的文件读取场景。
原文内容
Reads the contents of the file in the beginning.
Methods
| Name | Description |
|---|---|
| POMO_CachedFileReader::__construct | PHP5 constructor. |
| POMO_CachedFileReader::POMO_CachedFileReader | PHP4 constructor. — deprecated |
Source
class POMO_CachedFileReader extends POMO_StringReader {
/**
* PHP5 constructor.
*/
public function __construct( $filename ) {
parent::__construct();
$this->_str = file_get_contents( $filename );
if ( false === $this->_str ) {
return false;
}
$this->_pos = 0;
}
/**
* PHP4 constructor.
*
* @deprecated 5.4.0 Use __construct() instead.
*
* @see POMO_CachedFileReader::__construct()
*/
public function POMO_CachedFileReader( $filename ) {
_deprecated_constructor( self::class, '5.4.0', static::class );
self::__construct( $filename );
}
}