first work on .phar generation
authorChristian Weiske <cweiske@cweiske.de>
Thu, 27 Mar 2014 20:50:19 +0000 (21:50 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 27 Mar 2014 20:50:19 +0000 (21:50 +0100)
.gitignore
build.xml
src/phar-stub.php [new file with mode: 0644]

index a09bfc2d4e97c32baa888dd9339bef87f321a67e..c1892ca6727f2aa4163effb0eef2e3abf91c2afa 100644 (file)
@@ -1,3 +1,5 @@
 data/config.php
 www/test.htm
 data/config.php
 www/test.htm
-lib/simplepie/*
+lib/*
+/dist/
+/bin/phar-stapibas.php
index 5b7513cc65cf33326bd1dce86d0f47ff4a4b1b66..472e1ed8e07c2cb4c08f1c66053bfa58124f36ee 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,5 +1,80 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<project name="stapibas" default="dist">
+<project name="stapibas" default="phar">
+
+ <property name="version"  value="0.1.0" />
+ <property name="distdir" value="${phing.dir}/dist"/>
+ <property name="pharfile" value="${distdir}/${phing.project.name}-${version}.phar" />
+ <property name="libdir" value="${phing.dir}/lib"/>
+
+ <fileset id="fs.phar" dir="${phing.dir}">
+  <include name="bin/**"/>
+  <include name="data/**"/>
+  <include name="lib/**"/>
+  <include name="src/**"/>
+  <include name="www/**"/>
+
+  <include name="README.rst"/>
+
+  <exclude name="data/config.php"/>
+ </fileset>
+
+
+ <target name="phar" depends="collectdeps"
+         description="Create zip file for release"
+ >
+  <!-- strip the shebang  -->
+  <copy file="${phing.dir}/bin/stapibas" tofile="${phing.dir}/bin/phar-stapibas.php">
+   <filterchain>
+    <striplinecomments>
+     <comment value="#" />
+    </striplinecomments>
+   </filterchain>
+  </copy>
+
+  <mkdir dir="${distdir}"/>
+  <delete file="${pharfile}"/>
+  <pharpackage basedir="${phing.dir}"
+   destfile="${pharfile}"
+   stub="${phing.dir}/src/phar-stub.php"
+   alias="bdrem.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>
+   <fileset dir="${libdir}">
+    <include name="**"/>
+    <exclude name="simplepie"/>
+   </fileset>
+  </delete>
+
+  <pearPackageFileset id="dep-Console_CommandLine" package="pear.php.net/Console_CommandLine"/>
+  <pearPackageFileset id="dep-HTTP_Request2" package="pear.php.net/HTTP_Request2"/>
+  <pearPackageFileset id="dep-Net_URL2" package="pear.php.net/Net_URL2"/>
+  <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-Services_Linkback" package="pear2.php.net/Services_Linkback"/>
+
+  <copy todir="${libdir}">
+   <fileset refid="dep-Console_CommandLine"/>
+   <fileset refid="dep-HTTP_Request2"/>
+   <fileset refid="dep-Net_URL2"/>
+   <fileset refid="dep-PEAR"/>
+   <fileset refid="dep-Services_Linkback"/>
+  </copy>
+ </target>
+
 
  <target name="dump-db" description="Update data/tables.sql">
   <exec command="mysqldump --no-data --skip-add-drop-table --skip-set-charset -ustapibas -pstapibas stapibas|grep -v '/*!40' |grep -v '^--' |sed 's/AUTO_INCREMENT=[0-9]*//' > data/tables.sql" />
 
  <target name="dump-db" description="Update data/tables.sql">
   <exec command="mysqldump --no-data --skip-add-drop-table --skip-set-charset -ustapibas -pstapibas stapibas|grep -v '/*!40' |grep -v '^--' |sed 's/AUTO_INCREMENT=[0-9]*//' > data/tables.sql" />
diff --git a/src/phar-stub.php b/src/phar-stub.php
new file mode 100644 (file)
index 0000000..b1da1cf
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Phar stub file for stapibas. Handles startup of the .phar file.
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Stapibas
+ * @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/bdrem.htm
+ */
+if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
+    echo "Phar extension not avaiable\n";
+    exit(255);
+}
+
+$web = 'www/index.php';
+$cli = 'bin/phar-stapibas.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';
+    }
+    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
+if (php_sapi_name() == 'cgi-fcgi') {
+    echo "Your PHP has a bug handling phar files :/\n";
+    exit(10);
+}
+
+require 'phar://' . __FILE__ . '/' . $cli;
+__HALT_COMPILER();
+?>