1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Async sockets |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
namespace AsyncSockets\Operation; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class WriteOperation |
14
|
|
|
*/ |
15
|
|
|
class WriteOperation implements OperationInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Data to write |
19
|
|
|
* |
20
|
|
|
* @var string|array|\Traversable |
21
|
|
|
*/ |
22
|
|
|
private $data; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Flag if this is an out-of-band writing |
26
|
|
|
* |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
private $isOutOfBand; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* WriteOperation constructor. |
33
|
|
|
* |
34
|
|
|
* @param string|array|\Traversable $data Data to send |
35
|
|
|
* @param bool $isOutOfBand Flag if this is an out-of-band writing |
36
|
|
|
*/ |
37
|
42 |
|
public function __construct($data = null, $isOutOfBand = false) |
38
|
|
|
{ |
39
|
42 |
|
$this->data = $data !== null ? $data : null; |
40
|
42 |
|
$this->isOutOfBand = $isOutOfBand; |
41
|
42 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Return flag if this is an out-of-band writing |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
13 |
|
public function isOutOfBand() |
49
|
|
|
{ |
50
|
13 |
|
return $this->isOutOfBand; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set out-of-band flag |
55
|
|
|
* |
56
|
|
|
* @param bool $isOutOfBand Flag if this is an out-of-band writing |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
1 |
|
public function setOutOfBand($isOutOfBand) |
61
|
|
|
{ |
62
|
1 |
|
$this->isOutOfBand = $isOutOfBand; |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** {@inheritdoc} */ |
66
|
67 |
|
public function getTypes() |
67
|
|
|
{ |
68
|
67 |
|
return [self::OPERATION_WRITE]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Return Data |
73
|
|
|
* |
74
|
|
|
* @return string|array|\Traversable |
75
|
|
|
*/ |
76
|
37 |
|
public function getData() |
77
|
|
|
{ |
78
|
37 |
|
return $this->data; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets Data |
83
|
|
|
* |
84
|
|
|
* @param string|array|\Traversable $data Data to send |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
29 |
|
public function setData($data) |
89
|
|
|
{ |
90
|
29 |
|
$this->data = $data; |
91
|
29 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Checks whether request has data |
95
|
|
|
* |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
5 |
|
public function hasData() |
99
|
|
|
{ |
100
|
5 |
|
return $this->data !== null; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Clear send data |
105
|
|
|
* |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
1 |
|
public function clearData() |
109
|
|
|
{ |
110
|
1 |
|
$this->data = null; |
111
|
1 |
|
} |
112
|
|
|
} |
113
|
|
|
|