1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Developtech\AgilityBundle\EventSubscriber; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\EventSubscriber; |
6
|
|
|
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
7
|
|
|
use Doctrine\ORM\Events; |
8
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
9
|
|
|
|
10
|
|
|
class DynamicRelationSubscriber implements EventSubscriber |
11
|
|
|
{ |
12
|
|
|
const MODEL_PROJECT = 'Developtech\AgilityBundle\Entity\Project'; |
13
|
|
|
const MODEL_FEATURE = 'Developtech\AgilityBundle\Entity\Feature'; |
14
|
|
|
const MODEL_FEEDBACK = 'Developtech\AgilityBundle\Entity\Feedback'; |
15
|
|
|
|
16
|
|
|
/** @var string **/ |
17
|
|
|
protected $userClass; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $userClass |
21
|
|
|
*/ |
22
|
1 |
|
public function __construct($userClass) { |
23
|
1 |
|
$this->userClass = $userClass; |
24
|
1 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritDoc} |
28
|
|
|
*/ |
29
|
1 |
|
public function getSubscribedEvents() |
30
|
|
|
{ |
31
|
|
|
return array( |
32
|
1 |
|
Events::loadClassMetadata, |
33
|
1 |
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param LoadClassMetadataEventArgs $eventArgs |
38
|
|
|
*/ |
39
|
|
|
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) |
40
|
|
|
{ |
41
|
|
|
// the $metadata is the whole mapping info for this class |
42
|
|
|
$metadata = $eventArgs->getClassMetadata(); |
43
|
|
|
|
44
|
|
|
switch($metadata->getName()) { |
|
|
|
|
45
|
|
|
case self::MODEL_PROJECT: return $this->mapProject($metadata); |
|
|
|
|
46
|
|
|
case self::MODEL_FEATURE: return $this->mapFeature($metadata); |
|
|
|
|
47
|
|
|
case self::MODEL_FEEDBACK: return $this->mapFeedback($metadata); |
|
|
|
|
48
|
|
|
default: return; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param CLassMetadata $metadata |
54
|
|
|
*/ |
55
|
1 |
|
public function mapProject(ClassMetadata $metadata) { |
56
|
|
|
$metadata->mapManyToOne(array( |
57
|
1 |
|
'targetEntity' => $this->userClass, |
58
|
1 |
|
'fieldName' => 'productOwner', |
59
|
1 |
|
'cascade' => array(), |
60
|
|
|
'joinColumn' => array( |
61
|
|
|
'name' => 'product_owner_id', |
62
|
|
|
'referencedColumnName' => 'id', |
63
|
|
|
'onDelete' => 'SET NULL', |
64
|
|
|
'nullable' => true |
65
|
1 |
|
) |
66
|
|
|
)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param CLassMetadata $metadata |
71
|
|
|
*/ |
72
|
1 |
|
public function mapFeature(ClassMetadata $metadata) { |
73
|
|
|
$metadata->mapManyToOne(array( |
74
|
1 |
|
'targetEntity' => $this->userClass, |
75
|
1 |
|
'fieldName' => 'responsible', |
76
|
1 |
|
'cascade' => array(), |
77
|
|
|
'joinColumn' => array( |
78
|
|
|
'name' => 'responsible_id', |
79
|
|
|
'referencedColumnName' => 'id', |
80
|
|
|
'onDelete' => 'SET NULL', |
81
|
|
|
'nullable' => true |
82
|
1 |
|
) |
83
|
|
|
)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param CLassMetadata $metadata |
88
|
|
|
*/ |
89
|
1 |
|
public function mapFeedback(ClassMetadata $metadata) { |
90
|
|
|
$metadata->mapManyToOne(array( |
91
|
1 |
|
'targetEntity' => $this->userClass, |
92
|
1 |
|
'fieldName' => 'author', |
93
|
1 |
|
'cascade' => array(), |
94
|
|
|
'joinColumn' => array( |
95
|
|
|
'name' => 'author_id', |
96
|
|
|
'referencedColumnName' => 'id', |
97
|
|
|
'onDelete' => 'CASCADE', |
98
|
|
|
'nullable' => false |
99
|
1 |
|
) |
100
|
|
|
)); |
101
|
|
|
$metadata->mapManyToOne(array( |
102
|
1 |
|
'targetEntity' => $this->userClass, |
103
|
1 |
|
'fieldName' => 'responsible', |
104
|
1 |
|
'cascade' => array(), |
105
|
|
|
'joinColumn' => array( |
106
|
|
|
'name' => 'responsible_id', |
107
|
|
|
'referencedColumnName' => 'id', |
108
|
|
|
'onDelete' => 'SET NULL', |
109
|
|
|
'nullable' => true |
110
|
1 |
|
) |
111
|
|
|
)); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.