Edit report at https://bugs.php.net/bug.php?id=53810&edit=1

 ID:                 53810
 Comment by:         staff at pro-unreal dot de
 Reported by:        panman at traileyes dot com
 Summary:            Phar::mount() Entire Directory
 Status:             Open
 Type:               Feature/Change Request
 Package:            PHAR related
 Operating System:   Win 7 32 bit
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

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();
}
?>


Previous Comments:
------------------------------------------------------------------------
[2011-01-22 08:59:32] 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-01-22 05:12:45] 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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=53810&edit=1

Reply via email to