Ejemplo n.º 1
0
 /**
  * @param mixed
  * @param string
  * @param IEntity
  * @return scalar|NULL|DateTime
  * @throws MapperPersistenceException
  */
 protected function scalarizeValue($value, $key, IEntity $entity)
 {
     if ($value instanceof IEntityInjection) {
         $value = $value->getInjectedValue();
     }
     if ($value instanceof IEntity) {
         $value = $value->id;
     } else {
         if (is_array($value) or $value instanceof ArrayObject and get_class($value) == 'ArrayObject') {
             $value = serialize($value);
             // todo zkontrolovat jestli je jednodimenzni a neobrahuje zadne nesmysly
         } else {
             if (is_object($value) and method_exists($value, '__toString')) {
                 $value = $value->__toString();
             } else {
                 if ($value !== NULL and !$value instanceof DateTime and !is_scalar($value)) {
                     $mapper = $entity->getRepository(false) ? $entity->getRepository()->getMapper() : $this;
                     throw new MapperPersistenceException(array($mapper, $entity, $key, $value));
                 }
             }
         }
     }
     return $value;
 }