guzzle/guzzle — pull request #380 by mtdowling (2013-07-13 20:33:17+00:00)
Title: Custom responseClass creation through the operation.parse_class event

This PR attempts to address #375 in a way that does not require custom domain specific objects to be implemented in any specific way. If you need to create custom domain specific objects to create a custom responseClass object from a command result, you can listen to the `operation.parse_class` event of a client object. The listener should call the `setResult()` method of the event to set the create object and automatically stop event propagation. This gives the added flexibility of registering multiple listeners that can defer creation to the next listener.

So here's an example of how you'd register a listener to create custom domain specific objects:

```php
$client = new Client();
$client->setDescription(ServiceDescription::factory(array(
'operations' => array('test' => array('responseClass' => 'FooBazBar'))
)));
$foo = new \stdClass();
$client->getEventDispatcher()->addListener('operation.parse_class', function ($e) {
// Determine what to actually create for the command
if ($e['command']->getName() == 'test') {
$e->setResult(createTheObject($e['command']));
}
});
```

Any thoughts on this vs #375?