/** * Serializes Object * * @param Map $map the object structure map * @param mixed $object candidate to serialize * * @return mixed */ public function serialize(Map $map, $object) { $properties = $map->getProperties(); $data = $this->prepareData($map, $object); $content = []; foreach ($data as $localProperty => $value) { $value = serialize($value); $content[] = "{$properties[$localProperty]}='{$value}'"; } return implode(PHP_EOL, $content); }
/** * Serializes Object * * @param Map $map the object structure map * @param mixed $object candidate to serialize * * @return mixed */ public function serialize(Map $map, $object) { $properties = $map->getProperties(); $data = $this->prepareData($map, $object); $content = []; foreach ($data as $localProperty => $value) { $value = serialize($value); $content[$properties[$localProperty]] = $value; } return json_encode((object) $content); }
public function injectDataIntoObject(Map $map, array $data) { $reflection = new \ReflectionClass($map->getLocalName()); $object = $reflection->newInstance(); $localProperties = $map->getProperties(); foreach ($localProperties as $localProperty => $remoteProperty) { $value = unserialize($data[$remoteProperty]); $reflectedProperty = $reflection->getProperty($localProperty); $reflectedProperty->setAccessible(true); $reflectedProperty->setValue($object, $value); } return $object; }
public function testGetProperties() { $this->assertInternalType('array', $this->object->getProperties()); $this->assertArrayHasKey('id', $this->object->getProperties()); $this->assertArrayNotHasKey('password', $this->object->getProperties()); }