如何创建没有索引的Phar存档?

编程入门 行业动态 更新时间:2024-10-23 04:57:49
本文介绍了如何创建没有索引的Phar存档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用我的一个lib创建一个Phar存档. lib只是一类归类为文件夹和子文件夹的类.这里根本没有index.php,只有一个静态Config类可以调用以启动自动加载器.

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

之后,我尝试使用这样的phar:

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

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

但是出现以下错误:

警告:包括(phar://D:\ wamp \ www_test \ phar \ lib.phar/index.php) [function.include]:无法打开流:phar错误:"index.php"是 不是phar"D:/wamp/www/_test/phar/lib.phar"中的文件 第9行的D:\ wamp \ www_test \ phar \ lib.phar

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

如何在其中没有任何index.php文件的情况下制作phar存档?实际上,我只需要将存档文件作为文件的容器,而无需自动执行任何操作.

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.

推荐答案

首先,我认为您必须在stopBuffering()之前先startBuffering().我可能认为buildFromDirectory在内部为您完成此操作. 您无需执行stopBuffering()即可封存"存档.它已经准备就绪,可以运行中".

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".

第二步:您可以像这样观看defaultStub(在代码中隐式使用):

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

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

它有点神秘,但是您会发现的.它会检查是否支持phar流包装器(在5.3中),如果不支持,则将内容提取到临时文件中,然后执行Phar::START常量文件-默认情况下为"index.php".当然,它会执行Phar::interceptFileFuncs()并设置包含路径,这会使phar发挥魔力".但是您的问题听起来像您只需要一个lib存档.因此,最好使用"PharData"类.还没有尝试过,但是文档上是这样说的.

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.

更多推荐

如何创建没有索引的Phar存档?

本文发布于:2023-06-04 08:34:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/493342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   Phar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!