33 lines
830 B
PHP
Executable File
33 lines
830 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Traits;
|
|
use GuzzleHttp\Client;
|
|
|
|
trait ConsumesExternalService
|
|
{
|
|
/**
|
|
* Envoie une requete a un service
|
|
* @param $method
|
|
* @param $requestUrl
|
|
* @param array $body
|
|
* @param array $formParams
|
|
* @param array $headers
|
|
* @return string
|
|
*/
|
|
public function perfomRequest($method, $requestUrl, $body = [], $headers = [], $formParams = [])
|
|
{
|
|
$client = new Client([
|
|
'base_uri' => $this->baseUri,
|
|
]);
|
|
|
|
if(isset($this->key)){
|
|
unset($headers['authorization']);
|
|
$headers['Authorization'] = $this->key;
|
|
}
|
|
|
|
$response = $client->request($method , $requestUrl , ['json'=> $body , 'form_params' => $formParams , 'headers' => $headers] );
|
|
|
|
return $response->getBody()->getContents();
|
|
}
|
|
}
|