autoloader for custom stream wrappers
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Would it be possible to add an autoloader/callback function if a call is made to a function using a stream wrapper protocol that is not yet defined?
Currently, if you access a stream protocol not registered, a warning is logged 'Unable to find the wrapper "abc" - did you forget to enable it when you configured PHP?'.
In the below example, since abc hasn't yet been registered with stream_wrapper_register(), the new function stream_wrapper_autoload() would be called where abc would be registered and allow the file_get_contents() call to complete.
<?php
stream_wrapper_autoload(function($protocol)
{
switch ($protocol)
{
case 'abc':
stream_wrapper_register('abc', 'abc');
break;
}
});
$a = file_get_contents('abc://file.txt');
?>
I am using the AWS S3 stream wrapper (https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wrapper.html). Using this custom stream wrapper currently requires me either to:
- register the stream wrapper on every request even if it won't be used on the given request
- or register it before any call that would use it (file_get_contents, fopen, copy, etc).
- or add a wrapper function around file_get_contents and the other file functions to check first if the stream wrapper is registered by calling stream_get_wrappers().
Having an autoload function would allow me to register the stream wrapper only when it's needed.
Thank you for your help.
Ryan
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先通过 file_get_contents()、fopen() 和 copy() 跟踪未解析的流协议,并检查 stream_wrapper_register() 和 stream_get_wrappers() 当前如何处理注册。定义回调的行为及其与查找失败的交互,然后验证由回调注册的包装器是否能让原始文件操作完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100