diff --git a/src/HPCloud/Services/IdentityServices.php b/src/HPCloud/Services/IdentityServices.php index 492e03f..ac103d4 100644 --- a/src/HPCloud/Services/IdentityServices.php +++ b/src/HPCloud/Services/IdentityServices.php @@ -122,9 +122,14 @@ namespace HPCloud\Services; * - tenants() * - rescope() * + * Serializing + * + * IdentityServices has been intentionally built to serialize well. + * This allows implementors to cache IdentityServices objects rather + * than make repeated requests for identity information. * */ -class IdentityServices { +class IdentityServices /*implements Serializable*/ { /** * The version of the API currently supported. */ @@ -171,6 +176,8 @@ class IdentityServices { */ protected $catalog = array(); + protected $userDetails; + /** * Build a new IdentityServices object. * @@ -687,6 +694,7 @@ class IdentityServices { /** * @see HPCloud::Services::IdentityServices::rescopeUsingTenantId() + * @deprecated */ public function rescope($tenantId) { return $this->rescopeUsingTenantId($tenantId); @@ -824,4 +832,24 @@ class IdentityServices { $this->serviceCatalog = $json['access']['serviceCatalog']; } + /* Not necessary. + public function serialize() { + $data = array( + 'tokenDetails' => $this->tokenDetails, + 'userDetails' => $this->userDetails, + 'serviceCatalog' => $this->serviceCatalog, + 'endpoint' => $this->endpoint, + ); + return serialize($data); + } + + public function unserialize($data) { + $vals = unserialize($data); + $this->tokenDetails = $vals['tokenDetails']; + $this->userDetails = $vals['userDetails']; + $this->serviceCatalog = $vals['serviceCatalog']; + $this->endpoint = $vals['endpoint']; + } + */ + } diff --git a/test/Tests/IdentityServicesTest.php b/test/Tests/IdentityServicesTest.php index d624e04..29e0761 100644 --- a/test/Tests/IdentityServicesTest.php +++ b/test/Tests/IdentityServicesTest.php @@ -314,6 +314,33 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase { $this->assertNotEmpty($user['roles']); } + /** + * @depends testAuthenticateAsAccount + * @group serialize + */ + public function testSerialization($service) { + + $ser = serialize($service); + + $this->assertNotEmpty($ser); + + $again = unserialize($ser); + + $this->assertInstanceOf('\HPCloud\Services\IdentityServices', $again); + + $this->assertEquals($service->tenantId(), $again->tenantId()); + $this->assertEquals($service->serviceCatalog(), $again->serviceCatalog()); + $this->assertEquals($service->tokenDetails(), $again->tokenDetails()); + $this->assertEquals($service->user(), $again->user()); + $this->assertFalse($again->isExpired()); + + $tenantId = $again->tenantId(); + + $newTok = $again->rescopeUsingTenantId($tenantId); + + $this->assertNotEmpty($newTok); + } + /** * @group tenant */