2
2
3
3
namespace Ivan770 \HttpClient ;
4
4
5
+ use Ivan770 \HttpClient \Exceptions \PipelineNotAvailable ;
5
6
use Symfony \Component \HttpClient \Exception \JsonException ;
7
+ use Illuminate \Pipeline \Pipeline ;
6
8
7
9
/**
8
10
* @method int getStatusCode() Get response status code
@@ -14,11 +16,30 @@ class Response
14
16
{
15
17
protected $ baseResponse ;
16
18
19
+ protected $ pipeline ;
20
+
17
21
public function __construct ($ baseResponse )
18
22
{
19
23
$ this ->baseResponse = $ baseResponse ;
20
24
}
21
25
26
+ protected function pipelineAvailable ()
27
+ {
28
+ //TODO: Remove pipeline vendor lock.
29
+ if (class_exists (Pipeline::class)) {
30
+ return true ;
31
+ }
32
+ throw new PipelineNotAvailable ("Pipeline class cannot be found " );
33
+ }
34
+
35
+ protected function getPipeline ()
36
+ {
37
+ if ($ this ->pipelineAvailable () && is_null ($ this ->pipeline )) {
38
+ $ this ->pipeline = new Pipeline ();
39
+ }
40
+ return $ this ->pipeline ;
41
+ }
42
+
22
43
/**
23
44
* Create collection from response
24
45
*
@@ -44,6 +65,26 @@ public function getContent($throw = true)
44
65
}
45
66
}
46
67
68
+ /**
69
+ * Pass response content to function
70
+ *
71
+ * @param \Closure $function Function to call
72
+ */
73
+ public function then ($ function )
74
+ {
75
+ return $ function ->call ($ this , $ this ->getContent ());
76
+ }
77
+
78
+ /**
79
+ * Pass response content to pipeline
80
+ *
81
+ * @return Pipeline
82
+ */
83
+ public function pipeline ()
84
+ {
85
+ return $ this ->getPipeline ()->send ($ this ->getContent ());
86
+ }
87
+
47
88
public function __call ($ name , $ arguments )
48
89
{
49
90
return $ this ->baseResponse ->$ name (...$ arguments );
0 commit comments