consistent verbosity
[pharext/pharext] / src / pharext / Task / Configure.php
1 <?php
2
3 namespace pharext\Task;
4
5 use pharext\Exception;
6 use pharext\ExecCmd;
7 use pharext\Task;
8
9 /**
10 * Runs extension's configure
11 */
12 class Configure implements Task
13 {
14 /**
15 * @var array
16 */
17 private $args;
18
19 /**
20 * @var string
21 */
22 private $cwd;
23
24 /**
25 * @param string $cwd working directory
26 * @param array $args configure args
27 * @param string $prefix install prefix, e.g. /usr/local
28 * @param string $common_name PHP programs common name, e.g. php5
29 */
30 public function __construct($cwd, array $args = null, $prefix = null, $common_name = "php") {
31 $this->cwd = $cwd;
32 $cmd = $common_name . "-config";
33 if (isset($prefix)) {
34 $cmd = $prefix . "/bin/" . $cmd;
35 }
36 $this->args = ["--with-php-config=$cmd"];
37 if ($args) {
38 $this->args = array_merge($this->args, $args);
39 }
40 }
41
42 public function run($verbose = false) {
43 if ($verbose !== false) {
44 printf("Running ./configure ...\n");
45 }
46 $pwd = getcwd();
47 if (!chdir($this->cwd)) {
48 throw new Exception;
49 }
50 try {
51 $cmd = new ExecCmd("./configure", $verbose);
52 $cmd->run($this->args);
53 } finally {
54 chdir($pwd);
55 }
56 }
57 }