コード例 #1
0
ファイル: MapTest.php プロジェクト: drakojn/io
 public function testGetData()
 {
     $object = new User();
     $object->setId(3);
     $object->setAlias('the-doctor');
     $object->setName('Tenth');
     $object->setEmail('*****@*****.**');
     $data = ['id' => 3, 'alias' => 'the-doctor', 'name' => 'Tenth', 'email' => '*****@*****.**'];
     $this->assertInternalType('array', $this->object->getData($object));
     $this->assertSame($data, $this->object->getData($object));
 }
コード例 #2
0
ファイル: Php.php プロジェクト: drakojn/io
 /**
  * Serializes Object
  *
  * @param Map    $map    the object structure map
  * @param object $object candidate to serialize
  *
  * @return mixed
  */
 public function serialize(Map $map, $object)
 {
     $identifier = $map->getIdentifier();
     $data = $map->getData($object);
     if (!isset($data[$identifier]) || !$data[$identifier]) {
         $id = spl_object_hash($object);
         $reflection = new \ReflectionProperty($map->getLocalName(), $identifier);
         $reflection->setAccessible(true);
         $reflection->setValue($object, $id);
     }
     return serialize($object);
 }