Speed up development with full-stack environments for every branch.

Learn More

Mounting external files into a Phar archive [PHP]

24 Runs 432 Views 104 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/*
 * PHP Phar - Mounting external files into a Phar archive
 */

$p = new Phar('my.phar');
//issue the Phar::startBuffering() method call to buffer changes made to the archive until you issue the Phar::stopBuffering() command
$p->startBuffering();
//in order to mount an external file we use the Phar::mount method in the phar stub
//this makes external files accesible as they were internal files
//this option is very useful to config files or templates
$p->setStub("<?php
        if(file_exists( __DIR__ . 'config.xml'))
        {
                Phar::mount('config.xml', __DIR__ . 'include/config.xml');
        }
        __HALT_COMPILER();
?>");

//add the test file in the phar archive
$p->addFile('include/test.php');

//Stop buffering write requests to the Phar archive, and save changes to disk
$p->stopBuffering();
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).