1 | <?php |
||
12 | class Process implements ProcessInterface |
||
13 | { |
||
14 | const LINUX_STYLE = 'linux'; |
||
15 | |||
16 | /** |
||
17 | * @var ProcessInterface |
||
18 | */ |
||
19 | protected $process; |
||
20 | |||
21 | /** |
||
22 | * @var LoggerInterface |
||
23 | */ |
||
24 | protected $logger; |
||
25 | |||
26 | /** |
||
27 | * Process constructor. |
||
28 | * @param string $style |
||
29 | * @param LoggerInterface|null $logger |
||
30 | */ |
||
31 | 25 | public function __construct($style = self::LINUX_STYLE, LoggerInterface $logger = null) |
|
39 | |||
40 | /** |
||
41 | * Create "internal styled" process |
||
42 | * |
||
43 | * @param string $style |
||
44 | * @param LoggerInterface $logger |
||
45 | * @return ProcessInterface |
||
46 | */ |
||
47 | 25 | protected function getProcess($style, LoggerInterface $logger) |
|
48 | { |
||
49 | switch ($style) { |
||
50 | 25 | case self::LINUX_STYLE: |
|
51 | 25 | $process = new Linux\LinuxProcess($logger); |
|
52 | 25 | break; |
|
53 | 1 | default: |
|
54 | 1 | $msg = "System style '" . (string) $style . "' is not supported"; |
|
55 | 1 | throw new UnsupportedSystemException($msg); |
|
56 | 1 | } |
|
57 | 25 | return $process; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Check whether a pid is running |
||
62 | * |
||
63 | * @throws Exception\InvalidArgumentException |
||
64 | * @param int $pid |
||
65 | * @return boolean |
||
66 | */ |
||
67 | 16 | public function isRunning($pid) |
|
71 | |||
72 | /** |
||
73 | * Kill a process |
||
74 | * |
||
75 | * @throws Exception\InvalidArgumentException |
||
76 | * @param int $pid |
||
77 | * @param bool $wait |
||
78 | * @return void |
||
79 | */ |
||
80 | 14 | public function kill($pid, $wait = false) |
|
84 | } |
||
85 |