-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRef.php
More file actions
38 lines (29 loc) · 802 Bytes
/
Ref.php
File metadata and controls
38 lines (29 loc) · 802 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
<?php
namespace SyncEngine\Model\Trait;
use SyncEngine\Model\Interface\Persistable;
trait Ref
{
private string $ref;
public function getRef(): mixed
{
if ( ! isset( $this->ref ) ) {
$this->ref = '';
if ( $this instanceof Persistable && is_callable( [ $this->getEntity(), 'getRef' ] ) ) {
$this->ref = (string) $this->getEntity()->getRef();
}
}
return $this->ref;
}
public function createRef( $recreate = false, $prefix = '', $postfix = '' ): void
{
if ( ! $recreate && $this->getRef() ) {
return;
}
$ref = ( new \SyncEngine\Service\Generator\Ref() )->generate();
$ref = $prefix . $ref . $postfix;
if ( $this instanceof Persistable && is_callable( [ $this->getEntity(), 'setRef' ] ) ) {
$this->getEntity()->setRef( $ref );
}
$this->ref = $ref;
}
}