在我的应用程序引导代码中包含一个PHAR是有问题的。我试图在我的应用程序中包含phpunit/phpunit PHAR,以使PHPUnit类可用。
考虑到我有以下目录结构:
/path/to/code/
app.php
phpunit其中,phpunit是作为PHPUnit的PHPUnit,app.php包含:
<?php
$phar = 'phar://' . __DIR__ . '/phpunit';
include $phar;
assert(class_exists('\\PHPUnit\\Framework\\TestCase'));我得到以下错误:
PHP Warning: include(phar:///path/to/code/phpunit): failed to open stream:
phar error: no directory in "phar:///path/to/code/phpunit",
must have at least phar:///path/to/code/phpunit/ for root directory
(always use full path to a new phar) in /path/to/code/app.php on line 4但是,当我将PHAR重命名为phpunit.phar并包含它时,请使用
<?php
$phar = 'phar://' . __DIR__ . '/phpunit.phar';
include $phar;
assert(class_exists('\\PHPUnit\\Framework\\TestCase'));代码工作正常,并且存在TestCase类。
为什么第一个版本不能工作,关于“新phar的完整路径”的错误意味着什么?
我的PHP版本是7.2,PHPUnit PHAR是在版本7.*上安装的。
为什么不直接包括使用.phar 扩展?
我希望能够在没有PHPUnit扩展的情况下将.phar PHAR作为二进制文件使用,以保持事物的清洁。
发布于 2020-01-11 09:28:51
为什么第一个版本不能工作
基于源代码,您应该能够使用标记phar作为可执行文件,并在没有扩展的情况下使用它,但是如果这样做,我不确定您是否能够运行它。
* if executable is 1, only returns SUCCESS if the extension is one of the tar/zip .phar extensions
* if executable is 0, it returns SUCCESS only if the filename does *not* contain ".phar" anywhere, and treats
* the first extension as the filename extension
*
* if an extension is found, it sets ext_str to the location of the file extension in filename,
* and ext_len to the length of the extension.
* for urls like "phar://alias/oops" it instead sets ext_len to -1 and returns FAILURE, which tells
* the calling function to use "alias" as the phar alias
*
* the last parameter should be set to tell the thing to assume that filename is the full path, and only to check the
* extension rules, not to iterate.关于“通向新phar的完全路径”的错误意味着什么?
我认为他们是在试图传达这样的信息:你不能通过一条通往和平进程的部分道路。
我希望能够在没有PHPUnit扩展的情况下将.phar PHAR作为二进制文件使用,以保持事物的清洁。
您总是可以将phar文件命名为无扩展名的符号链接或别名。
发布于 2021-01-02 11:47:55
不要使用phar://流,因为您正在访问(外部) Phar文件。使用phar://实际上试图访问Phar存档中的资源。
<?php
$phar = __DIR__ . '/phpunit';
include $phar;
assert(class_exists('\\PHPUnit\\Framework\\TestCase'));https://stackoverflow.com/questions/59302726
复制相似问题