示例#1
0
 public function testAddPropertyMappingWithName()
 {
     $metadata = new Metadata();
     $mapping = array('name' => 'some_property', 'type' => 'string');
     $metadata->addPropertyMapping('someProperty', $mapping);
     assertEquals($metadata->getPropertyMapping('someProperty'), $mapping);
 }
示例#2
0
 /**
  * @param object   $object
  * @param Metadata $metadata
  * @return array
  */
 public function toArray($object, Metadata $metadata)
 {
     $reflClass = new \ReflectionClass(get_class($object));
     $data = array();
     foreach ($reflClass->getProperties() as $property) {
         $mapping = $metadata->getPropertyMapping($property->getName());
         if (null == $mapping) {
             continue;
         }
         $property->setAccessible(true);
         if ($mapping['type'] == DataTypes::COLLECTION || DataTypes::HASH == $mapping['type']) {
             foreach ((array) $property->getValue($object) as $key => $value) {
                 $data[$mapping['name'] . ':' . $key] = $value;
             }
         } else {
             $data[$mapping['name']] = $this->reverseTransformValue($mapping['type'], $property->getValue($object));
         }
     }
     return $data;
 }
示例#3
0
 /**
  * @param ReflectionClass $reflClass
  * @param object          $object
  * @param string          $propertyName
  * @param Metadata        $metadata
  * @param array           $newData
  * @param MultiExec       $transaction
  */
 protected function handleSortedIndex(ReflectionClass $reflClass, $object, $propertyName, $keyName, Metadata $metadata, array $newData, $transaction)
 {
     $property = $reflClass->getProperty($propertyName);
     $property->setAccessible(true);
     $mapping = $metadata->getPropertyMapping($propertyName);
     if (!isset($newData[$mapping['name']]) || null === $newData[$mapping['name']]) {
         $transaction->zrem($this->keyNamingStrategy->getKeyName(array($keyName, $newData[$mapping['name']])), $this->getIdForClass($object, $metadata));
         return;
     }
     $transaction->zadd($this->keyNamingStrategy->getKeyName(array($keyName)), $newData[$mapping['name']], $this->getIdForClass($object, $metadata));
 }