-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.php
More file actions
46 lines (36 loc) · 971 Bytes
/
Data.php
File metadata and controls
46 lines (36 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace SyncEngine\Model\Trait;
use SyncEngine\Model\Interface\Persistable;
use SyncEngine\Structure\Data\ResourceData;
trait Data
{
protected ResourceData $data;
public function initData(): void
{
$this->data = new ResourceData( [] );
if ( $this instanceof Persistable && is_callable( [ $this->getEntity(), 'getData' ] ) ) {
$this->data->set( (array) $this->getEntity()->getData() );
}
}
public function getData( $key = null, $default = null ): mixed
{
if ( ! isset( $this->data ) ) {
$this->initData();
}
return $this->data->get( $key, $default );
}
public function setData( $value, $key = null ): void
{
if ( ! isset( $this->data ) ) {
$this->initData();
}
$this->data->set( $value, $key );
if ( $this instanceof Persistable && is_callable( [ $this->getEntity(), 'setData' ] ) ) {
$this->getEntity()->setData( $this->data->getArrayCopy() );
}
}
public function getDataFields(): array
{
return [];
}
}