*/
private $args;
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::getArgs()
+ */
+ public function getArgs() {
+ return $this->args;
+ }
+
/**
* Output pharext vX.Y.Z header
*/
printf("pharext v%s (c) Michael Wallner <mike@php.net>\n\n", VERSION);
}
+ /**
+ * @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) {
+ if (!isset($fmt)) {
+ $fmt = "%s\n";
+ $arg = error_get_last()["message"];
+ } else {
+ $arg = array_slice(func_get_args(), 1);
+ }
+ vfprintf(STDERR, "ERROR: $fmt", $arg);
+ }
+ }
+
/**
* Output command line help message
* @param string $prog
printf("\n");
}
-
+ /**
+ * Create temporary file/directory name
+ * @param string $prefix
+ * @param string $suffix
+ */
+ private function tempname($prefix, $suffix = null) {
+ if (!isset($suffix)) {
+ $suffix = uniqid();
+ }
+ return sprintf("%s/%s.%s", sys_get_temp_dir(), $prefix, $suffix);
+ }
}
\ No newline at end of file
$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" : " ");
$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");