| Conditions | 5 |
| Paths | 1 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public function startJob( |
||
| 21 | callable $callback = null, |
||
| 22 | callable $onError = null |
||
| 23 | ): void { |
||
| 24 | $this->hasCallbackSet = null !== $callback; |
||
| 25 | $this->hasOnErrorSet = null !== $callback; |
||
| 26 | |||
| 27 | $this->start( |
||
| 28 | static function (string $type, string $buffer) use ($callback, $onError) { |
||
| 29 | // if we can't decode probably child failed to execute |
||
| 30 | if ($decoded = base64_decode($buffer, true)) { |
||
| 31 | /** @var AsyncChildResponse $asyncChildResponse */ |
||
| 32 | $asyncChildResponse = unserialize($decoded, [false]); |
||
| 33 | } else { |
||
| 34 | throw new RuntimeException('Child process returned: ' . $buffer); |
||
| 35 | } |
||
| 36 | |||
| 37 | if (null !== $onError && $asyncChildResponse->getError()) { |
||
| 38 | $onError($asyncChildResponse->getError()); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (null !== $callback) { |
||
| 42 | $callback($asyncChildResponse->getJobResult(), $asyncChildResponse->getStdOut()); |
||
| 43 | } |
||
| 57 | } |