print $this->progress($data, 0);
} else {
if ($verbose) {
- printf("%s\n", $data);
+ printf("%s", $data);
}
$this->output .= $data;
}
* @return string
*/
private function progress($string, $flags) {
- static $c = 0;
- static $s = ["\\","|","/","-"];
+ static $counter = 0;
+ static $symbols = ["\\","|","/","-"];
$this->output .= $string;
+
+ if (false !== strpos($string, "\n")) {
+ ++$counter;
+ }
return $flags & PHP_OUTPUT_HANDLER_FINAL
? " \r"
- : sprintf(" %s\r", $s[$c++ % count($s)]);
+ : sprintf(" %s\r", $symbols[$counter % 4]);
}
/**
{
use CliCommand;
+ /**
+ * Cleanups
+ * @var array
+ */
+ private $cleanup = [];
+
/**
* Create the command
*/
]);
}
+ /**
+ * Perform cleaniup
+ */
+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
private function extract(Phar $phar) {
- $this->debug("Extracting %s ...\n", basename($phar->getPath()));
- return (new Task\Extract($phar))->run($this->verbosity());
+ $temp = (new Task\Extract($phar))->run($this->verbosity());
+ $this->cleanup[] = new Task\Cleanup($temp);
+ return $temp;
}
private function hooks(SplObjectStorage $phars) {
$this->info("Installing %s ...\n", basename($phar->getPath()));
$this->install($list[$phar]);
$this->activate($list[$phar]);
- $this->cleanup($list[$phar]);
$this->info("Successfully installed %s!\n", basename($phar->getPath()));
}
} catch (\Exception $e) {
*/
private function install($temp) {
// phpize
- $this->info("Running phpize ...\n");
$phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"});
$phpize->run($this->verbosity());
// configure
- $this->info("Running configure ...\n");
$configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"});
$configure->run($this->verbosity());
// make
- $this->info("Running make ...\n");
$make = new Task\Make($temp);
$make->run($this->verbosity());
// install
- $this->info("Running make install ...\n");
$sudo = isset($this->args->sudo) ? $this->args->sudo : null;
$install = new Task\Make($temp, ["install"], $sudo);
$install->run($this->verbosity());
}
- private function cleanup($temp) {
- (new Task\Cleanup($temp))->run();
- }
-
private function activate($temp) {
if ($this->args->ini) {
$files = [realpath($this->args->ini)];
$sudo = isset($this->args->sudo) ? $this->args->sudo : null;
$type = $this->metadata("type") ?: "extension";
- $this->info("Running INI activation ...\n");
$activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
if (!$activate->run($this->verbosity())) {
$this->info("Extension already activated ...\n");
* @return string local source
*/
private function download($source) {
- $this->info("Fetching remote source %s ...\n", $source);
-
if ($this->args->git) {
$task = new Task\GitClone($source);
} else {
* @return string extracted directory
*/
private function extract($source) {
- $this->debug("Extracting %s ...\n", $source);
-
$task = new Task\Extract($source);
$dest = $task->run($this->verbosity());
$this->cleanup[] = new Task\Cleanup($source);
if ($this->args->pecl) {
- $this->debug("Sanitizing PECL dir ...\n");
$source = (new Task\PeclFixup($source))->run($this->verbosity());
}
}
* @return boolean false, if extension was already activated
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running INI activation ...\n");
+ }
$extension = basename(current(glob("{$this->cwd}/modules/*.so")));
if ($this->type === "zend_extension") {
}
foreach ($this->inis as $file) {
+ if ($verbose) {
+ printf("Checking %s ...\n", $file);
+ }
$temp = new Tempfile("phpini");
foreach (file($file) as $line) {
if (preg_match("/^\s*{$this->type}\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
}
/* not found; append to last processed file, which is the main by default */
+ if ($verbose) {
+ printf("Activating in %s ...\n", $file);
+ }
fprintf($temp->getStream(), $this->type . "=%s\n", $extension);
$temp->closeStream();
$cmd->setSu($this->sudo);
}
$cmd->run([$path, $file]);
+
+ if ($verbose) {
+ printf("Replaced %s ...\n", $file);
+ }
return true;
}
* @return Generator
*/
public function run($verbose = false) {
+ if ($verbose) {
+ printf("Packaging pharext ... \n");
+ }
$rdi = new RecursiveDirectoryIterator(dirname(dirname(__DIR__)));
$rii = new RecursiveIteratorIterator($rdi);
for ($rii->rewind(); $rii->valid(); $rii->next()) {
* @param bool $verbose
*/
public function run($verbose = false) {
+ if ($verbose) {
+ printf("Cleaning up %s ...\n", $this->rm);
+ }
if ($this->rm instanceof Tempfile) {
unset($this->rm);
} elseif (is_dir($this->rm)) {
}
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running ./configure ...\n");
+ }
$pwd = getcwd();
if (!chdir($this->cwd)) {
throw new Exception;
* @return \pharext\Tempdir
*/
public function run($verbose = false) {
+ if ($verbose) {
+ printf("Extracting %s ...\n", basename($this->source->getPath()));
+ }
$dest = new Tempdir("extract");
$this->source->extractTo($dest);
return $dest;
* @return \pharext\Tempdir
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
$local = new Tempdir("gitclone");
$cmd = new ExecCmd("git", $verbose);
$cmd->run(["clone", $this->source, $local]);
* @throws \pharext\Exception
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running make");
+ if ($this->args) {
+ foreach ($this->args as $arg) {
+ printf(" %s", $arg);
+ }
+ }
+ printf(" ...\n");
+ }
$pwd = getcwd();
if (!chdir($this->cwd)) {
throw new Exception;
* @throws \pahrext\Exception
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Sanitizing PECL dir ...\n");
+ }
$dirs = glob("{$this->source}/*", GLOB_ONLYDIR);
$files = array_diff(glob("{$this->source}/*"), $dirs);
$dest = current($dirs);
foreach ($files as $file) {
+ if ($verbose) {
+ printf("Moving %s into %s ...\n", basename($file), basename($dest));
+ }
if (!rename($file, "$dest/" . basename($file))) {
throw new Exception;
}
* @return string
*/
public function run($verbose = false) {
+ if ($verbose) {
+ printf("Compressing %s ...\n", basename($this->package->getPath()));
+ }
$phar = $this->package->compress($this->encoding);
$meta = $phar->getMetadata();
if (isset($meta["stub"])) {
public function run($verbose = false) {
$extension = substr(strstr($this->phar, "-pharext.phar"), 8);
$name = sprintf("%s/%s.ext%s", $this->dest, $this->name, $extension);
+
+ if ($verbose) {
+ printf("Renaming %s to %s ...\n", basename($this->phar), basename($name));
+ }
if (!rename($this->phar, $name)) {
throw new Exception;
* @return \pharext\Openssl\PrivateKey
*/
public function run($verbose = false) {
+ if ($verbose) {
+ printf("Signing %s ...\n", basename($this->phar->getPath()));
+ }
$this->pkey->sign($this->phar);
return $this->pkey;
}
* @throws \pharext\Exception
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running %s ...\n", $this->phpize);
+ }
$pwd = getcwd();
if (!chdir($this->cwd)) {
throw new Exception;
* @throws \pharext\Exception
*/
public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
$context = $this->createStreamContext();
if (!$remote = fopen($this->source, "r", false, $context)) {