Skip to content

Commit

Permalink
use build_object function to build object.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Mar 20, 2017
1 parent bedae2f commit d456c8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/ChangesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function changes($object)
return Converter::convertJsonPatchToMongoUpdate($diff);
}

unset($values['_id']);

return ['$set' => $values];
})->call($object);
}
Expand Down
20 changes: 6 additions & 14 deletions src/Hydrator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Makasim\Yadm;

use function Makasim\Values\build_object;
use function Makasim\Values\set_values;

class Hydrator
Expand All @@ -10,11 +11,6 @@ class Hydrator
*/
private $modelClass;

/**
* @var object
*/
private $prototypeModel;

/**
* @param string $modelClass
*/
Expand All @@ -24,17 +20,13 @@ public function __construct($modelClass)
}

/**
* @param array $values
*
* @return object
*/
public function create()
public function create(array $values = [])
{
if (false == $this->prototypeModel) {
$this->prototypeModel = new $this->modelClass();

$this->hydrate([], $this->prototypeModel);
}

return clone $this->prototypeModel;
return $this->hydrate($values, build_object($this->modelClass, $values));
}

/**
Expand All @@ -46,7 +38,7 @@ public function create()
*/
public function hydrate(array $values, $model = null)
{
$model = $model ?: $this->create();
$model = $model ?: $this->create($values);

if (isset($values['_id'])) {
$values['_id'] = (string) $values['_id'];
Expand Down

0 comments on commit d456c8f

Please sign in to comment.