-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngineModel.php
More file actions
63 lines (52 loc) · 1.48 KB
/
EngineModel.php
File metadata and controls
63 lines (52 loc) · 1.48 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace SyncEngine\Model\Abstract;
use Doctrine\ORM\EntityManagerInterface;
use SyncEngine\Entity\Abstract\EngineEntity;
use SyncEngine\Model\Interface\Configurable;
use SyncEngine\Model\Interface\Exportable;
use SyncEngine\Model\Trait\Config;
use SyncEngine\Model\Trait\Data;
use SyncEngine\Model\Trait\Ref;
use SyncEngine\Service\ModelExporter;
/**
* @template T of EngineEntity
* @extends EngineModel<T>
*/
abstract class EngineModel extends EntityModel implements Exportable, Configurable
{
use Ref;
use Config;
use Data;
/**
* @inheritDoc
* @param EngineEntity|null $entity
*/
public function __construct( ?EngineEntity $entity = null )
{
parent::__construct( $entity );
}
public function export(): array
{
// Run validation to trigger parsers and supervisors.
$this->validate();
return $this->getContainer()->get( ModelExporter::class )->export( $this );
}
public function update( $flush = false, ?EntityManagerInterface $entityManager = null ): void
{
if ( $this->hasEntity() ) {
$this->getEntity()->setModified( new \DateTimeImmutable() );
}
parent::update( $flush, $entityManager );
}
public function persist( $flush = false, ?EntityManagerInterface $entityManager = null ): void
{
$entity = $this->getEntity();
if ( ! $entity->getCreated() ) {
$entity->setCreated( new \DateTimeImmutable() );
}
if ( ! $entity->getModified() ) {
$entity->setModified( new \DateTimeImmutable() );
}
parent::persist( $flush, $entityManager );
}
}