/**
  * @param array $data
  * @param bool $fullHydration
  *
  * @return mixed|EntityModel
  *
  * @throws \RuntimeException
  */
 public final function create(array $data = [], bool $fullHydration = false) : EntityModel
 {
     $this->preCreate($data);
     $model = $this->hydrator->hydrate($this->className, $data, $fullHydration);
     $this->postCreate($model);
     return $model;
 }
Beispiel #2
0
 /**
  *
  * @param EntityModel $model
  * @return EntityModel
  *
  * @throws \RuntimeException
  */
 public function save(EntityModel $model) : EntityModel
 {
     if ($model instanceof EntityModel) {
         // TODO: test serializer, it doesn't work
         $data = $this->serializer->serialize($model);
         $collection = $this->getCollectionInstance();
         $result = $collection->insert($data);
         $model = $this->hydrator->hydrate($this->getModelClass(), $result, true);
     }
     return $model;
 }