@@ -29,36 +29,38 @@ public function __construct($request)
29
29
}
30
30
31
31
/**
32
- * Returns the payload from a guzzle request.
32
+ * Generates a payload with the provided properties
33
33
*
34
- * @param \Psr\Http\Message\RequestInterface $request
35
- * An instance of the guzzle request to extract a payload from.
34
+ * @param string $identifier
35
+ * @param string $method
36
+ * @param string $timestamp
37
+ * @param string $uri
38
+ * @param string $content
36
39
*
37
40
* @return string
38
- * The payload.
39
41
*/
40
- protected function generateFromPsr7Request ( Psr7Request $ request ) : string
41
- {
42
- $ id = isset ( $ this -> request -> getHeader ( ' X-SIGNED-ID ' )[ 0 ]) ?
43
- $ this -> request -> getHeader ( ' X-SIGNED-ID ' )[ 0 ] : '' ;
44
- $ timestamp = isset ( $ this -> request -> getHeader ( ' X-SIGNED-TIMESTAMP ' )[ 0 ]) ?
45
- $ this -> request -> getHeader ( ' X-SIGNED-TIMESTAMP ' )[ 0 ] : '' ;
46
-
42
+ private function generate (
43
+ string $ identifier ,
44
+ string $ method ,
45
+ string $ timestamp ,
46
+ string $ uri ,
47
+ string $ content
48
+ ) : string {
47
49
$ payload = [
48
- 'id ' => ( string ) $ id ,
49
- 'method ' => strtoupper ($ this -> request -> getMethod () ),
50
+ 'id ' => $ identifier ,
51
+ 'method ' => strtoupper ($ method ),
50
52
'timestamp ' => $ timestamp ,
51
- 'uri ' => rtrim (( string ) $ this -> request -> getUri () , '/ ' )
53
+ 'uri ' => rtrim ($ uri , '/ ' )
52
54
];
53
55
54
- if (is_null (json_decode (( string ) $ this -> request -> getBody () ))) {
56
+ if (is_null (json_decode ($ content ))) {
55
57
$ payload = array_merge ($ payload , [
56
- 'content ' => ( string ) $ this -> request -> getBody ()
58
+ 'content ' => $ content
57
59
]);
58
60
} else {
59
61
$ payload = array_merge ($ payload , [
60
62
'content ' => json_encode (
61
- json_decode (( string ) $ this -> request -> getBody () ),
63
+ json_decode ($ content ),
62
64
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
63
65
)
64
66
]);
@@ -67,6 +69,31 @@ protected function generateFromPsr7Request(Psr7Request $request) : string
67
69
return json_encode ($ payload , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
68
70
}
69
71
72
+ /**
73
+ * Returns the payload from a guzzle request.
74
+ *
75
+ * @param \Psr\Http\Message\RequestInterface $request
76
+ * An instance of the guzzle request to extract a payload from.
77
+ *
78
+ * @return string
79
+ * The payload.
80
+ */
81
+ protected function generateFromPsr7Request (Psr7Request $ request ) : string
82
+ {
83
+ $ id = isset ($ this ->request ->getHeader ('X-SIGNED-ID ' )[0 ]) ?
84
+ $ this ->request ->getHeader ('X-SIGNED-ID ' )[0 ] : '' ;
85
+ $ timestamp = isset ($ this ->request ->getHeader ('X-SIGNED-TIMESTAMP ' )[0 ]) ?
86
+ $ this ->request ->getHeader ('X-SIGNED-TIMESTAMP ' )[0 ] : '' ;
87
+
88
+ return $ this ->generate (
89
+ (string ) $ id ,
90
+ (string ) $ this ->request ->getMethod (),
91
+ (string ) $ timestamp ,
92
+ (string ) $ this ->request ->getUri (),
93
+ (string ) $ this ->request ->getBody ()
94
+ );
95
+ }
96
+
70
97
/**
71
98
* Retruns the payload from an illuminate request.
72
99
*
@@ -81,27 +108,13 @@ protected function generateFromIlluminateRequest(IlluminateRequest $request) : s
81
108
$ id = $ this ->request ->headers ->get ('X-SIGNED-ID ' , '' );
82
109
$ timestamp = $ this ->request ->headers ->get ('X-SIGNED-TIMESTAMP ' , '' );
83
110
84
- $ payload = [
85
- 'id ' => (string ) $ id ,
86
- 'method ' => strtoupper ($ this ->request ->getMethod ()),
87
- 'timestamp ' => $ timestamp ,
88
- 'uri ' => rtrim ((string ) $ this ->request ->fullUrl (), '/ ' ),
89
- ];
90
-
91
- if (is_null (json_decode ((string ) $ this ->request ->getContent ()))) {
92
- $ payload = array_merge ($ payload , [
93
- 'content ' => (string ) $ this ->request ->getContent ()
94
- ]);
95
- } else {
96
- $ payload = array_merge ($ payload , [
97
- 'content ' => json_encode (
98
- json_decode ((string )$ this ->request ->getContent ()),
99
- JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
100
- )
101
- ]);
102
- }
103
-
104
- return json_encode ($ payload , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
111
+ return $ this ->generate (
112
+ (string ) $ id ,
113
+ (string ) $ this ->request ->getMethod (),
114
+ (string ) $ timestamp ,
115
+ (string ) $ this ->request ->fullUrl (),
116
+ (string ) $ this ->request ->getContent ()
117
+ );
105
118
}
106
119
107
120
/**
0 commit comments