How to create a Phar archive without an index?

I am trying to create a Phar archive with one of my libs. Lib is just a bunch of classes organized into folders and subfolders. There is no index.php, just a static Config class to call the startup initiator.

In any case, I created this archive:

$phar = new Phar(__DIR__ . '/lis.phar',0,'lib.phar'); $phar->buildFromDirectory(__DIR__ . '/class','/\.php$'); $phar->stopBuffering(); 

After that, I try to use phar as follows:

 require('lib.phar'); Config::register(); // Config is in the phar 

But I get the following error:

Warning: enable (phar: // D: \ wamp \ www_test \ phar \ lib.phar / index.php) [function.include]: could not open the stream: phar error: "index.php" is not a file in phar "D : /wamp/www/_test/phar/lib.phar "in D: \ wamp \ www_test \ phar \ lib.phar on line 9

How can I make a phar archive without any index.php file inside it? Actually, I just need an archive to be a container for my files, there is no need to automatically execute anything.

+2
source share
1 answer

First of all, I think you should startBuffering() before stopBuffering() . And I might think that buildFromDirectory doing this inside of you. You do not need to do stopBuffering() to "seal" the archive. Its ready on the fly.

So, secondly: you can look at defaultStub (which is used in implanting code) as follows:

 $phar->setDefaultStub(); var_dump($phar->getStub()); 

Its a little bit mysterious, but you will understand it. It checks for flash stream support (in 5.3), and if it does not extract the contents to a temp file, then it runs the constant file Phar::START , which by default is "index.php". And, of course, it does Phar::interceptFileFuncs() and sets the inclusion path, which makes phar "magic". But your question sounds as if you only need an archive for your libraries. Thus, you are better off using the "PharData" class. I have not tried it yet, but the documentation says so.

+1
source

All Articles