File tree Expand file tree Collapse file tree 4 files changed +72
-96
lines changed
src/Josser/Client/Transport
tests/Josser/Tests/Transport Expand file tree Collapse file tree 4 files changed +72
-96
lines changed Original file line number Diff line number Diff line change 1313 ],
1414 "require" : {
1515 "php" : " >=5.5.0" ,
16- "guzzlehttp/guzzle" : " ^6.0" ,
16+ "guzzlehttp/guzzle" : " ^5.0|^ 6.0" ,
1717 "symfony/serializer" : " ^2.0|^3.0"
1818 },
1919 "require-dev" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Josser package.
5+ *
6+ * (C) Alan Gabriel Bem <alan.bem@gmail.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Josser \Client \Transport ;
13+
14+ use GuzzleHttp \Client ;
15+ use Josser \Exception \TransportFailureException ;
16+
17+ /**
18+ * JSON-RPC http transport with Guzzle 5.
19+ *
20+ * @author Alan Gabriel Bem <alan.bem@gmail.com>
21+ */
22+ class Guzzle5Transport implements TransportInterface
23+ {
24+ /**
25+ * Guzzle http client.
26+ *
27+ * @var Client
28+ */
29+ private $ guzzle ;
30+
31+ /**
32+ * @param Client $guzzle
33+ */
34+ public function __construct (Client $ guzzle )
35+ {
36+ $ this ->guzzle = $ guzzle ;
37+ }
38+
39+ /**
40+ * @return Client
41+ */
42+ public function getGuzzle ()
43+ {
44+ return $ this ->guzzle ;
45+ }
46+
47+ /**
48+ * Send data to remote JSON-RPC service over HTTP.
49+ *
50+ * @throws \Josser\Exception\TransportFailureException
51+ * @param mixed $data
52+ * @return string
53+ */
54+ public function send ($ data )
55+ {
56+ try {
57+ $ response = $ this ->guzzle ->post (null , [
58+ 'body ' => $ data ,
59+ 'headers ' => [
60+ 'Content-Type ' => 'application/json ' ,
61+ ]
62+ ]);
63+ return $ response ->getBody ()->getContents ();
64+ } catch (\Exception $ e ) {
65+ $ error = sprintf ('JSON-RPC http connection failed. Remote service at "%s" is not responding. ' , $ this ->guzzle ->getBaseUrl ());
66+ throw new TransportFailureException ($ error , null , $ e );
67+ }
68+ }
69+ }
Original file line number Diff line number Diff line change 1515use Josser \Exception \TransportFailureException ;
1616
1717/**
18- * JSON-RPC http transport.
18+ * JSON-RPC http transport with Guzzle 6 .
1919 *
2020 * @author Alan Gabriel Bem <alan.bem@gmail.com>
2121 */
22- class HttpTransport implements TransportInterface
22+ class Guzzle6Transport implements TransportInterface
2323{
2424 /**
2525 * Guzzle http client.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments