Speed up development with full-stack environments for every branch.Learn More
How to create and use a Phar archive [PHP]
996 Runs 8202 Views 2705 Copies
<?php /* * PHP Phar - How to create and use a Phar archive */ $p = new Phar('my.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, 'my.phar'); //issue the Phar::startBuffering() method call to buffer changes made to the archive until you issue the Phar::stopBuffering() command $p->startBuffering(); //set the Phar file stub //the file stub is merely a small segment of code that gets run initially when the Phar file is loaded, //and it always ends with a __HALT_COMPILER() $p->setStub('<?php Phar::mapPhar(); include "phar://my.phar/index.php"; __HALT_COMPILER(); ?>'); //Adding files to the archive $p['text.txt'] = 'This is a text file'; //Adding files to an archive using Phar::buildFromDirectory() //adds all of the PHP files in the stated directory to the Phar archive $p->buildFromDirectory('include/', '$(.*)\.php$'); //Stop buffering write requests to the Phar archive, and save changes to disk $p->stopBuffering(); echo "my.phar archive has been saved"; ?>
Please login/signup to get access to the terminal.