Added minification and manifest generation (-n)
This commit is contained in:
@ -27,20 +27,37 @@ class PharBuilder
|
||||
{
|
||||
// Create the phar
|
||||
$phar = new \Phar("/tmp/output.phar");
|
||||
$vo = posix_isatty(STDOUT);
|
||||
|
||||
// Add files
|
||||
log_debug("Adding files to phar archive...");
|
||||
$t = count($this->files); $i = 0; $lp = null;
|
||||
$phar->startBuffering();
|
||||
foreach ($this->files as $file) {
|
||||
$phar->addFile($file->dest?:$file->src, $file->src);
|
||||
$i++;
|
||||
$tp = dirname($file->src);
|
||||
if ($tp!=$lp) {
|
||||
$lp=$tp;
|
||||
printf("\r\e[K%d/%d %s", $i, $t, $tp);
|
||||
}
|
||||
if (fnmatch("*.php",$file->src)) {
|
||||
$phar->addFromString($file->dest?:$file->src, php_strip_whitespace($file->src));
|
||||
} else {
|
||||
$phar->addFile($file->dest?:$file->src, $file->src);
|
||||
}
|
||||
}
|
||||
($vo) && printf("\r\e[K");
|
||||
$phar->stopBuffering();
|
||||
|
||||
// Create stub
|
||||
if ($this->manifest->getIsLibrary()) {
|
||||
log_debug("Creating library stub...");
|
||||
// Create library stub
|
||||
$stub = '<?php ';
|
||||
$stub.= 'if (basename(__FILE__)==basename($_SERVER["SCRIPT_FILENAME"])) { echo "Error: This is a library and can not be executed\n"; exit(1); }';
|
||||
$stub.= 'require_once __DIR__."/vendor/autoload.php";';
|
||||
if (($stubfile = $this->manifest->getStubFile())) {
|
||||
$stub.= 'require_once __DIR__."/'.ltrim($stubfile,'/').'";';
|
||||
}
|
||||
$phar->addFromString("index.php", $stub);
|
||||
} else {
|
||||
log_debug("Creating application stub...");
|
||||
@ -50,6 +67,9 @@ class PharBuilder
|
||||
$phar->addFromString("index.php", $stub);
|
||||
// Make the phar stub executable
|
||||
$mainstub = $phar->createDefaultStub("index.php");
|
||||
$tmp = "/tmp/".uniqid("stub"); file_put_contents($tmp, $mainstub);
|
||||
$mainstub = php_strip_whitespace($tmp);
|
||||
unlink($tmp);
|
||||
$mainstub = "#!/usr/bin/env php\n{$mainstub}";
|
||||
$phar->setStub($mainstub);
|
||||
}
|
||||
|
Reference in New Issue
Block a user