Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Artifact [4035c76835]

Artifact 4035c768359934a150c9c9b8083ebc83f31eb55e:

  • File templates/phar.php — part of check-in [01f616a04b] at 2015-01-21 12:28:32 on branch trunk — Separate phar plugin from php generation template, prepare for classmap building. (user: mario size: 1743)

<?php
/**
 * api: php
 * title: Phar generation
 * description: PHP script template to get Phar assembled
 *
 * Used as template php script for -t phar building.
 * Extracts passed Ruby variables as PHP strings, so some
 * need constant(), strlen() or boolean interpretation.
 *
 */


#-- Parameters from phar.rb passed as JSON in argv[1]
extract(json_decode($_SERVER["argv"][1], TRUE));


/**
 * Create phar
 *  · Tempoarary filename.
 *  · FPM package name as Phar name.
 *  · Read complete staging dir.
 */
$p = new Phar($tmpf, 0, $name);
$p->startBuffering();
$p->buildFromDirectory($srcdir);


/**
 * Add stub
 *  · Use given file
 *  · Default init+index.php for native Phars.
 *  · Stub for zip/tar archive.
 */
if (strlen($stub) && file_exists($stub)) {
   $p->setStub(file_get_contents($stub));
}
elseif (constant($format) == Phar::PHAR) {
   $p->setDefaultStub("__init__.php", "index.php");
}
else {
   $p->setDefaultStub();
}


/**
 * Phar meta data
 *  · Use injected JSON blob.
 *  · Contains at least fpm package infos,
 *  · May contain additional fields - attrs{} from `-s src` or `composer` module
 *  · Build and include a classmap.
 */
if ($meta) {
   $p->setMetadata($meta);
}


/**
 * Complete packaging
 *  · Set per-file compression
 *  · Add signature, if any.
 *  · Compressed outer archive hull (tar or phar).
 */
if (constant($filegz)) {
   $p->compressFiles(constant($filegz));
}
if (strlen($sign)) {
   $p->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents($sign));
}
else {
   $p->setSignatureAlgorithm(Phar::SHA256);
}
// Whole-archive compression; output goes to a different filename. (Cleaned up in Ruby...)
$p->stopBuffering();
if (strlen($extout)) {
   $p->compress(constant($hullgz));
}