- private function installPackage() {
- $this->extract();
- $this->exec("phpize", $this->php("ize"));
- $this->exec("configure", "./configure --with-php-config=". $this->php("-config") . " ".
- implode(" ", (array) $this->args->configure));
- $this->exec("make", "make -sj3");
- $this->exec("install", "make -s install", true);
+ private function activate() {
+ if ($this->args->ini) {
+ $files = [realpath($this->args->ini)];
+ } else {
+ $files = array_filter(array_map("trim", explode(",", php_ini_scanned_files())));
+ $files[] = php_ini_loaded_file();
+ }
+
+ $extension = basename(current(glob("modules/*.so")));
+ $pattern = preg_quote($extension);
+
+ foreach ($files as $index => $file) {
+ $temp = new Tempfile("phpini");
+ foreach (file($file) as $line) {
+ if (preg_match("/^\s*extension\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
+ // already there
+ $this->info("Extension already activated\n");
+ return;
+ }
+ fwrite($temp->getStream(), $line);
+ }
+ }
+
+ // not found, add extension line to the last process file
+ if (isset($temp, $file)) {
+ fprintf($temp->getStream(), "extension=%s\n", $extension);
+ $temp->closeStream();
+
+ $path = $temp->getPathname();
+ $stat = stat($file);
+
+ $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]);
+ $this->exec("INI owner transfer", "chown", [$ugid, $path], true);
+
+ $perm = decoct($stat["mode"] & 0777);
+ $this->exec("INI permission transfer", "chmod", [$perm, $path], true);
+
+ $this->exec("INI activation", "mv", [$path, $file], true);
+ }