|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-22 05:12 UTC] panman at traileyes dot com
Description:
------------
It would be _very_ nice to be able to mount an external directory somewhere in the Phar. That way if there are many files that need to be included they don't need to each be Phar::mount()'ed.
Note that all sub files and folders should also be in directory listings and available through the Web. Bugs 53809 and 53801.
The directory structure should be as follows for the test below:
make.php = In the test script below
list.php = In the test script below
ext/page1.html = <p>Page 1</p>
ext/page2.html = <p>Page 2</p>
Test script:
---------------
<?php
// make.php
try {
$p = new Phar('test.phar');
$p->addFile('list.php');
$p->setStub('<?php
Phar::interceptFileFuncs();
Phar::webPhar("test.phar", "list.php");
Phar::mount(__DIR__ . "/ext/", "ext/");
__HALT_COMPILER();');
echo 'Done making test.phar';
} catch (Exception $e) {
echo 'Exception caught: ' . $e->getMessage();
}
?>
<?php
// list.php
$path = Phar::running() . '/ext';
echo "Path: $path<br>\r\n";
echo 'Exists: ' . (file_exists($path) ? 'Yes' : 'No') . "<br>\r\n";
echo "Listing...<br>\r\n";
foreach (new DirectoryIterator($path) as $file) {
if ($file->isDot()) continue;
echo $file->getFilename() . "<br>\r\n";
}
echo "...done listing<br>\r\n";
?>
Expected result:
----------------
Visiting: make.php
Done making test.phar
Visiting: test.phar/list.php
Path: phar://test.phar/ext
Exists: Yes
Listing...
page1.html
page2.html
...done listing
Visiting: test.phar/ext/page1.html
Page 1
Actual result:
--------------
Visiting: make.php
Done making test.phar
Visiting: test.phar/list.php
Path: phar://test.phar/ext
Exists: No
Listing...
Visiting: test.phar/ext/page1.html
404 - File /ext/page1.html Not Found
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 22:00:01 2025 UTC |
Hi, Mounting directories works but you have an error in your stub. Any initialization should be called before Phar::webPhar() unless you want it on CLI only. What indeed doesn't work is mounting to files/directories that already exists inside the phar. Change make.php to the following: <?php // make.php try { $p = new Phar('test.phar'); $p->addFile('list.php'); $p->setStub('<?php Phar::interceptFileFuncs(); // Mount must be before webPhar and not after it Phar::mount(__DIR__ . "/ext/", "ext/"); Phar::webPhar("test.phar", "list.php"); __HALT_COMPILER();'); echo 'Done making test.phar'; } catch (Exception $e) { echo 'Exception caught: ' . $e->getMessage(); } ?>