1 | <?php |
||
16 | class ReadWriteOperation implements OperationInterface |
||
17 | { |
||
18 | /** |
||
19 | * Flag if read operations must be processed before write |
||
20 | */ |
||
21 | const READ_FIRST = true; |
||
22 | |||
23 | /** |
||
24 | * Flag if write operations must be processed before read |
||
25 | */ |
||
26 | const WRITE_FIRST = false; |
||
27 | |||
28 | /** |
||
29 | * Operation queue indexed by operation type |
||
30 | * |
||
31 | * @var OperationInterface[][] |
||
32 | */ |
||
33 | private $queue = []; |
||
34 | |||
35 | /** |
||
36 | * Flag whether read operation must be fired before write |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $isReadFirst; |
||
41 | |||
42 | /** |
||
43 | * ReadWriteOperation constructor. |
||
44 | * |
||
45 | * @param bool $isReadFirst Flag whether read operation must be fired before write |
||
46 | * @param OperationInterface[] $operations Array of operations to schedule |
||
47 | */ |
||
48 | 15 | public function __construct($isReadFirst, array $operations = []) |
|
55 | |||
56 | /** |
||
57 | * Set read or write operation |
||
58 | * |
||
59 | * @param OperationInterface $operation Operation to set |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | 15 | public function scheduleOperation(OperationInterface $operation) |
|
77 | |||
78 | /** |
||
79 | * Mark operation as completed |
||
80 | * |
||
81 | * @param OperationInterface $operation Operation to mark as done |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | 10 | public function markCompleted(OperationInterface $operation) |
|
99 | |||
100 | /** |
||
101 | * Return current read operation |
||
102 | * |
||
103 | * @return ReadOperation|null |
||
104 | */ |
||
105 | 11 | public function getReadOperation() |
|
111 | |||
112 | /** |
||
113 | * Return current write operation |
||
114 | * |
||
115 | * @return WriteOperation|null |
||
116 | */ |
||
117 | 11 | public function getWriteOperation() |
|
123 | |||
124 | /** |
||
125 | * Return true if read must be handled before write |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 5 | public function isReadFirst() |
|
133 | |||
134 | /** |
||
135 | * @inheritDoc |
||
136 | */ |
||
137 | 3 | public function getTypes() |
|
148 | } |
||
149 |