| Conditions | 5 |
| Paths | 1 |
| Total Lines | 26 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | public function startJob(callable $callback = null, callable $onError = null) |
||
| 31 | { |
||
| 32 | $this->hasCallbackSet = null !== $callback; |
||
| 33 | $this->hasOnErrorSet = null !== $callback; |
||
| 34 | |||
| 35 | $this->start( |
||
| 36 | function ($type, $buffer) use ($callback, $onError) { |
||
| 37 | |||
| 38 | // if we can't decode probably child failed to execute |
||
| 39 | if ($decoded = base64_decode($buffer, true)) { |
||
| 40 | /** @var AsyncChildResponse $asyncChildResponse */ |
||
| 41 | $asyncChildResponse = unserialize($decoded); |
||
| 42 | } else { |
||
| 43 | throw new \RuntimeException('Child process returned: ' . $buffer); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (null !== $onError && $asyncChildResponse->getError()) { |
||
| 47 | $onError($asyncChildResponse->getError()); |
||
| 48 | } |
||
| 49 | |||
| 50 | if (null !== $callback) { |
||
| 51 | $callback($asyncChildResponse->getJobResult(), $asyncChildResponse->getStdOut()); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 72 | } |