php 从 .phar 存档中提取文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12997385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:37:03  来源:igfitidea点击:

Extracting files from .phar archive

phpphar

提问by epsilones

There is something I entirely missed as for phar files. I am installing a project that requires phpunit, pdepend and other dependencies. I fetched them as .phar files. But, I am not able ot extract the files from them using command line tool (php command). I googled the problem, and I found nothing really answering the question. Could anyone help ?

对于 phar 文件,我完全错过了一些东西。我正在安装一个需要 phpunit、pdepend 和其他依赖项的项目。我将它们作为 .phar 文件获取。但是,我无法使用命令行工具(php 命令)从中提取文件。我用谷歌搜索了这个问题,我没有发现任何真正回答这个问题的东西。有人可以帮忙吗?

采纳答案by noetix

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 输出目录

回答by Adrian Heine

Extending on @pozs's answer, you can actually use PharData->extractToin a simple one-liner:

扩展@pozs 的答案,您实际上可以在简单的单行中使用PharData->extractTo

php -r '$phar = new Phar("phar-file.phar"); $phar->extractTo("./directory");'

回答by lyte

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 是相对于您当前的工作目录提取的。

回答by ya.teck

PhpStorm IDE can be used for viewing content of phar archives.

PhpStorm IDE 可用于查看 phar 档案的内容。

回答by naju

This siteconverts .phar files to .zip files easily.

该站点可以轻松地将 .phar 文件转换为 .zip 文件。

Try it out.

试试看。

回答by pozs

If you want to just using it, you should include as phar:///path/to/myphar.phar/file.php.

如果你只想使用它,你应该包括 as phar:///path/to/myphar.phar/file.php

But if you really want to unpack it, see the PharDataclass - no known (internal) extraction in command line, but you can write a script for that.

但是,如果您真的想解压缩它,请参阅PharData类 - 在命令行中没有已知的(内部)提取,但您可以为此编写一个脚本。

回答by Josef says Reinstate Monica

PHP also has functions for extracting phar archives, but the files keep the current compression. To properly extract an archive it has to be converted into a uncompressed form first and then extracted:

PHP 还具有提取 phar 档案的功能,但文件保持当前压缩。要正确提取存档,必须先将其转换为未压缩形式,然后再提取:

<?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!

这将为您提供所有未压缩的文件!