コード例 #1
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);
 }
コード例 #2
0
ファイル: Stream.php プロジェクト: drakojn/io
 /**
  * @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;
 }
コード例 #3
0
ファイル: MapTest.php プロジェクト: drakojn/io
 public function testGetIdentifier()
 {
     $identifier = 'id';
     $this->assertEquals($identifier, $this->object->getIdentifier());
     $this->assertInternalType('string', $this->object->getIdentifier());
 }
コード例 #4
0
ファイル: Mapper.php プロジェクト: drakojn/io
 public function findByIdentifier($identifierQuery)
 {
     $identifier = $this->map->getIdentifier();
     return current($this->driver->find($this, [$identifier => $identifierQuery]));
 }