php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53810 Phar::mount() Entire Directory
Submitted: 2011-01-22 05:12 UTC Modified: 2011-01-22 08:59 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: panman at traileyes dot com Assigned:
Status: Open Package: PHAR related
PHP Version: 5.3.5 OS: Win 7 32 bit
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: panman at traileyes dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-22 08:59 UTC] panman at traileyes dot com
Another nice feature that would go along with this is the ability to merge a directory with an existing Phar directory. This way users could make their own modules that would then act like it is apart of the Phar. I know this can be done on an individual file basis but there may be files scatter throughout several folders and just mounting the one folder would be nice. Of course there would be some kind of conflict checker, maybe user option to use the internal or mounted files.
 [2011-07-06 01:51 UTC] staff at pro-unreal dot de
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();
}
?>
 [2023-05-18 11:57 UTC] infocollegeschool at gmail dot com
College School Info are sharing latest news about education, school, college, learning, teaching, classes, exam, study, courses etc. More info to visit: (https://collegeschoolinfo.com)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC