epsilones
epsilones

Reputation: 11609

Extracting files from .phar archive

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 ?

Upvotes: 62

Views: 78264

Answers (7)

Najmal Jabbar
Najmal Jabbar

Reputation: 335

http://unphar.com converts .phar files to .zip files easily.

Try it out.

Upvotes: 9

Josef
Josef

Reputation: 1532

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!

Upvotes: 4

ya.teck
ya.teck

Reputation: 2336

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

Upvotes: 15

lyte
lyte

Reputation: 1192

Not sure if it's new, but under PHP 5.4.16 this works:

phar extract -f %some phar file%

The phar is extracted relative to your current working directory.

Upvotes: 74

Adrian Heine
Adrian Heine

Reputation: 4131

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");'

Upvotes: 103

pozs
pozs

Reputation: 36234

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.

Upvotes: 4

noetix
noetix

Reputation: 4923

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

phar-extract library.phar output-directory

Upvotes: 22

Related Questions