| Total Complexity | 6 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Process implements ProcessInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $id; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $command; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $pathToLockFile; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \Symfony\Component\Process\Process |
||
| 28 | */ |
||
| 29 | protected $process; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param array $command |
||
| 33 | * @param string $tempDir |
||
| 34 | */ |
||
| 35 | public function __construct(array $command, string $tempDir) |
||
| 36 | { |
||
| 37 | $this->id = \sha1(implode(' ', $command)); |
||
| 38 | $this->command = $command; |
||
| 39 | $this->pathToLockFile = rtrim($tempDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->id; |
||
| 40 | |||
| 41 | $preparedCommand = array_merge($command, [';', 'rm', $this->pathToLockFile]); |
||
| 42 | |||
| 43 | $this->process = new SymfonyProcess($preparedCommand); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | public function start(): void |
||
| 50 | { |
||
| 51 | if ($this->isLocked()) { |
||
| 52 | throw new RuntimeException('Process is locked.'); |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->lock(); |
||
| 56 | $this->process->start(); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | protected function lock(): void |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function isLocked(): bool |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | public function getCommand(): array |
||
| 81 | } |
||
| 82 | } |
||
| 83 |