Passed
Push — master ( 032384...6ce998 )
by Fabio
05:25
created

TSignalParameter::setExitCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * TSignalParameter classes
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
8
 */
9
10
namespace Prado\Util;
11
12
/**
13
 * TSignalParameter class.
14
 *
15
 * This is the parameter for signal events.  The {@see \Prado\TEventParameter::getParameter()}
16
 * property is the array of $signalInfo from the Signal handler {@see \Prado\Util\TSignalsDispatcher::__invoke()};
17
 * when available on the PHP system.
18
 *
19
 * There is also the Signal {@see self::getSignal()}, whether to exit {@see self::getIsExit()},
20
 * the exit code when exiting {@see self::getExitCode()}, and the alarm time {@see self::getAlarmTime()}
21
 * if the signal is SIGALRM.
22
 *
23
 * When there is Signal Info in the Parameter property, there are inspection methods
24
 * {@see self::getParameterErrorNumber()} for accessing the Signal Error Number,
25
 * {@see self::getParameterCode()} for accessing the Signal Code, {@see self::getParameterStatus()}
26
 * for accessing the Signal Status, {@see self::getParameterPID()} for accessing
27
 * the Signal PID, and {@see self::getParameterUID()} for accessing the Signal PID UID.
28
 *
29
 * @author Brad Anderson <[email protected]>
30
 * @since 4.2.3
31
 */
32
class TSignalParameter extends \Prado\TEventParameter
33
{
34
	/** @var int Signal being sent. */
35
	private int $_signal;
36
37
	/** @var bool Should the Signal exit. */
38
	private bool $_isExit;
39
40
	/** @var int The exit code when exiting. */
41
	private int $_exitCode;
42
43
	/** @var ?int The time of the alarm signal. */
44
	private ?int $_alarmTime;
45
46
	/**
47
	 * Constructor.
48
	 * @param mixed $parameter parameter of the event
49
	 * @param bool $isExiting
50
	 * @param int $exitCode
51
	 * @param int $signal
52
	 */
53
	public function __construct(int $signal = 0, bool $isExiting = false, int $exitCode = 0, mixed $parameter = null)
54
	{
55
		$this->_signal = $signal;
56
		$this->_isExit = $isExiting;
57
		$this->_exitCode = $exitCode;
58
		parent::__construct($parameter);
59
	}
60
61
	/**
62
	 * @return int The signal being raised.
63
	 */
64
	public function getSignal(): int
65
	{
66
		return $this->_signal;
67
	}
68
69
	/**
70
	 * @param int $value The signal being raised.
71
	 * @return static The current object.
72
	 */
73
	public function setSignal(int $value): static
74
	{
75
		$this->_signal = $value;
76
77
		return $this;
78
	}
79
80
	/**
81
	 * @return bool Should the signal exit.
82
	 */
83
	public function getIsExiting(): bool
84
	{
85
		return $this->_isExit;
86
	}
87
88
	/**
89
	 * @param bool $value Should the signal exit.
90
	 * @return static The current object.
91
	 */
92
	public function setIsExiting(bool $value): static
93
	{
94
		$this->_isExit = $value;
95
96
		return $this;
97
	}
98
99
	/**
100
	 * @return int The exit code when exiting.
101
	 */
102
	public function getExitCode(): int
103
	{
104
		return $this->_exitCode;
105
	}
106
107
	/**
108
	 * @param int $value The exit code when exiting.
109
	 * @return static The current object.
110
	 */
111
	public function setExitCode(int $value): static
112
	{
113
		$this->_exitCode = $value;
114
115
		return $this;
116
	}
117
118
	/**
119
	 * @return ?int The alarm time.
120
	 */
121
	public function getAlarmTime(): ?int
122
	{
123
		return $this->_alarmTime;
124
	}
125
126
	/**
127
	 * @param ?int $value The alarm time.
128
	 * @return static The current object.
129
	 */
130
	public function setAlarmTime(?int $value): static
131
	{
132
		$this->_alarmTime = $value;
133
134
		return $this;
135
	}
136
137
	/**
138
	 * @return ?int The Parameter Error Number.
139
	 */
140
	public function getParameterErrorNumber(): ?int
141
	{
142
		$param = $this->getParameter();
143
144
		return $param['errno'] ?? null;
145
	}
146
147
	/**
148
	 * @return ?int The Parameter Code.
149
	 */
150
	public function getParameterCode(): ?int
151
	{
152
		$param = $this->getParameter();
153
154
		return $param['code'] ?? null;
155
	}
156
157
	/**
158
	 * @return ?int The Parameter Status.
159
	 */
160
	public function getParameterStatus(): ?int
161
	{
162
		$param = $this->getParameter();
163
164
		return $param['status'] ?? null;
165
	}
166
167
	/**
168
	 * @return ?int The Parameter PID.
169
	 */
170
	public function getParameterPID(): ?int
171
	{
172
		$param = $this->getParameter();
173
174
		return $param['pid'] ?? null;
175
	}
176
177
	/**
178
	 * @return ?int The Parameter UID.
179
	 */
180
	public function getParameterUID(): ?int
181
	{
182
		$param = $this->getParameter();
183
184
		return $param['uid'] ?? null;
185
	}
186
}
187