@@ -32,42 +32,75 @@ class LogData
32
32
* @param HttpResponse|null $response
33
33
* @return array
34
34
*/
35
- public function getRequestInformation (
35
+ public function getLogData (
36
36
RequestInterface $ request ,
37
37
array $ data ,
38
- Schema $ schema = null ,
39
- HttpResponse $ response = null
38
+ ? Schema $ schema ,
39
+ ? HttpResponse $ response
40
40
) : array {
41
- $ requestInformation = [];
41
+ $ logData = [];
42
+ $ logData = array_merge ($ logData , $ this ->gatherRequestInformation ($ request ));
43
+ if ($ schema ) {
44
+ $ logData = array_merge ($ logData , $ this ->gatherQueryInformation ($ schema ));
45
+ }
46
+ $ logData [LoggerInterface::COMPLEXITY ] = $ this ->getFieldCount ($ data ['query ' ] ?? '' );
47
+ if ($ response ) {
48
+ $ logData = array_merge ($ logData , $ this ->gatherResponseInformation ($ response ));
49
+ }
50
+
51
+ return $ logData ;
52
+ }
53
+
54
+ /**
55
+ * Gets the information needed from the request
56
+ *
57
+ * @param RequestInterface $request
58
+ * @return array
59
+ */
60
+ private function gatherRequestInformation (RequestInterface $ request ) : array
61
+ {
42
62
$ requestInformation [LoggerInterface::HTTP_METHOD ] = $ request ->getMethod ();
43
63
$ requestInformation [LoggerInterface::STORE_HEADER ] = $ request ->getHeader ('Store ' ) ?: '' ;
44
64
$ requestInformation [LoggerInterface::CURRENCY_HEADER ] = $ request ->getHeader ('Currency ' ) ?: '' ;
45
65
$ requestInformation [LoggerInterface::HAS_AUTH_HEADER ] = $ request ->getHeader ('Authorization ' ) ? 'true ' : 'false ' ;
46
- $ requestInformation [LoggerInterface::IS_CACHEABLE ] =
47
- ($ response ->getHeader ('X-Magento-Tags ' ) && $ response ->getHeader ('X-Magento-Tags ' ) !== '' )
48
- ? 'true '
49
- : 'false ' ;
50
66
$ requestInformation [LoggerInterface::REQUEST_LENGTH ] = $ request ->getHeader ('Content-Length ' ) ?: '' ;
67
+ return $ requestInformation ;
68
+ }
51
69
52
- if ($ schema ) {
53
- $ schemaConfig = $ schema ->getConfig ();
54
- $ mutationOperations = $ schemaConfig ->getMutation ()->getFields ();
55
- $ queryOperations = $ schemaConfig ->getQuery ()->getFields ();
56
- $ requestInformation [LoggerInterface::HAS_MUTATION ] = count ($ mutationOperations ) > 0 ? 'true ' : 'false ' ;
57
- $ requestInformation [LoggerInterface::NUMBER_OF_OPERATIONS ] =
58
- count ($ mutationOperations ) + count ($ queryOperations );
59
- $ operationNames = array_merge (array_keys ($ mutationOperations ), array_keys ($ queryOperations ));
60
- $ requestInformation [LoggerInterface::OPERATION_NAMES ] =
61
- count ($ operationNames ) > 0 ? implode (", " , $ operationNames ) : 'operationNameNotFound ' ;
62
- }
63
-
64
- $ requestInformation [LoggerInterface::COMPLEXITY ] = $ this ->getFieldCount ($ data ['query ' ] ?? '' );
65
-
66
- if ($ response ) {
67
- $ requestInformation [LoggerInterface::HTTP_RESPONSE_CODE ] = $ response ->getHttpResponseCode ();
68
- }
70
+ /**
71
+ * Gets the information needed from the schema
72
+ *
73
+ * @param Schema $schema
74
+ * @return array
75
+ */
76
+ private function gatherQueryInformation (Schema $ schema ) : array
77
+ {
78
+ $ schemaConfig = $ schema ->getConfig ();
79
+ $ mutationOperations = $ schemaConfig ->getMutation ()->getFields ();
80
+ $ queryOperations = $ schemaConfig ->getQuery ()->getFields ();
81
+ $ queryInformation [LoggerInterface::HAS_MUTATION ] = count ($ mutationOperations ) > 0 ? 'true ' : 'false ' ;
82
+ $ queryInformation [LoggerInterface::NUMBER_OF_OPERATIONS ] =
83
+ count ($ mutationOperations ) + count ($ queryOperations );
84
+ $ operationNames = array_merge (array_keys ($ mutationOperations ), array_keys ($ queryOperations ));
85
+ $ queryInformation [LoggerInterface::OPERATION_NAMES ] =
86
+ count ($ operationNames ) > 0 ? implode (", " , $ operationNames ) : 'operationNameNotFound ' ;
87
+ return $ queryInformation ;
88
+ }
69
89
70
- return $ requestInformation ;
90
+ /**
91
+ * Gets the information needed from the response
92
+ *
93
+ * @param HttpResponse $response
94
+ * @return array
95
+ */
96
+ private function gatherResponseInformation (HttpResponse $ response ) : array
97
+ {
98
+ $ responseInformation [LoggerInterface::IS_CACHEABLE ] =
99
+ ($ response ->getHeader ('X-Magento-Tags ' ) && $ response ->getHeader ('X-Magento-Tags ' ) !== '' )
100
+ ? 'true '
101
+ : 'false ' ;
102
+ $ responseInformation [LoggerInterface::HTTP_RESPONSE_CODE ] = $ response ->getHttpResponseCode ();
103
+ return $ responseInformation ;
71
104
}
72
105
73
106
/**
0 commit comments