File tree Expand file tree Collapse file tree 4 files changed +116
-0
lines changed
app/code/Magento/AsynchronousOperations Expand file tree Collapse file tree 4 files changed +116
-0
lines changed Original file line number Diff line number Diff line change 6
6
namespace Magento \AsynchronousOperations \Model ;
7
7
8
8
use Magento \AsynchronousOperations \Api \Data \OperationInterface ;
9
+ use Magento \AsynchronousOperations \Model \OperationStatusValidator ;
9
10
use Magento \Framework \DataObject ;
10
11
11
12
/**
12
13
* Class Operation
13
14
*/
14
15
class Operation extends DataObject implements OperationInterface
15
16
{
17
+ /**
18
+ * @var OperationStatusValidator
19
+ */
20
+ protected $ operationStatusValidator ;
21
+
22
+ /**
23
+ * Operation constructor.
24
+ *
25
+ * @param array $data
26
+ * @param OperationStatusValidator $operationStatusValidator
27
+ */
28
+ public function __construct (
29
+ array $ data = [],
30
+ OperationStatusValidator $ operationStatusValidator
31
+ ) {
32
+ $ this ->operationStatusValidator = $ operationStatusValidator ;
33
+ parent ::__construct ($ data );
34
+ }
35
+
16
36
/**
17
37
* @inheritDoc
18
38
*/
@@ -106,6 +126,7 @@ public function getStatus()
106
126
*/
107
127
public function setStatus ($ status )
108
128
{
129
+ $ this ->operationStatusValidator ->validate ($ status );
109
130
return $ this ->setData (self ::STATUS , $ status );
110
131
}
111
132
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \AsynchronousOperations \Model ;
7
+
8
+ /**
9
+ * Class OperationStatusPool
10
+ *
11
+ * Pool of statuses that require validate
12
+ */
13
+ class OperationStatusPool
14
+ {
15
+ /**
16
+ * @var array
17
+ */
18
+ protected $ statuses ;
19
+
20
+ /**
21
+ * @param array $statuses
22
+ */
23
+ public function __construct (array $ statuses = [])
24
+ {
25
+ $ this ->statuses = $ statuses ;
26
+ }
27
+
28
+ /**
29
+ * Retrieve statuses that require validate
30
+ *
31
+ * @return array
32
+ */
33
+ public function getStatuses ()
34
+ {
35
+ return $ this ->statuses ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \AsynchronousOperations \Model ;
7
+
8
+ use Magento \AsynchronousOperations \Model \OperationStatusPool ;
9
+ use Magento \Framework \Exception \NoSuchEntityException ;
10
+ use Doctrine \Instantiator \Exception \InvalidArgumentException ;
11
+
12
+ /**
13
+ * Class OperationStatusValidator to validate operation status
14
+ */
15
+ class OperationStatusValidator
16
+ {
17
+ /**
18
+ * @var OperationStatusPool
19
+ */
20
+ protected $ operationStatusPool ;
21
+
22
+ /**
23
+ * OperationStatusValidator constructor.
24
+ *
25
+ * @param OperationStatusPool $operationStatusPool
26
+ */
27
+ public function __construct (OperationStatusPool $ operationStatusPool )
28
+ {
29
+ $ this ->operationStatusPool = $ operationStatusPool ;
30
+ }
31
+
32
+ /**
33
+ * Validate method
34
+ *
35
+ * @param $status
36
+ */
37
+ public function validate ($ status )
38
+ {
39
+ $ statuses = $ this ->operationStatusPool ->getStatuses ();
40
+
41
+ if (!in_array ($ status , $ statuses )) {
42
+ throw new \InvalidArgumentException ('Invalid Operation Status. ' );
43
+ }
44
+
45
+ return ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change 80
80
</argument >
81
81
</arguments >
82
82
</type >
83
+ <type name =" Magento\AsynchronousOperations\Model\OperationStatusPool" >
84
+ <arguments >
85
+ <argument name =" statuses" xsi : type =" array" >
86
+ <item name =" complete" xsi : type =" string" >1</item >
87
+ <item name =" retriablyFailed" xsi : type =" string" >2</item >
88
+ <item name =" notRetriablyFailed" xsi : type =" string" >3</item >
89
+ <item name =" open" xsi : type =" string" >4</item >
90
+ <item name =" rejected" xsi : type =" string" >5</item >
91
+ </argument >
92
+ </arguments >
93
+ </type >
83
94
<virtualType
84
95
name =" Magento\AsynchronousOperations\Ui\Component\DataProvider"
85
96
type =" Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" />
You can’t perform that action at this time.
0 commit comments