public function testRecursion() { $a = new A(); $b = new B(); $a->b = $b; $b->a = $a; $packer = new Packer(new NullObjectPacker()); $c = $packer->pack($a); $this->assertTrue($c instanceof A); $this->assertTrue($c->b instanceof B); $this->assertFalse($c === $a); $this->assertFalse($c->b === $b); $this->assertTrue($c->b->a === $c); }
/** * {@inheritdoc} */ public function synchronize($key, callable $function) { $id = $this->getId(); $lockContext = true; $serialized = $this->storage->read($id, $key, $lockContext); try { $value = $serialized !== null ? $this->packer->unserialize($serialized) : null; $value = $function($value); $serialized = $this->packer->serialize($value); } catch (\Exception $e) { $this->storage->unlock($lockContext); throw $e; } $this->storage->write($id, $key, $serialized, $lockContext); return $this->data[$key] = $value; }