first work on .phar
authorChristian Weiske <cweiske@cweiske.de>
Wed, 21 May 2014 05:48:02 +0000 (07:48 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 21 May 2014 05:48:02 +0000 (07:48 +0200)
.gitignore
build.xml
src/stub-phar.php [new file with mode: 0644]

index 8010ba3..53196ec 100644 (file)
@@ -1,6 +1,8 @@
-README.html
-repos
-data/config.php
-build.properties
-dist
+/README.html
+/repos
+/data/config.php
+/build.properties
+/dist
 /lib/
+/www/*.phar
+/www/*.phar.bz2
index bb7b1a0..a7682e3 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -8,8 +8,8 @@
   -->
   <property file="build.properties" />
 
-  <property name="version-m"  value="0.3" />
-  <property name="version"    value="0.3.1" />
+  <property name="version-m"  value="0.4" />
+  <property name="version"    value="0.4.0" />
   <property name="stability"  value="alpha" />
   <property name="releasenotes" value="
 Version 0.3.1 - 2012-09-27
@@ -36,6 +36,7 @@ Version 0.3.0 - 2012-09-27
 * Added nginx rewrite rules to README [skl]
 " />
   <property name="zipfile"     value="${phing.project.name}-${version}.tar.bz2" />
+  <property name="pharfile"    value="${phing.dir}/dist/${phing.project.name}-${version}.phar" />
   <property name="pkgfile"     value="${phing.project.name}-${version}.tgz" />
   <property name="distfile"    value="dist/${zipfile}" />
   <property name="distpkgfile" value="dist/pear/${pkgfile}" />
@@ -57,14 +58,54 @@ Version 0.3.0 - 2012-09-27
    <exclude name="data/config.php"/>
   </fileset>
 
+  <fileset id="fs.phar" dir="${phing.dir}">
+   <include name="data/**"/>
+   <include name="lib/**"/>
+   <include name="scripts/**"/>
+   <include name="src/**"/>
+   <include name="www/**"/>
+
+   <include name="ChangeLog"/>
+   <include name="README.rst"/>
+
+   <exclude name="data/config.php"/>
+   <exclude name="**/.gitignore/"/>
+   <exclude name="**/.git/"/>
+   <exclude name="lib/geshi/geshi/src/doc/"/>
+   <exclude name="lib/twig/twig/doc/"/>
+   <exclude name="lib/twig/twig/test/"/>
+   <exclude name="lib/pear-pear.php.net/PEAR/bin/"/>
+   <exclude name="lib/pear-pear.php.net/PEAR/PEAR/"/>
+  </fileset>
+
   <fileset id="fs.doc" dir=".">
    <include name="README.rst"/>
    <include name="NEWS.rst"/>
   </fileset>
 
-  <taskdef name="rST" classname="phing.tasks.ext.rSTTask" />
   <taskdef name="d51pearpkg2" classname="phing.tasks.ext.d51PearPkg2Task" />
 
+
+  <!-- FIXME: depends="collectdeps" -->
+  <target name="phar"
+          description="Create phar file for release"
+  >
+   <delete file="${pharfile}"/>
+   <pharpackage basedir="${phing.dir}"
+                destfile="${pharfile}"
+                stub="${phing.dir}/src/stub-phar.php"
+                alias="phorkie.phar"
+   >
+    <fileset refid="fs.phar"/>
+   </pharpackage>
+
+   <exec executable="bzip2" dir="${phing.dir}/dist">
+    <arg value="-kf"/>
+    <arg file="${pharfile}"/>
+   </exec>
+  </target>
+
+
   <target name="zip" depends="check"
    description="Create zip file for release"
    >
diff --git a/src/stub-phar.php b/src/stub-phar.php
new file mode 100644 (file)
index 0000000..72e367d
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Phar stub file for phorkie. Handles startup of the .phar file.
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Phorkie
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://phorkie.sf.net/
+ */
+if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
+    echo "Phar extension not avaiable\n";
+    exit(255);
+}
+
+$web = 'www/index.php';
+//FIXME
+$cli = 'scripts/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 == '') {
+        //we need a / to get the relative links on index.php work
+        if (!isset($_SERVER['REQUEST_SCHEME'])) {
+            $_SERVER['REQUEST_SCHEME'] = 'http';
+        }
+        $url = $_SERVER['REQUEST_SCHEME'] . '://'
+            . $_SERVER['HTTP_HOST']
+            . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
+            . '/';
+        header('Location: ' . $url);
+        exit(0);
+    } else if ($path == '/') {
+        return 'www/index.php';
+    }
+
+    if (substr($path, -4) == '.css') {
+        header('Expires: ' . date('r', time() + 86400 * 7));
+    }
+    return $path;
+}
+
+//Phar::interceptFileFuncs();
+set_include_path(
+    'phar://' . __FILE__
+    . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
+);
+Phar::webPhar(null, $web, null, array(), 'rewritePath');
+
+//TODO: implement CLI script runner
+echo "phorkie can only be used in the browser\n";
+exit(1);
+__HALT_COMPILER();
+?>