Skip to content

Instantly share code, notes, and snippets.

@nise-nabe
Created September 25, 2012 03:58
Show Gist options
  • Save nise-nabe/3779900 to your computer and use it in GitHub Desktop.
Save nise-nabe/3779900 to your computer and use it in GitHub Desktop.
phar test
<?php
$files = array('testdir/Foo.class.php', 'Hello.class.php');
// pharインスタンスを生成
$phar = new Phar(dirname(__FILE__) . '/test.phar', 0, 'test.phar');
// ファイルをアーカイブに追加
foreach ($files as $filename)
{
$phar[$filename] = file_get_contents($filename);
}
echo "created\n";
<?php
class Foo
{
public function getName() {
return __CLASS__;
}
public function execute() {
return 'This is ' . $this->getName();
}
}
<?php
class Hello
{
public function getName() {
return __CLASS__;
}
public function greet() {
echo __FILE__;
return 'Hello, world!';
}
}
<?php
// pharに含まれるファイルを取り出す
require_once 'phar://test.phar/testdir/Foo.class.php';
require_once 'phar://test.phar/Hello.class.php';
$foo = new Foo();
echo $foo->execute() . "\n";
$greet = new Hello();
echo $greet->greet() . "\n";
<?php
class Foo
{
public function getName() {
return __CLASS__;
}
public function execute() {
return 'This is ' . $this->getName();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment