/** * 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); }
/** * 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); }
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; }
/** * @param Mapper\Map $map * @param $data * * @return bool */ protected function write(Mapper\Map $map, $data) { $reflectionProperty = new \ReflectionProperty($map->getLocalName(), $map->getIdentifier()); $reflectionProperty->setAccessible(true); $identifier = $reflectionProperty->getValue($data); $new = false; if (!$identifier) { $identifier = spl_object_hash($data); $new = true; } $uri = $this->buildUri($map->getRemoteName()) . '/' . $identifier; $result = (bool) file_put_contents($uri, $this->descriptor->serialize($map, $data), false, $this->context ?: null); if ($result && $new) { $reflectionProperty->setValue($data, $identifier); } return $result; }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage $object argument is not a object */ public function testValidateObjectWithAWrongType() { $wrongType = ['wrong' => 'type']; $this->object->validateObject($wrongType); }
public function findByIdentifier($identifierQuery) { $identifier = $this->map->getIdentifier(); return current($this->driver->find($this, [$identifier => $identifierQuery])); }