GuzzleCommandClient
This Symfony 2 bundle implements Guzzle Commands
https://github.com/guzzle/command
Installing
This project can be installed using Composer. Add the following to your composer.json:
{
"require": {
"asgoodasnu/guzzlecommandclient": "dev-master"
}
}
Defining services
Create a json file defining the different operations available, for example:
{
"name": "My Service name",
"baseUrl": "",
"operations": {
"myOperationName": {
"httpMethod": "GET",
"uri": "/api/getProduct/{id}.{format}",
"summary": "Retrieve all products",
"responseClass": "MyModelResponse",
"parameters": {
"format": {
"default": "json",
"location": "uri"
},
"id": {
"type": "string",
"required": "true",
"location": "uri"
}
}
}
},
"models": {
"MyModelResponse": {
"type": "object"
}
}
}
Using it
$json = file_get_contents(path/to/json/file");
$guzzleCommandClient = new GuzzleCommandClient($json);
$guzzleCommandClient->setBaseUrl($imageServiceEndpoint);
$params = array(
'id' => '12345',
);
$result = $guzzleCommandClient->executeCommand('myOperationName', $params);
if ($result['status'] == 'error') {
// Show the error
return;
}
if (is_object($result['message'])) {
// Deal with the response object
return $result['message']->json();
}
return $result['message'];

