Created
June 18, 2011 06:46
-
-
Save simonjodet/1032868 to your computer and use it in GitHub Desktop.
Build a PHAR without hidden files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Cleaning up any existing phar | |
if(file_exists('package.phar')) | |
{ | |
unlink('package.phar'); | |
} | |
//Where are my application sources | |
$dir = '../app/'; | |
//Quickly get a recursive folder list | |
$folder = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | |
$items = array(); | |
foreach($folder as $item) | |
{ | |
//Get the filename | |
$filename = pathinfo($item->getPathName(), PATHINFO_BASENAME); | |
//Filter Unix hidden files by their leading dot. Add more filters in this condition. | |
if(substr($filename, 0, 1) != '.') | |
{ | |
//Key is the relative path inside the Phar, value is the complete path of the file | |
$items[substr($item->getPathName(), strlen($dir))] = $item->getPathName(); | |
} | |
} | |
//Shows the packaged files | |
print_r($items); | |
$phar = new Phar('package.phar'); | |
//Populate the Phar | |
$phar->buildFromIterator(new ArrayIterator($items)); | |
//Add a stub | |
$phar->setStub(file_get_contents('stub.php')); | |
echo PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Phar::interceptFileFuncs(); | |
//Listing the Phar's content | |
$phar = new Phar(__FILE__); | |
foreach (new RecursiveIteratorIterator($phar) as $iteration) | |
{ | |
echo $iteration->getPathName().PHP_EOL; | |
} | |
__HALT_COMPILER(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment