Ejemplo n.º 1
0
 /**
  * @param AbstractEntity $entity
  * @return AbstractEntity
  * @throws \Edefine\Framework\Database\DatabaseException
  */
 private function updateEntity(AbstractEntity $entity)
 {
     $updateParts = [];
     foreach ($entity->getMappedFieldsWithValues() as $field => $value) {
         $updateParts[] = sprintf('`%s` = %s', $field, ValueConverter::convertToDatabase($value));
     }
     $result = $this->database->exec(sprintf('UPDATE `%s` SET %s WHERE `id` = %d', $entity->getTableName(), implode(', ', $updateParts), $entity->getId()));
     return $entity;
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return AbstractEntity
  */
 protected function mapToEntity(array $data)
 {
     /** @var AbstractEntity $entity */
     $entity = new $this->entityClass();
     foreach ($entity->getMappedFields() as $field) {
         $value = ValueConverter::convertToEntity($entity, $field, $data[$field]);
         $setter = 'set' . ucfirst($field);
         $entity->{$setter}($value);
     }
     return $entity;
 }
Ejemplo n.º 3
0
 public function testConvertToEntity()
 {
     $entity = new FakeEntity();
     $this->assertEquals('test', ValueConverter::convertToEntity($entity, 'baz', 'test'));
     $this->assertEquals(new \DateTime('2015-01-02 03:04:05'), ValueConverter::convertToEntity($entity, 'bar', '2015-01-02 03:04:05'));
 }