Skip to content

Commit

Permalink
Merge pull request #320 from GrahamCampbell/2.1-fixes
Browse files Browse the repository at this point in the history
Fixed the logic to move to the saved array
  • Loading branch information
GrahamCampbell committed Sep 7, 2014
2 parents f756075 + bd0beef commit af343d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,24 @@ public static function add(&$array, $object)
*/
public static function remove(&$array, $object)
{
if (in_array($object, $array, true)) {
unset($array[spl_object_hash($object)]);
}
unset($array[spl_object_hash($object)]);
}

/**
* Move an object to another array.
*
* @param array $old
* @param array $new
* @param object $object
*
* @return void
*/
public static function move(&$old, &$new, $object)
{
$hash = spl_object_hash($object);

unset($old[$hash]);

$new[$hash] = $object;
}
}
5 changes: 3 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ private function persist($object)
throw new SaveFailedException(get_class($object));
}

Arr::add($this->saved, $object);
Arr::remove($this->pending, $object);
if (!$this->isSaved($object)) {
Arr::move($this->pending, $this->saved, $object);
}
}

/**
Expand Down

0 comments on commit af343d5

Please sign in to comment.