Created
October 29, 2013 12:48
-
-
Save pschultz/7214036 to your computer and use it in GitHub Desktop.
guzzle responseClass example
This file contains 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 | |
namespace Classmarkets\Api; | |
use Guzzle\Service\Command\OperationCommand; | |
class ItemCollection extends \Doctrine\Common\Collections\ArrayCollection | |
{ | |
// This is the method Guzzle is looking for | |
public static function fromCommand(OperationCommand $command) | |
{ | |
$response = $command->getResponse(); | |
$data = $response->json(); // if you are not receiving json, there is a way of getting the raw response. Check the docs | |
return self::fromArray($data); | |
} | |
public static function fromArray(array $data) | |
{ | |
$collection = new self(); | |
// assign $collection's with values in $data | |
return $collection | |
} | |
} |
This file contains 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
name: Item | |
operations: | |
Search: | |
httpMethod: GET | |
uri: /search | |
responseClass: Classmarkets\Api\ItemCollection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment