1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of slick/orm package |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Slick\Orm\Mapper; |
11
|
|
|
|
12
|
|
|
use Slick\Database\Adapter\AdapterInterface; |
13
|
|
|
use Slick\Orm\Descriptor\EntityDescriptorInterface; |
14
|
|
|
use Slick\Orm\Descriptor\EntityDescriptorRegistry; |
15
|
|
|
use Slick\Orm\EntityInterface; |
16
|
|
|
use Slick\Orm\EntityMapperInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract EntityMapper |
20
|
|
|
* |
21
|
|
|
* @package Slick\Orm\Mapper |
22
|
|
|
* @author Filipe Silva <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractEntityMapper implements EntityMapperInterface |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var EntityInterface |
29
|
|
|
*/ |
30
|
|
|
protected $entity; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EntityDescriptorInterface |
34
|
|
|
*/ |
35
|
|
|
protected $descriptor; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var AdapterInterface |
39
|
|
|
*/ |
40
|
|
|
protected $adapter; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $entityClassName; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get entity descriptor |
49
|
|
|
* |
50
|
|
|
* @return EntityDescriptorInterface |
51
|
|
|
*/ |
52
|
12 |
|
public function getDescriptor() |
53
|
|
|
{ |
54
|
12 |
|
if (null == $this->descriptor) { |
55
|
8 |
|
$this->setDescriptor( |
56
|
8 |
|
EntityDescriptorRegistry::getInstance() |
57
|
8 |
|
->getDescriptorFor($this->getEntityClassName()) |
58
|
8 |
|
); |
59
|
8 |
|
} |
60
|
12 |
|
return $this->descriptor; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set entity descriptor |
65
|
|
|
* |
66
|
|
|
* @param EntityDescriptorInterface $descriptor |
67
|
|
|
* |
68
|
|
|
* @return $this|self|EntityMapper |
69
|
|
|
*/ |
70
|
12 |
|
public function setDescriptor($descriptor) |
71
|
|
|
{ |
72
|
12 |
|
$this->descriptor = $descriptor; |
73
|
12 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets the adapter for this mapper |
78
|
|
|
* |
79
|
|
|
* @param AdapterInterface $adapter |
80
|
|
|
* |
81
|
|
|
* @return self|$this|EntityMapper |
82
|
|
|
*/ |
83
|
10 |
|
public function setAdapter(AdapterInterface $adapter) |
84
|
|
|
{ |
85
|
10 |
|
$this->adapter = $adapter; |
86
|
10 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Retrieves the current adapter |
91
|
|
|
* |
92
|
|
|
* @return AdapterInterface |
93
|
|
|
*/ |
94
|
6 |
|
public function getAdapter() |
95
|
|
|
{ |
96
|
6 |
|
return $this->adapter; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Gets entity class name for this mapper |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
8 |
|
public function getEntityClassName() |
105
|
|
|
{ |
106
|
8 |
|
if (null == $this->entityClassName) { |
107
|
6 |
|
$this->setEntityClassName(get_class($this->entity)); |
108
|
6 |
|
} |
109
|
8 |
|
return $this->entityClassName; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Sets entity class name for this mapper |
114
|
|
|
* |
115
|
|
|
* @param string $entityClassName |
116
|
|
|
* |
117
|
|
|
* @return self|$this|EntityMapper |
118
|
|
|
*/ |
119
|
10 |
|
public function setEntityClassName($entityClassName) |
120
|
|
|
{ |
121
|
10 |
|
$this->entityClassName = $entityClassName; |
122
|
10 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
} |