$this->help($prog);
exit;
}
-
- if ($this->args["source"]) {
- if ($this->args["pecl"]) {
- $this->source = new PeclSourceDir($this, $this->args["source"]);
- } elseif ($this->args["git"]) {
- $this->source = new GitSourceDir($this, $this->args["source"]);
- } else {
- $this->source = new FilteredSourceDir($this, $this->args["source"]);
+
+ try {
+ if ($this->args["source"]) {
+ if ($this->args["pecl"]) {
+ $this->source = new PeclSourceDir($this, $this->args["source"]);
+ } elseif ($this->args["git"]) {
+ $this->source = new GitSourceDir($this, $this->args["source"]);
+ } elseif (realpath($this->args["source"]."/pharext_package.php")) {
+ $this->source = new PharextSourceDir($this, $this->args["source"]);
+ } else {
+ $this->source = new FilteredSourceDir($this, $this->args["source"]);
+ }
}
+ } catch (\Exception $e) {
+ $errs[] = $e->getMessage();
}
foreach ($this->args->validate() as $error) {
foreach ($errs as $err) {
$this->error("%s\n", $err);
}
+ printf("\n");
if (!$this->args["quiet"]) {
$this->help($prog);
}
$this->createPackage();
}
- /**
- * @inheritdoc
- * @see \pharext\Command::getArgs()
- */
- public function getArgs() {
- return $this->args;
- }
-
- /**
- * @inheritdoc
- * @see \pharext\Command::info()
- */
- public function info($fmt) {
- if (!$this->args->quiet) {
- vprintf($fmt, array_slice(func_get_args(), 1));
- }
- }
-
- /**
- * @inheritdoc
- * @see \pharext\Command::error()
- */
- public function error($fmt) {
- if (!$this->args->quiet) {
- vfprintf(STDERR, "ERROR: $fmt", array_slice(func_get_args(), 1));
- }
- }
-
/**
* Traverses all pharext source files to bundle
* @return Generator
*/
private function createPackage() {
$pkguniq = uniqid();
- $pkgtemp = sys_get_temp_dir() ."/{$pkguniq}.phar";
+ $pkgtemp = $this->tempname($pkguniq, "phar");
$pkgdesc = "{$this->args->name}-{$this->args->release}";
$this->info("Creating phar %s ...%s", $pkgtemp, $this->args->verbose ? "\n" : " ");
try {
- $package = new Phar($pkgtemp, 0, "ext.phar");
+ $package = new Phar($pkgtemp);
$package->startBuffering();
$package->buildFromIterator($this->source, $this->source->getBaseDir());
$package->buildFromIterator($this->bundle());
$package->setStub("#!/usr/bin/php -dphar.readonly=1\n".$package->getStub());
$package->stopBuffering();
- chmod($pkgtemp, 0770);
- if ($this->args->verbose) {
+ if (!chmod($pkgtemp, 0777)) {
+ $this->error(null);
+ } elseif ($this->args->verbose) {
$this->info("Created executable phar %s\n", $pkgtemp);
} else {
$this->info("OK\n");
$pkgname = $this->args->dest ."/". basename($pkgfile);
$this->info("Finalizing %s ... ", $pkgname);
if (!rename($pkgtemp, $pkgname)) {
- $this->error("%s\n", error_get_last()["message"]);
+ $this->error(null);
exit(5);
}
$this->info("OK\n");