Skip to content

Instantly share code, notes, and snippets.

@kimikimi714
Last active February 7, 2016 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimikimi714/cc9b503f09ecbdf0cb02 to your computer and use it in GitHub Desktop.
Save kimikimi714/cc9b503f09ecbdf0cb02 to your computer and use it in GitHub Desktop.
How to make valid phar file? (Hello.php puts in hello directory.)
<?php
class Hello {
public function sayHello() {
echo "hello\n";
}
}
<?php
$phar = new Phar('hello.phar', 0, 'hello.phar');
$phar->buildFromDirectory(__DIR__ . '/hello');
$phar->setDefaultStub();
<?php
try {
$file = (new PharFileInfo('phar://' . __DIR__ . '/hello.phar/hello/Hello.php'))->openFile();
var_dump($file);
} catch (Exception $e) {
var_dump($e);
}
@kimikimi714
Copy link
Author

This is an output when I executed open_phar.php.

object(RuntimeException)#3 (7) {
  ["message":protected]=>
  string(118) "Cannot access phar file entry '/hello/Hello.php' in archive '/Users/kimikimi714/Documents/hello.phar'"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(59) "/Users/kimikimi714/Documents/open_test.php"
  ["line":protected]=>
  int(6)
  ["trace":"Exception":private]=>
  array(1) {
    [0]=>
    array(6) {
      ["file"]=>
      string(59) "/Users/kimikimi714/Documents/open_test.php"
      ["line"]=>
      int(6)
      ["function"]=>
      string(11) "__construct"
      ["class"]=>
      string(12) "PharFileInfo"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        string(79) "phar:///Users/kimikimi714/Documents/hello.phar/hello/Hello.php"
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
}

_人人人人人人人人人人_
> RuntimeException <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

@DjJakkiGlass
Copy link

I don't understand how to take the files from an updated plugin and make it into a .phar file on my server. Plz help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment