To ease the deployment of Stubbles applications and new versions of the framework, Frank "invented" the
Stubbles Archive (also referred to as STAR). This allows us to create a single file, that contains all PHP class files as well as other resources (like XML documents or XSL templates) that are required by Stubbles in one single file. This file can be included just like you would include any other PHP file:
require stubConfig::getLibPath() . DIRECTORY_SEPARATOR . 'stubbles.php';
// now, the classloader is available and can be used
stubClassLoader::load('net.stubbles.xml.stubXMLStreamWriterFactory');
Of course, this does not load all classes in the archive, but just the base classes, that are needed to run the application, by making use of the
__halt_compiler() function. All other classes will be loaded from the same file using PHP's
stream wrapper API. Of course, this results in a performance loss, but according to our profiling, the loss is minimal.
Greg Beaver and Marcus Börger developed a similar format (based on
PHP_Archive in PEAR), but implemented it in C and released it as
phar in the PECL repository. Currently, the PHP core developers are
discussing, whether this extension should be added to the core in the next version of PHP. Since the announcement of the phar extension, we decided that we will
deprecate STAR in favor of phar, once it stabilized and got included into the core. Currently, it seems, that this will not happen in any 5.x version of PHP, so this is another candidate for my PHP 6 wishlist.
I think, it would be a great addition to PHP (from a developer's and marketing point of view) to bundle libraries and applications in one single file and deploy them by copying them to a specified folder. When using STAR for deployment you get a
StarClassRegistry, that knowns about all available classes in any STAR-archive that has been deployed. Loading a class from any archive gets extremely easy:
require '/path/to/starReader.php';
include StarClassRegistry::getUriForClass('com.example.MyClass');
The
getUriForClass() method scans all archives and will cache the results so they are only scanned once. Having something along those lines backed by a C implementation would be a huge benefit, IMHO. Combining this with
namespaces would be great as we finally would introduce unique names for our classes.
And yes, I still know, that PHP is not Java. If I want to develop in Java, I do this at work...