Ejemplo n.º 1
0
Archivo: Php.php Proyecto: 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);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }
Ejemplo n.º 4
0
 public function testGetLocalName()
 {
     $name = 'Dummy\\Data\\User';
     $this->assertEquals($name, $this->object->getLocalName());
     $this->assertInternalType('string', $this->object->getLocalName());
 }