Beispiel #1
0
 /**
  * @param string $package path to package file
  */
 function __construct($package, \Pyrus\Package $parent)
 {
     $package = realpath($package);
     if (!$package) {
         throw new Phar\Exception('Phar package ' . $package . ' does not exist');
     }
     $pxml = false;
     $this->archive = $package;
     try {
         if (\Phar::isValidPharFilename($package, 1)) {
             $phar = new \Phar($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME);
             $pxml = 'phar://' . $package . '/' . $phar->getMetaData();
         } else {
             $phar = new \PharData($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME);
             if ($phar->getMetaData()) {
                 $pxml = 'phar://' . $package . '/' . $phar->getMetaData();
             }
         }
     } catch (\Exception $e) {
         throw new Phar\Exception('Could not open Phar archive ' . $package, $e);
     }
     $package = str_replace('\\', '/', $package);
     try {
         if ($pxml === false) {
             $info = pathinfo($package);
             $internal = $info['filename'];
             if (isset($phar[$internal . '/.xmlregistry'])) {
                 if ($phar instanceof \PharData) {
                     $iterate = new \PharData('phar://' . $package . '/' . $internal . '/.xmlregistry');
                 } else {
                     $iterate = new \Phar('phar://' . $package . '/' . $internal . '/.xmlregistry');
                 }
                 foreach (new \RecursiveIteratorIterator($iterate, \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
                     $filename = $file->getFileName();
                     // default to new package.xml
                     if (preg_match('@^(.+)\\-package.xml$@', $filename)) {
                         $pxml = $file->getPathName();
                         break;
                     }
                 }
             } else {
                 foreach (array('package2.xml', $internal . '/' . 'package2.xml', 'package.xml', $internal . '/' . 'package.xml') as $checkfile) {
                     if (isset($phar[$checkfile])) {
                         $this->_BCpackage = true;
                         $pxml = $phar[$checkfile]->getPathName();
                         break;
                     }
                 }
             }
         }
         if ($pxml === false) {
             throw new Phar\Exception('No package.xml in archive');
         }
     } catch (\Exception $e) {
         throw new Phar\Exception('Could not extract Phar archive ' . $package, $e);
     }
     parent::__construct(new \Pyrus\PackageFile($pxml, 'Pyrus\\PackageFile\\v2'), $parent);
 }
Beispiel #2
0
Phar::mapPhar('neo4jphp.phar');
spl_autoload_register(function ($className) {
    if (strpos($className, 'Everyman\\Neo4j\\') !== 0) {
        return;
    }
    $libPath = 'phar://neo4jphp.phar/lib/';
    $classFile = str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
    $classPath = $libPath . $classFile;
    if (file_exists($classPath)) {
        require $classPath;
    }
});
if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'][0])) {
    $command = empty($_SERVER['argv'][1]) ? '-help' : $_SERVER['argv'][1];
    $me = new Phar('neo4jphp.phar');
    $meta = $me->getMetaData();
    if ($command == '-help') {
        echo <<<HELP
Neo4jPHP version {$meta['version']}

{$_SERVER['argv'][0]} [-help|-license|-readme|-version|<host>] <port>
    -help            Display help text
    -license         Display software license
    -readme          Display README
    -version         Display version information
    <host> (<port>)  Test connection to Neo4j instance on host (port defaults to 7474)

HELP;
    } else {
        if ($command == '-license') {
            echo file_get_contents('phar://neo4jphp.phar/LICENSE') . "\n\n";
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$pname = 'phar://' . $fname;
$file = "<?php __HALT_COMPILER(); ?>";
$files = array();
$pmeta = 'hi there';
$files['a'] = array('cont' => 'a');
$files['b'] = array('cont' => 'b');
$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
$files['d'] = array('cont' => 'd', 'meta' => array('hi' => 'there', 'foo' => 'bar'));
include 'files/phar_test.inc';
foreach ($files as $name => $cont) {
    var_dump(file_get_contents($pname . '/' . $name));
}
$phar = new Phar($fname);
var_dump($phar->hasMetaData());
var_dump($phar->getMetaData());
var_dump($phar->delMetaData());
var_dump($phar->getMetaData());
var_dump($phar->delMetaData());
var_dump($phar->getMetaData());
foreach ($files as $name => $cont) {
    echo "  meta {$name}\n";
    var_dump($phar[$name]->hasMetadata());
    var_dump($phar[$name]->getMetadata());
    var_dump($phar[$name]->delMetadata());
    var_dump($phar[$name]->getMetadata());
}
unset($phar);
foreach ($files as $name => $cont) {
    var_dump(file_get_contents($pname . '/' . $name));
}