直接输出plist与写入文件系统
我正在使用 CFPropertyList PHP 库,默认方法似乎是写入/保存 plist 文件。
由于我可以控制输出缓存,因此我认为跳过 plist 文件的写入并直接渲染它会更有效。
我将如何修改 CFPropertyList 来做到这一点?
这是当前的保存功能:
public function save($file=null,$format=null) {
$file = $file ? $file : $this->file;
$format = $format ? $format : $this->format;
if( !in_array( $format, array( self::FORMAT_BINARY, self::FORMAT_XML ) ) )
throw new PListException( "format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML" );
if(!file_exists($file)) {
// dirname("file.xml") == "" and is treated as the current working directory
if(!is_writable(dirname($file))) throw IOException::notWritable($file);
}
else if(!is_writable($file)) throw IOException::notWritable($file);
$content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML();
$fh = fopen($file, 'wb');
fwrite($fh,$content);
fclose($fh);
}
I am working with the CFPropertyList PHP libraries and it seems the default methods are to write/save the plist files.
Since I can control output caching, I think it would be more efficient to skip the writing of the plist file and simply render it directly.
How would I go about modifying the CFPropertyList to do this?
Here is the current save function:
public function save($file=null,$format=null) {
$file = $file ? $file : $this->file;
$format = $format ? $format : $this->format;
if( !in_array( $format, array( self::FORMAT_BINARY, self::FORMAT_XML ) ) )
throw new PListException( "format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML" );
if(!file_exists($file)) {
// dirname("file.xml") == "" and is treated as the current working directory
if(!is_writable(dirname($file))) throw IOException::notWritable($file);
}
else if(!is_writable($file)) throw IOException::notWritable($file);
$content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML();
$fh = fopen($file, 'wb');
fwrite($fh,$content);
fclose($fh);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能:
编辑:重构。
Possibly:
Edit: Refactoring.