|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
9
|
|
|
* @since 0.28 |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace Core\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
|
14
|
|
|
use LogicException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @see AttachableEntityInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
trait AttachableEntityTrait |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var AttachableEntityManager |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $attachableEntityManager; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
* @ODM\Hash |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $attachableEntityReferences = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @see AttachableEntityInterface::setAttachableEntityManager() |
|
35
|
|
|
*/ |
|
36
|
|
|
public function setAttachableEntityManager(AttachableEntityManager $attachableEntityManager) |
|
37
|
|
|
{ |
|
38
|
|
|
if (isset($this->attachableEntityManager)) { |
|
39
|
|
|
throw new LogicException('Attachable entity manager is already set'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->attachableEntityManager = $attachableEntityManager->setReferences($this->attachableEntityReferences); |
|
43
|
|
|
|
|
44
|
|
|
return $this; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @see AttachableEntityInterface::addAttachedEntity() |
|
49
|
|
|
*/ |
|
50
|
|
|
public function addAttachedEntity(IdentifiableEntityInterface $entity, $key = null) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->getAttachableEntityManager()->addAttachedEntity($entity, $key); |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @see AttachableEntityInterface::removeAttachedEntity() |
|
59
|
|
|
*/ |
|
60
|
|
|
public function removeAttachedEntity($key) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getAttachableEntityManager()->removeAttachedEntity($key); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @see AttachableEntityInterface::getAttachedEntity() |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getAttachedEntity($key = null) |
|
69
|
|
|
{ |
|
70
|
|
|
if (!isset($key)) { |
|
71
|
|
|
// allow ommiting parameter for Core\Entity\Hydrator\EntityHydrator::extract() |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->getAttachableEntityManager()->getAttachedEntity($key); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @see AttachableEntityInterface::createAttachedEntity() |
|
80
|
|
|
*/ |
|
81
|
|
|
public function createAttachedEntity($entityClass, $values = [], $key=null) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getAttachableEntityManager()->createAttachedEntity($entityClass, $values, $key); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @see AttachableEntityInterface::hasAttachedEntity() |
|
88
|
|
|
*/ |
|
89
|
|
|
public function hasAttachedEntity($key) |
|
90
|
|
|
{ |
|
91
|
|
|
return (bool) $this->getAttachableEntityManager()->getAttachedEntity($key); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @throws LogicException |
|
96
|
|
|
* @return AttachableEntityManager |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function getAttachableEntityManager() |
|
99
|
|
|
{ |
|
100
|
|
|
if (!isset($this->attachableEntityManager)) { |
|
101
|
|
|
throw new LogicException('No attachable entity manager is set'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->attachableEntityManager; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.