first work on phar version. redirection does not work yet
authorChristian Weiske <cweiske@cweiske.de>
Wed, 9 Apr 2014 20:10:42 +0000 (22:10 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 9 Apr 2014 20:10:42 +0000 (22:10 +0200)
.gitignore
build.xml [new file with mode: 0644]
src/phar-stub.php [new file with mode: 0644]
www/get.php

index d2f14ac..6396bc2 100644 (file)
@@ -1,3 +1,5 @@
 /www/imgcache
 /data/phancap.config.php
 /README.html
+/lib/
+/dist/
diff --git a/build.xml b/build.xml
new file mode 100644 (file)
index 0000000..2bf0ce1
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project name="phancap" default="phar" basedir=".">
+
+ <property name="version"  value="0.1.0" />
+ <property name="pharfile" value="${phing.dir}/dist/${phing.project.name}-${version}.phar" />
+ <property name="libdir" value="${phing.dir}/lib"/>
+
+ <fileset id="fs.phar" dir="${phing.dir}">
+<!---->
+  <include name="data/**"/>
+  <include name="lib/**"/>
+  <include name="src/**"/>
+  <include name="www/**"/>
+
+  <include name="README.rst"/>
+
+  <exclude name="data/phancap.config.php"/>
+<!--
+  <include name="www/index.php"/> -->
+ </fileset>
+
+ <typedef name="pearPackageFileSet" classname="phing.types.PearPackageFileSet" />
+
+ <target name="phar" depends="collectdeps"
+         description="Create zip file for release"
+ >
+  <mkdir dir="${phing.dir}/dist/"/>
+  <delete file="${pharfile}"/>
+  <pharpackage basedir="${phing.dir}"
+   destfile="${pharfile}"
+   stub="${phing.dir}/src/phar-stub.php"
+   alias="test.phar"
+  >
+   <fileset refid="fs.phar"/>
+  </pharpackage>
+  <!--
+  <exec executable="bzip2" dir="${phing.dir}/dist">
+   <arg value="-kf"/>
+   <arg file="${pharfile}"/>
+  </exec>
+  -->
+ </target>
+
+
+ <target name="collectdeps" description="Copy package dependencies to lib/">
+  <delete dir="${libdir}"/>
+  <mkdir dir="${libdir}"/>
+
+  <pearPackageFileset id="dep-PEAR" package="pear.php.net/PEAR">
+   <include name="PEAR/Exception.php"/>
+   <include name="PEAR.php"/>
+   <include name="PEAR5.php"/>
+  </pearPackageFileset>
+  <pearPackageFileset id="dep-Getopt" package="pear.php.net/Console_Getopt" />
+
+  <copy todir="${libdir}">
+   <fileset refid="dep-PEAR"/>
+   <fileset refid="dep-Getopt"/>
+  </copy>
+ </target>
+
+
+ <target name="docs" description="render documentation">
+  <rst file="README.rst"/>
+ </target>
+
+</project>
diff --git a/src/phar-stub.php b/src/phar-stub.php
new file mode 100644 (file)
index 0000000..04aa111
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Phar stub file for bdrem. Handles startup of the .phar file.
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Phancap
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/phancap.htm
+ */
+if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
+    echo "Phar extension not avaiable\n";
+    exit(255);
+}
+
+$web = 'www/index.php';
+
+/**
+ * Rewrite the HTTP request path to an internal file.
+ * Maps "" and "/" to "www/index.php".
+ *
+ * @param string $path Path from the browser, relative to the .phar
+ *
+ * @return string Internal path.
+ */
+function rewritePath($path)
+{
+    if ($path == '' || $path == '/') {
+        return 'www/index.php';
+    } else if ($path == '/get' || $path == '/get.php') {
+        return 'www/get.php';
+    } else if ($path == '/setup' || $path == '/setup.php') {
+        return 'www/setup.php';
+    }
+    return $path;
+}
+
+//Phar::interceptFileFuncs();
+set_include_path(
+    'phar://' . __FILE__
+    . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
+);
+Phar::webPhar(null, $web, null, array(), 'rewritePath');
+
+//work around https://bugs.php.net/bug.php?id=52322
+//require 'phar://' . __FILE__ . '/' . $web;
+echo "cli\n";
+__HALT_COMPILER();
+?>
index 739aaf8..4cd2b3a 100644 (file)
@@ -50,6 +50,7 @@ try {
     }
 } catch (\Exception $e) {
     //FIXME: handle 404s and so properly
+    //FIXME: send out error image if images are preferred
     header('HTTP/1.0 500 Internal Server error');
     header('Content-type: text/plain');
     echo $e->getMessage() . "\n";