包含或需要 vfsStream 文件
使用 vfsStream,我可以要求或包含虚拟文件吗?
$structure = array(
'classes' => array('Foo.php' => '<?php class Foo {} ?>')
);
\vfsStream::create($structure);
require_once(\vfsStream::url('classes').DIRECTORY_SEPARATOR.'Foo.php');
上面的代码在 PHPUnit 下会默默地失败。
谢谢。
Using vfsStream, am I able to require or include a virtual file?
$structure = array(
'classes' => array('Foo.php' => '<?php class Foo {} ?>')
);
\vfsStream::create($structure);
require_once(\vfsStream::url('classes').DIRECTORY_SEPARATOR.'Foo.php');
The code above fails silently under PHPUnit.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过吗
require_once(\vfsStream::url('root/classes').DIRECTORY_SEPARATOR.'Foo.php');
?对
vfsStream::create($struct);
的调用创建根目录,并且不使用$structs
中的第一个条目作为根目录,因为可能还有更多条目然后是该数组中的一个元素。另请参阅 https://github.com/mikey179/vfsStream/wiki/Createcomplexstructs 处的文档。Have you tried
require_once(\vfsStream::url('root/classes').DIRECTORY_SEPARATOR.'Foo.php');
? The call to
vfsStream::create($structure);
creates the root directory, and does not use the first entry in$structures
as the root directory as there might be more then one element in this array. See also documentation at https://github.com/mikey179/vfsStream/wiki/Createcomplexstructures.除了 Frank 的关于 url() 错误使用的回答之外,还可能存在配置问题。在常规 PHP 安装中,您必须确保在 php.ini 中启用了allow_url_fopen,并在配置或脚本中启用了allow_url_include。
然而,就我而言,我正在运行 Suhosin 扩展,它会忽略这些参数并完全默认情况下禁用 url_fopen。为了包含/需要 vfsStream 文件,您需要将 vfs:// 方案添加到 php.ini 中 Suhosin 的白名单中:
suhosin.executor.include.whitelist = "vfs://"
谢谢感谢 vfsStream 维护者 Frank Kleine 帮助我找到了这个问题。1
In addition to Frank's answer about the incorrect use of url(), there may be a configuration issue. In a stock PHP installation, you have to make sure allow_url_fopen is enabled in your php.ini and allow_url_include is enabled in configuration or your script.
In my case, however, I'm running the Suhosin extension, which ignores these parameters and completely disables url_fopen by default. In order to include/require a vfsStream file, you need to add the vfs:// scheme to Suhosin's whitelist in php.ini:
suhosin.executor.include.whitelist = "vfs://"
Thanks to Frank Kleine, the vfsStream maintainer, for helping me track this down.1