11
11
use Magento \Framework \Exception \BulkException ;
12
12
use Magento \Webapi \Controller \Rest \RequestProcessorInterface ;
13
13
use Magento \Framework \Webapi \Rest \Response as RestResponse ;
14
- use Magento \Webapi \Controller \Rest \InputParamsResolver ;
14
+ use Magento \WebapiAsync \Controller \Rest \ Asynchronous \InputParamsResolver ;
15
15
use Magento \AsynchronousOperations \Model \MassSchedule ;
16
16
use Magento \AsynchronousOperations \Model \ConfigInterface as WebApiAsyncConfig ;
17
17
use Magento \Framework \Reflection \DataObjectProcessor ;
18
18
use Magento \AsynchronousOperations \Api \Data \AsyncResponseInterfaceFactory ;
19
19
use Magento \AsynchronousOperations \Api \Data \AsyncResponseInterface ;
20
20
21
+ /**
22
+ * Responsible for dispatching single and bulk requests.
23
+ * Single requests dispatching represented by this class.
24
+ * Bulk requests dispatching represented by virtualType of this class.
25
+ */
21
26
class AsynchronousRequestProcessor implements RequestProcessorInterface
22
27
{
23
28
const PROCESSOR_PATH = "/^ \\/async( \\/V.+)/ " ;
29
+ const BULK_PROCESSOR_PATH = "/^ \\/async\/bulk( \\/V.+)/ " ;
24
30
25
31
/**
26
32
* @var \Magento\Framework\Webapi\Rest\Response
27
33
*/
28
34
private $ response ;
29
-
30
35
/**
31
- * @var InputParamsResolver
36
+ * @var \Magento\WebapiAsync\Controller\Rest\Asynchronous\ InputParamsResolver
32
37
*/
33
38
private $ inputParamsResolver ;
34
-
35
39
/**
36
40
* @var MassSchedule
37
41
*/
38
42
private $ asyncBulkPublisher ;
39
-
40
43
/**
41
44
* @var WebApiAsyncConfig
42
45
*/
43
46
private $ webapiAsyncConfig ;
44
-
45
47
/**
46
48
* @var \Magento\Framework\Reflection\DataObjectProcessor
47
49
*/
48
50
private $ dataObjectProcessor ;
49
-
50
51
/**
51
52
* @var AsyncResponseInterfaceFactory
52
53
*/
53
54
private $ asyncResponseFactory ;
55
+ /**
56
+ * @var string Regex pattern
57
+ */
58
+ private $ processorPath ;
54
59
55
60
/**
56
61
* Initialize dependencies.
@@ -61,21 +66,24 @@ class AsynchronousRequestProcessor implements RequestProcessorInterface
61
66
* @param WebapiAsyncConfig $webapiAsyncConfig
62
67
* @param DataObjectProcessor $dataObjectProcessor
63
68
* @param AsyncResponseInterfaceFactory $asyncResponse
69
+ * @param string $processorPath
64
70
*/
65
71
public function __construct (
66
72
RestResponse $ response ,
67
73
InputParamsResolver $ inputParamsResolver ,
68
74
MassSchedule $ asyncBulkPublisher ,
69
75
WebApiAsyncConfig $ webapiAsyncConfig ,
70
76
DataObjectProcessor $ dataObjectProcessor ,
71
- AsyncResponseInterfaceFactory $ asyncResponse
77
+ AsyncResponseInterfaceFactory $ asyncResponse ,
78
+ $ processorPath = self ::PROCESSOR_PATH
72
79
) {
73
80
$ this ->response = $ response ;
74
81
$ this ->inputParamsResolver = $ inputParamsResolver ;
75
82
$ this ->asyncBulkPublisher = $ asyncBulkPublisher ;
76
83
$ this ->webapiAsyncConfig = $ webapiAsyncConfig ;
77
84
$ this ->dataObjectProcessor = $ dataObjectProcessor ;
78
85
$ this ->asyncResponseFactory = $ asyncResponse ;
86
+ $ this ->processorPath = $ processorPath ;
79
87
}
80
88
81
89
/**
@@ -84,12 +92,12 @@ public function __construct(
84
92
public function process (\Magento \Framework \Webapi \Rest \Request $ request )
85
93
{
86
94
$ path = $ request ->getPathInfo ();
87
- $ path = preg_replace (self :: PROCESSOR_PATH , "$1 " , $ path );
95
+ $ path = preg_replace ($ this -> processorPath , "$1 " , $ path );
88
96
$ request ->setPathInfo (
89
97
$ path
90
98
);
91
99
92
- $ entitiesParamsArray = [ $ this ->inputParamsResolver ->resolve ()] ;
100
+ $ entitiesParamsArray = $ this ->inputParamsResolver ->resolve ();
93
101
$ topicName = $ this ->getTopicName ($ request );
94
102
95
103
try {
@@ -133,7 +141,19 @@ public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
133
141
return false ;
134
142
}
135
143
136
- if (preg_match (self ::PROCESSOR_PATH , $ request ->getPathInfo ()) === 1 ) {
144
+ if (preg_match ($ this ->processorPath , $ request ->getPathInfo ()) === 1 ) {
145
+ return true ;
146
+ }
147
+ return false ;
148
+ }
149
+
150
+ /**
151
+ * @param \Magento\Framework\Webapi\Rest\Request $request
152
+ * @return bool
153
+ */
154
+ public function isBulk (\Magento \Framework \Webapi \Rest \Request $ request )
155
+ {
156
+ if (preg_match (self ::BULK_PROCESSOR_PATH , $ request ->getPathInfo ()) === 1 ) {
137
157
return true ;
138
158
}
139
159
return false ;
0 commit comments