Skip to content

Commit 58f1088

Browse files
committed
Merge pull request #2 from equip/feature/diffable-entity-trait
Add DiffableEntityTrait
2 parents 44ca8cb + 0cc41c5 commit 58f1088

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Traits/DiffableEntityTrait.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Equip\Data\Traits;
4+
5+
/**
6+
* Intended to be used by classes implementing Equip\Data\EntityInterface that
7+
* also need to implement Equip\Data\DiffableInterface.
8+
*/
9+
trait DiffableEntityTrait /* implements DiffableInterface */
10+
{
11+
/**
12+
* @see \Equip\Data\EntityInterface::withData()
13+
*
14+
* @param array $data
15+
*
16+
* @return static
17+
*/
18+
abstract public function withData(array $data);
19+
20+
/**
21+
* @see \Equip\Data\ArraySerializableInterface::toArray()
22+
*
23+
* @return array
24+
*/
25+
abstract public function toArray();
26+
27+
/**
28+
* @param array $values
29+
*
30+
* @return array
31+
*/
32+
public function diff(array $values)
33+
{
34+
$copy = $this->withData($values);
35+
return array_diff_assoc($copy->toArray(), $this->toArray());
36+
}
37+
}

0 commit comments

Comments
 (0)