-
Notifications
You must be signed in to change notification settings - Fork 27
/
UnitOfWork.php
39 lines (31 loc) · 1003 Bytes
/
UnitOfWork.php
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
<?php
namespace Ddeboer\Salesforce\MapperBundle;
use Ddeboer\Salesforce\MapperBundle\Annotation\AnnotationReader;
class UnitOfWork
{
protected $mapper;
protected $annotationReader;
protected $identityMap = array();
public function __construct(Mapper $mapper, AnnotationReader $annotationReader)
{
$this->mapper = $mapper;
$this->annotationReader = $annotationReader;
}
public function find($modelClass, $id)
{
$sObjectName = $this->getObjectName($modelClass);
if (isset($this->identityMap[$sObjectName][$id])) {
return $this->identityMap[$sObjectName][$id];
}
}
public function addToIdentityMap($model)
{
$this->getObjectName($model);
$this->identityMap[$this->getObjectName($model)][$model->getId()] = $model;
}
protected function getObjectName($model)
{
$description = $this->mapper->getObjectDescription($model);
return $description->getName();
}
}