Extracting files from .phar archive

后端 未结 7 1171
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 07:31

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

相关标签:
7条回答
  • 2021-01-31 07:56

    Yes, this library can do it: https://github.com/koto/phar-util

    phar-extract library.phar output-directory

    0 讨论(0)
  • 2021-01-31 08:12

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

    0 讨论(0)
  • 2021-01-31 08:14

    This site converts .phar files to .zip files easily.

    Try it out.

    0 讨论(0)
  • 2021-01-31 08:14

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

    0 讨论(0)
  • 2021-01-31 08:16

    If you want to just using it, you should include as 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.

    0 讨论(0)
  • 2021-01-31 08:18

    Extending on @pozs’s answer, you can actually use PharData->extractTo in a simple one-liner:

    php -r '$phar = new Phar("phar-file.phar"); $phar->extractTo("./directory");'
    
    0 讨论(0)
提交回复
热议问题