[英]Extracting files from .phar archive
There is something I entirely missed as for phar files. 对于phar文件,我完全错过了一些东西。 I am installing a project that requires phpunit, pdepend and other dependencies. 我正在安装一个需要phpunit,pdepend和其他依赖项的项目。 I fetched them as .phar files. 我把它们作为.phar文件获取。 But, I am not able ot extract the files from them using command line tool (php command). 但是,我无法使用命令行工具(php命令)从中提取文件。 I googled the problem, and I found nothing really answering the question. 我搜索了问题,我发现没有什么能真正回答这个问题。 Could anyone help ? 有人可以帮忙吗?
扩展@ pozs的答案,你可以在一个简单的单行中实际使用PharData-> extractTo :
php -r '$phar = new Phar("phar-file.phar"); $phar->extractTo("./directory");'
Not sure if it's new, but under PHP 5.4.16 this works: 不确定它是否是新的,但在PHP 5.4.16下,这有效:
phar extract -f %some phar file%
The phar is extracted relative to your current working directory. 相对于当前工作目录提取phar。
Yes, this library can do it: https://github.com/koto/phar-util 是的,这个库可以做到: https : //github.com/koto/phar-util
phar-extract library.phar output-directory phar-extract library.phar输出目录
PhpStorm IDE可用于查看phar档案的内容。
If you want to just using it, you should include as phar:///path/to/myphar.phar/file.php
. 如果您只想使用它,则应包括phar:///path/to/myphar.phar/file.php
。
But if you really want to unpack it, see the PharData class - no known (internal) extraction in command line, but you can write a script for that. 但是如果你真的想要解压缩它,请参阅PharData类 - 在命令行中没有已知的(内部)提取,但你可以为此编写脚本。
PHP also has functions for extracting phar archives, but the files keep the current compression. PHP还具有提取phar存档的功能,但文件保持当前压缩。 To properly extract an archive it has to be converted into a uncompressed form first and then extracted: 要正确提取存档,必须先将其转换为未压缩的表单,然后再解压缩:
<?php
$phar = new Phar('Someclass.phar');
$phar2 = $phar->convertToExecutable (Phar::TAR,Phar::NONE); // Convert to an uncompressed tar archive
$phar2->extractTo('/some/path/'); // Extract all files
This will give you all the files uncompressed! 这将为您提供所有未压缩的文件!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.