By "JAR files" I mean basically a .zip archive, with a specific extension, organized after certain rules, which contains a PHP-GTK project. The idea in itself is nothing new; there is already WinAmp .wsz, Java .jar, Mozilla .xpi and so on.
Such packaging would be useful because with PHP-GTK in particular and with CLI projects in general, we often find the need for more than one file involved in a project: images, glade definitions, code and perhaps more. Bundling all such files in a single archive is very easy to do.
The more difficult alternative involves taking into consideration the filesystem structure of the particular operating system the project is installed on, and down that path lays the use of autotools and all kinds of additional complications. Not exactly what PHP-GTK needs, if it aims to become a widely accepted cross-platform language. Java has probably already proven all these points with .jar.
While PHP-GTK would especially benefit from this, I suspect it would be useful for all CLI PHP projects. I'm not so sure about the Web, since I suppose it may introduce all kinds of security and performance issues. Besides, you can say that Web projects already run in "containers", so to speak, with DOCUMENT_ROOT and all that.
A simple minimal rule to be followed by the PHP archives (PAR) would be to contain an index.php file in the root of the archive. The author would be free to organize the rest of the archive as he sees fit. There was talk about META-INF definitions inside the package, but I see no reason not to keep things simple.
The CLI php executable may, in the future, include an option to execute such archives. It would implicate unpacking the archive, defining a constant such as CONTAINER_ROOT pointing at the unpacked directory, execute index.php, and clean everything up after index.php stops.
For the moment, that's exactly how the script I provide here works.
This script I've written is really simplistic (uses unzip to test and unpack the archive and is Linux-centric). It implements archive support in the following manner:
php load_archive.php myproject.zip
What it does:
/tmp.
index.php, but prepend an also unique temporary
file which will set the constant CONTAINER_ROOT to the
full path of the directory that the archive was unpacked in.
index.php finishes.
The PAR packages have to follow these simple rules:
index.php file in the root of the
archive.
The script itself is merely proof-of-concept so I do not plan to develop it anymore.
However, the PAR issue itself is much more interesting. If you are
interested in promoting the usage of such files for PHP or in adding any
useful ideas, please contact me or raise the issue on the
php-general mailing list.
This script is hereby placed into the public domain. You can do whatever you want with it.