1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Tester\Runner;
9:
10:
11: 12: 13: 14: 15:
16: class PhpExecutable
17: {
18:
19: public $arguments;
20:
21:
22: private $path;
23:
24:
25: private $version;
26:
27:
28: private $cgi;
29:
30:
31: public function __construct($path, $args = NULL)
32: {
33: $this->path = \Tester\Helpers::escapeArg($path);
34: $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
35: $proc = @proc_open("$this->path -n -v", $descriptors, $pipes);
36: $output = stream_get_contents($pipes[1]);
37: $error = stream_get_contents($pipes[2]);
38: if (proc_close($proc)) {
39: throw new \Exception("Unable to run '$path': " . preg_replace('#[\r\n ]+#', ' ', $error));
40: } elseif (!preg_match('#^PHP (\S+).*c(g|l)i#i', $output, $matches)) {
41: throw new \Exception("Unable to detect PHP version (output: $output).");
42: }
43:
44: $this->version = $matches[1];
45: $this->cgi = strcasecmp($matches[2], 'g') === 0;
46: $this->arguments = $args;
47: }
48:
49:
50: 51: 52:
53: public function getCommandLine()
54: {
55: return $this->path;
56: }
57:
58:
59: 60: 61:
62: public function getVersion()
63: {
64: return $this->version;
65: }
66:
67:
68: 69: 70:
71: public function isCgi()
72: {
73: return $this->cgi;
74: }
75:
76: }
77: