first things first: my Phars do run. I'm playing around a little bit and I have the following scenario:
- a Phar for the application (nothing irregular with it) (application-phar)
- a second phar, for example for a library. (lib-phar)
I'd like to put the lib-phar into the application-phar. and require only the application-phar. So that the bootstrap (stub) from the application-phar loads the bootstrap from the lib-phar.
This is the best introducing Resource I've come up with: http://www.slideboom.com/presentations/26182/PHP-5.3-Part-3---Introducing-PHAR
I have the following:
lib-phar
$innerPharFile = $this->newFile('lib.phar');
$innerPhar = new Phar((string) $innerPharFile);
$innerPhar->addFromString('index.php', '<?php echo " inner index loaded"; ?>');
$innerPhar->setStub(file_get_contents('inner_stub.php'));
inner-stub
<?php
echo " inner stub loaded\n\n";
// Here is the problem: how do i execute index.php from inner, here?
var_dump(Phar::running (TRUE));
echo "\n";
__HALT_COMPILER();
?>
application-phar
$pharFile = $this->newFile('application.phar');
$phar = new Phar((string) $pharFile);
$phar->addFile($innerPharFile,'lib.phar');
$phar->addFromString('index.php', '<?php echo "outer index loaded"; ?>');
$phar->setStub(file_get_contents('outer-stub.php'));
outer-stub
<?php
echo "outer stub loaded\n";
$inner_phar = 'phar://'.__FILE__.'/lib.phar';
require $inner_phar;
require 'phar://'.__FILE__.'/index.php';
__HALT_COMPILER();
?>
main
php -f 'application.phar'
outputs:
outer stub loaded
inner stub loaded
string(xx) "phar://full/path/to/application.phar"
outer index loaded
So long, so good, but... How Do I execute the inner index.php? I think the problem is, that i would like to dome something very confusing:
require 'phar://phar://full/path/to/application.phar/lib.phar';
which is in readable form: :
require 'phar://
phar://full/path/to/application.phar
/lib.phar';
because my lib.phar is IN application.phar. So I think I would need a wrapper around the wrapper.
So maybe the PHAR-Extension is not made for this. As we see the second stub is called, but the magic __FILE__
constant (as well as Phar::running(TRUE|FALSE)
is set wrong here.
Do you have any ideas? Or made a similary setup?
Of course I know the alternatives:
- use one stub and one phar for lib + application
- decompress the lib.phar to a temporary place and require it from there with Phar::load()
I really like to think about this nesting setup. Maybe you got another great idea?
Best regards Philipp