support for running .ext.phars without ext/phar
[pharext/pharext] / src / pharext_installer.php
index 89e44a3ec62073acea09f0386900e66ee3008bb6..19386f203b87632bf1c1eea7d9841008cb1e14c4 100644 (file)
@@ -1,11 +1,38 @@
+#!/usr/bin/env php
 <?php
+
 /**
  * The installer sub-stub for extension phars
  */
 
+namespace pharext;
+
+define("PHAREXT_PHAR", __FILE__);
+
 spl_autoload_register(function($c) {
        return include strtr($c, "\\_", "//") . ".php";
 });
 
-$installer = new pharext\Installer();
+#include <pharext/Exception.php>
+#include <pharext/Tempname.php>
+#include <pharext/Tempfile.php>
+#include <pharext/Tempdir.php>
+#include <pharext/Archive.php>
+
+namespace pharext;
+
+if (extension_loaded("Phar")) {
+       \Phar::interceptFileFuncs();
+       \Phar::mapPhar();
+       $phardir = "phar://".__FILE__;
+} else {
+       $archive = new Archive(__FILE__);
+       $phardir = $archive->extract();
+}
+
+set_include_path("$phardir:". get_include_path());
+
+$installer = new Installer();
 $installer->run($argc, $argv);
+
+__HALT_COMPILER();