From ae8fe9c91f0971fa518369ea39b235f297e1bbdc Mon Sep 17 00:00:00 2001 From: Adam Segal Date: Fri, 8 May 2015 16:20:26 -0700 Subject: [PATCH 1/2] Updated package to use Guzzle 5. --- composer.json | 2 +- .../Hmvc/Commands/HmvcCallCommand.php | 2 +- src/Teepluss/Hmvc/Hmvc.php | 50 ++++++++++++------- src/Teepluss/Hmvc/HmvcServiceProvider.php | 2 +- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 9db9021..359b630 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=5.3.0", - "guzzle/guzzle": "3.9.1" + "guzzlehttp/guzzle": "5.0.*@dev" }, "require-dev": { "illuminate/support": "4.1.x" diff --git a/src/Teepluss/Hmvc/Commands/HmvcCallCommand.php b/src/Teepluss/Hmvc/Commands/HmvcCallCommand.php index 9ed4d44..c9ea0ed 100644 --- a/src/Teepluss/Hmvc/Commands/HmvcCallCommand.php +++ b/src/Teepluss/Hmvc/Commands/HmvcCallCommand.php @@ -65,7 +65,7 @@ public function fire() parse_str($parameters, $parameters); } - // User credentails. + // User credentials. $auth = $this->option('user'); if ($auth) diff --git a/src/Teepluss/Hmvc/Hmvc.php b/src/Teepluss/Hmvc/Hmvc.php index bce1987..0845b13 100644 --- a/src/Teepluss/Hmvc/Hmvc.php +++ b/src/Teepluss/Hmvc/Hmvc.php @@ -1,6 +1,6 @@ remoteClient, 'setDefaultOption'), array($option, $value)); } - - //sd($this->remoteClient); - return $this; } @@ -169,28 +168,42 @@ public function configureRemoteClient($configurations) * * @param string $uri * @param string $method - * @param array $parameters + * @param array $parameters = [[data], [options]] * @return mixed */ public function invokeRemote($uri, $method = 'GET', $parameters = array()) { $remoteClient = $this->getRemoteClient(); - // Make request. - $request = call_user_func_array(array($remoteClient, $method), array($uri, null, $parameters)); + //to maintain compatibility, data is the first parameter value + list($data, $options) = array_merge($parameters, [], []); + if (!empty($data)) { + if (($method == "GET") && !isset($options['query'])) { + $options['query'] = $data; + } elseif (!isset($options['body']) && !isset($options['json'])) { + $options['body'] = $data; + } + } + if (!isset($options['verify'])) { + $options['verify'] = false; + } - // Ignore all SSL case. - $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false); - $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false); + + // Make request. + $request = $remoteClient->createRequest($method, $uri, $options); // Send request. - $response = $request->send(); + $response = $remoteClient->send($request); - // Body responsed. + if (isset($options['future']) && $options['future'] == true) { + return $response; + } + + // Body response. $body = (string) $response->getBody(); // Decode json content. - if ($response->getContentType() == 'application/json') + if ($response->getHeader('Content-Type') == 'application/json') { if (function_exists('json_decode') and is_string($body)) { @@ -212,14 +225,15 @@ public function __call($method, $parameters = array()) { $uri = array_shift($parameters); - $parameters = current($parameters); - $parameters = is_array($parameters) ? $parameters : array(); - if (preg_match('/^http(s)?/', $uri)) { + $method = strtoupper($method); return $this->invokeRemote($uri, $method, $parameters); } + $parameters = current($parameters); + $parameters = is_array($parameters) ? $parameters : array(); + return $this->invoke($uri, $method, $parameters); } } diff --git a/src/Teepluss/Hmvc/HmvcServiceProvider.php b/src/Teepluss/Hmvc/HmvcServiceProvider.php index 103bfb7..bbd29eb 100644 --- a/src/Teepluss/Hmvc/HmvcServiceProvider.php +++ b/src/Teepluss/Hmvc/HmvcServiceProvider.php @@ -1,6 +1,6 @@ Date: Wed, 5 Aug 2015 19:08:53 -0700 Subject: [PATCH 2/2] Update guzzle from 5 to 5.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 359b630..50380df 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=5.3.0", - "guzzlehttp/guzzle": "5.0.*@dev" + "guzzlehttp/guzzle": "5.3.*@dev" }, "require-dev": { "illuminate/support": "4.1.x"