Created
June 27, 2017 11:54
-
-
Save leitom/127e7670b075cca3d6009c8a5a10583b to your computer and use it in GitHub Desktop.
Zonda?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait Http | |
{ | |
function wrapGuzzle($guzzle) | |
{ | |
return new class($guzzle) { | |
private $guzzle; | |
public function __construct($guzzle) | |
{ | |
$this->guzzle = $guzzle; | |
} | |
public function __call($method, $arguments) | |
{ | |
$response = call_user_func_array([$this->guzzle, $method], $arguments); | |
if (in_array($method, ['get', 'post', 'delete', 'put', 'patch'])) { | |
return json_decode((string) $response->getBody(), true); | |
} | |
return $response; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment