downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Phar::startBuffering> <Phar::setSignatureAlgorithm
[edit] Last updated: Fri, 25 May 2012

view this page in

Phar::setStub

(PHP >= 5.3.0, PECL phar >= 1.0.0)

Phar::setStubPhar アーカイブの PHP ローダ (あるいは起動スタブ) を設定する

説明

bool Phar::setStub ( string $stub )

注意:

このメソッドは、php.iniphar.readonly0 でないと Phar オブジェクトで動作しません。それ以外の場合は PharException がスローされます。

このメソッドを使用して、新しい Phar アーカイブに PHP 起動ローダスタブを追加します。あるいは、既存の Phar アーカイブのローダスタブを置き換えます。

Phar アーカイブのローダスタブは、 このようにアーカイブを直接インクルードした際に使用されます。

<?php
include 'myphar.phar';
?>

phar ストリームラッパーを使用して次のようにファイルをインクルードした際には、 ローダにはアクセスしません。

<?php
include 'phar://myphar.phar/somefile.php';
?>

パラメータ

stub

文字列あるいはオープンしたストリームハンドル。 この phar アーカイブの実行スタブとして使用します。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

エラー / 例外

php.ini で phar.readonly が有効になっている場合に UnexpectedValueException がスローされます。 変更をディスクに書き込む際に何らかの問題が発生した場合は PharException がスローされます。

例1 Phar::setStub() の例

<?php
try {
    
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar'0'brandnewphar.phar');
    
$p['a.php'] = '<?php var_dump("Hello");';
    
$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
    include 
'phar://brandnewphar.phar/a.php';
    
var_dump($p->getStub());
    
$p['b.php'] = '<?php var_dump("World");';
    
$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
    include 
'phar://brandnewphar.phar/b.php';
    
var_dump($p->getStub());
} catch (
Exception $e) {
    echo 
'brandnewphar.phar での書き込み操作に失敗しました: '$e;
}
?>

上の例の出力は以下となります。

string(5) "Hello"
string(82) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"
string(5) "World"
string(83) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"

参考



add a note add a note User Contributed Notes Phar::setStub
Olivier Laviale 17-Jul-2011 07:14
If your stub has a namespace, it is used for each include that doesn't define one.
jaimz22 at gmail dot com 16-Jan-2008 03:04
One thing I had alot of problems with, is that i can't set the stub unless I put the whole operation inside of a try/catch block!

If i remove the try/catch block it will error our and not write the stub with the content i want it to have.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites