質問

I'm trying to make a Phar archive with one of my lib. The lib is just a bunch of classes organized into folders and subfolders. No index.php at all here, just a static Config class to call to initiate the autoloader.

Anyway, I built a archive like this :

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

After that I'm trying to use the phar like this :

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

But I get the following error :

Warning: include(phar://D:\wamp\www_test\phar\lib.phar/index.php) [function.include]: failed to open 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 ? In fact I just need the archive to be a container for my files, no need to auto execute anything.

役に立ちましたか?

解決

First of all, i think you have to startBuffering() before stopBuffering(). And I might think that buildFromDirectory does this internally for you. You don't need to do stopBuffering() for "sealing" the archive. Its ready "on the fly".

So second: You can watch the defaultStub (which is used in your code implicity) like this:

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

Its a littly bit cryptic, but you will figure it out. It does check for phar stream wrapper support (in 5.3) and if not it extracts the contents to temp file and then executes the Phar::START constant File - which is by default "index.php". And of course it does Phar::interceptFileFuncs() and sets the include path, which makes the phar working "magic". But your question sounds like you only need an archive for your libs. So you're better off with using the "PharData" class. Haven't tried it yet, but the documentation says so.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top