예제 #1
0
파일: Ini.php 프로젝트: drakojn/io
 /**
  * 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);
 }
예제 #2
0
파일: Json.php 프로젝트: drakojn/io
 /**
  * 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);
 }
예제 #3
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);
 }
예제 #4
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;
 }
예제 #5
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;
 }
예제 #6
0
파일: MapTest.php 프로젝트: drakojn/io
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage $object argument is not a object
  */
 public function testValidateObjectWithAWrongType()
 {
     $wrongType = ['wrong' => 'type'];
     $this->object->validateObject($wrongType);
 }
예제 #7
0
파일: Mapper.php 프로젝트: drakojn/io
 public function findByIdentifier($identifierQuery)
 {
     $identifier = $this->map->getIdentifier();
     return current($this->driver->find($this, [$identifier => $identifierQuery]));
 }