1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 18:13:00 +01:00

[Service] Using the Serializable interface on Guzzle\Service\ServiceBuilder. Closes #41

This commit is contained in:
Michael Dowling 2012-04-20 21:47:03 -07:00
parent 72a86e86c9
commit cbf125fd0f
2 changed files with 16 additions and 5 deletions

View File

@ -6,7 +6,7 @@ namespace Guzzle\Service;
* Service builder to generate service builders and service clients from
* configuration settings
*/
class ServiceBuilder implements \ArrayAccess
class ServiceBuilder implements \ArrayAccess, \Serializable
{
/**
* @var array Service builder configuration data
@ -102,13 +102,23 @@ class ServiceBuilder implements \ArrayAccess
}
/**
* Magic method to allow serialization to support caching
* Restores the service builder from JSON
*
* @param string $serialized JSON data to restore from
*/
public function unserialize($serialized)
{
$this->builderConfig = json_decode($serialized, true);
}
/**
* Represents the service builder as a string
*
* @return array
*/
public function __sleep()
public function serialize()
{
return array('builderConfig');
return json_encode($this->builderConfig);
}
/**

View File

@ -73,7 +73,8 @@ EOT;
}
/**
* @covers Guzzle\Service\ServiceBuilder::__sleep
* @covers Guzzle\Service\ServiceBuilder::serialize
* @covers Guzzle\Service\ServiceBuilder::unserialize
*/
public function testAllowsSerialization()
{