Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to put a phar into a phar?
    text
    copied!<p>first things first: my Phars do run. I'm playing around a little bit and I have the following scenario:</p> <ul> <li>a Phar for the application (nothing irregular with it) (application-phar)</li> <li>a second phar, for example for a library. (lib-phar)</li> </ul> <p>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.</p> <p>This is the best introducing Resource I've come up with: <a href="http://www.slideboom.com/presentations/26182/PHP-5.3-Part-3---Introducing-PHAR">http://www.slideboom.com/presentations/26182/PHP-5.3-Part-3---Introducing-PHAR</a></p> <p>I have the following:</p> <h2>lib-phar</h2> <pre><code>$innerPharFile = $this-&gt;newFile('lib.phar'); $innerPhar = new Phar((string) $innerPharFile); $innerPhar-&gt;addFromString('index.php', '&lt;?php echo " inner index loaded"; ?&gt;'); $innerPhar-&gt;setStub(file_get_contents('inner_stub.php')); </code></pre> <h2>inner-stub</h2> <pre><code>&lt;?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(); ?&gt; </code></pre> <h2>application-phar</h2> <pre><code>$pharFile = $this-&gt;newFile('application.phar'); $phar = new Phar((string) $pharFile); $phar-&gt;addFile($innerPharFile,'lib.phar'); $phar-&gt;addFromString('index.php', '&lt;?php echo "outer index loaded"; ?&gt;'); $phar-&gt;setStub(file_get_contents('outer-stub.php')); </code></pre> <h2>outer-stub</h2> <pre><code>&lt;?php echo "outer stub loaded\n"; $inner_phar = 'phar://'.__FILE__.'/lib.phar'; require $inner_phar; require 'phar://'.__FILE__.'/index.php'; __HALT_COMPILER(); ?&gt; </code></pre> <h2>main</h2> <pre><code>php -f 'application.phar' </code></pre> <p>outputs:</p> <pre><code>outer stub loaded inner stub loaded string(xx) "phar://full/path/to/application.phar" outer index loaded </code></pre> <p>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:</p> <pre><code> require 'phar://phar://full/path/to/application.phar/lib.phar'; </code></pre> <p>which is in readable form: :</p> <pre><code> require 'phar:// phar://full/path/to/application.phar /lib.phar'; </code></pre> <p>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 <code>__FILE__</code> constant (as well as <code>Phar::running(TRUE|FALSE)</code> is set wrong here.</p> <p>Do you have any ideas? Or made a similary setup?</p> <p>Of course I know the alternatives:</p> <ul> <li>use one stub and one phar for lib + application</li> <li>decompress the lib.phar to a temporary place and require it from there with Phar::load()</li> </ul> <p>I really like to think about this nesting setup. Maybe you got another great idea?</p> <p>Best regards Philipp</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload