1
|
|
|
<?php namespace Comodojo\Extender\Socket\Messages\Task; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Extender\Traits\TasksRequestTrait; |
4
|
|
|
use \Serializable; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @package Comodojo Extender |
8
|
|
|
* @author Marco Giovinazzi <[email protected]> |
9
|
|
|
* @license MIT |
10
|
|
|
* |
11
|
|
|
* LICENSE: |
12
|
|
|
* |
13
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
14
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
15
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
16
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
17
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
18
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
19
|
|
|
* THE SOFTWARE. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class Request implements Serializable { |
23
|
|
|
|
24
|
|
|
use TasksRequestTrait; |
25
|
|
|
|
26
|
|
|
protected $parameters = []; |
27
|
|
|
|
28
|
|
|
protected $done; |
29
|
|
|
|
30
|
|
|
protected $fail; |
31
|
|
|
|
32
|
|
|
protected $pipe; |
33
|
|
|
|
34
|
|
|
// public function __construct($name, $task, array $parameters = null) { |
|
|
|
|
35
|
|
|
// |
36
|
|
|
// $this->setName($name); |
|
|
|
|
37
|
|
|
// $this->setTask($task); |
|
|
|
|
38
|
|
|
// $this->setParameters($parameters); |
|
|
|
|
39
|
|
|
// |
40
|
|
|
// } |
41
|
|
|
|
42
|
9 |
|
public function setParameters(array $parameters = null) { |
43
|
|
|
|
44
|
9 |
|
$this->parameters = empty($parameters) ? [] : $parameters; |
45
|
|
|
|
46
|
9 |
|
return $this; |
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
9 |
|
public function getParameters() { |
51
|
|
|
|
52
|
9 |
|
return $this->parameters; |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getOnDone() { |
57
|
|
|
|
58
|
|
|
return $this->done; |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
3 |
|
public function onDone(Request $request = null) { |
63
|
|
|
|
64
|
3 |
|
$this->done = $request; |
65
|
|
|
|
66
|
3 |
|
return $this; |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getOnFail() { |
71
|
|
|
|
72
|
|
|
return $this->fail; |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
6 |
|
public function onFail(Request $request = null) { |
77
|
|
|
|
78
|
6 |
|
$this->fail = $request; |
79
|
|
|
|
80
|
6 |
|
return $this; |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getPipe() { |
85
|
|
|
|
86
|
|
|
return $this->pipe; |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
3 |
|
public function pipe(Request $request = null) { |
91
|
|
|
|
92
|
3 |
|
$this->pipe = $request; |
93
|
|
|
|
94
|
3 |
|
return $this; |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function import(array $data) { |
99
|
|
|
|
100
|
|
|
$this->setName($data['name']); |
101
|
|
|
$this->setTask($data['task']); |
102
|
|
|
$this->setNiceness($data['niceness']); |
103
|
|
|
$this->setMaxtime($data['maxtime']); |
104
|
|
|
$this->setParameters($data['parameters']); |
105
|
|
|
|
106
|
|
|
$this->onDone(empty($data['done']) ? null : Request::createFromExport($data['done'])); |
107
|
|
|
$this->onFail(empty($data['fail']) ? null : Request::createFromExport($data['fail'])); |
108
|
|
|
$this->pipe(empty($data['pipe']) ? null : Request::createFromExport($data['pipe'])); |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
9 |
|
public function export() { |
113
|
|
|
|
114
|
|
|
return [ |
115
|
9 |
|
'name' => $this->getName(), |
116
|
9 |
|
'task' => $this->getTask(), |
117
|
9 |
|
'niceness' => $this->getNiceness(), |
118
|
9 |
|
'maxtime' => $this->getMaxtime(), |
119
|
9 |
|
'parameters' => $this->getParameters(), |
120
|
9 |
|
'done' => empty($this->done) ? null : $this->done->export(), |
121
|
9 |
|
'fail' => empty($this->fail) ? null : $this->fail->export(), |
122
|
9 |
|
'pipe' => empty($this->pipe) ? null : $this->pipe->export() |
123
|
3 |
|
]; |
124
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function serialize() { |
128
|
|
|
|
129
|
|
|
return serialize($this->export()); |
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function unserialize($data) { |
134
|
|
|
|
135
|
|
|
$data = unserialize($data); |
136
|
|
|
|
137
|
|
|
$this->import($data); |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
9 |
|
public static function create($name, $task, array $parameters = null) { |
142
|
|
|
|
143
|
9 |
|
$request = new Request(); |
144
|
|
|
|
145
|
9 |
|
return $request->setName($name) |
146
|
9 |
|
->setTask($task) |
147
|
9 |
|
->setParameters($parameters); |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public static function createFromExport(array $export) { |
152
|
|
|
|
153
|
|
|
$r = new Request(); |
154
|
|
|
$r->import($export); |
155
|
|
|
|
156
|
|
|
return $r; |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.