1 | <?php |
||
2 | /** |
||
3 | * Program base |
||
4 | * User: moyo |
||
5 | * Date: 27/12/2017 |
||
6 | * Time: 6:10 PM |
||
7 | */ |
||
8 | |||
9 | namespace Carno\Process; |
||
10 | |||
11 | use Carno\Process\Chips\Forking; |
||
12 | use Carno\Process\Contracts\Lifecycle; |
||
13 | use Carno\Promise\Promised; |
||
14 | |||
15 | abstract class Program implements Lifecycle |
||
16 | { |
||
17 | use Forking; |
||
18 | |||
19 | // use ON process started |
||
20 | public const STARTED = 0xE1; |
||
21 | |||
22 | // use ON process stopped |
||
23 | public const STOPPED = 0xE9; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $name = null; |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | final public function name() : string |
||
34 | { |
||
35 | return $this->name; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return static |
||
40 | */ |
||
41 | final public function fork() |
||
42 | { |
||
43 | return $this->forked ?? $this->forked = new Piping($this); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param Piping $piping |
||
48 | * @return static |
||
49 | */ |
||
50 | final public function forked(Piping $piping) : self |
||
51 | { |
||
52 | $this->forking($piping); |
||
53 | return $this; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * triggered when process forking (still in parent process) |
||
58 | * @param Piping $piping |
||
59 | */ |
||
60 | abstract protected function forking(Piping $piping) : void; |
||
61 | |||
62 | /** |
||
63 | * triggered when process started (in child process) |
||
64 | */ |
||
65 | abstract protected function starting() : void; |
||
66 | |||
67 | /** |
||
68 | * triggered when process exiting (in child process) |
||
69 | * @param Promised $wait |
||
70 | */ |
||
71 | abstract protected function stopping(Promised $wait) : void; |
||
72 | } |
||
73 |