1 | <?php |
||
25 | final class MetadataLoadInterceptor implements EventSubscriber |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | public function getSubscribedEvents() |
||
36 | |||
37 | /** |
||
38 | * Handles \Doctrine\ORM\Events::loadClassMetadata event by modifying metadata of Go! AOP proxied classes. |
||
39 | * |
||
40 | * This method intercepts loaded metadata of Doctrine's entities which are weaved by Go! AOP, |
||
41 | * and denotes them as mapped superclass. If weaved entities uses mappings from traits |
||
42 | * (such as Timestampable, Blameable, etc... from https://github.com/Atlantic18/DoctrineExtensions), |
||
43 | * it will remove all mappings from proxied class for fields inherited from traits in order to prevent |
||
44 | * collision with concrete subclass of weaved entity. Fields from trait will be present in concrete subclass |
||
45 | * of weaved entitites. |
||
46 | * |
||
47 | * @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#mapped-superclasses |
||
48 | * @see https://github.com/Atlantic18/DoctrineExtensions |
||
49 | * |
||
50 | * @param LoadClassMetadataEventArgs $args |
||
51 | */ |
||
52 | 2 | public function loadClassMetadata(LoadClassMetadataEventArgs $args) |
|
69 | |||
70 | /** |
||
71 | * Remove fields in Go! AOP proxied class metadata that are inherited |
||
72 | * from traits. |
||
73 | * |
||
74 | * @param ClassMetadata $metadata |
||
75 | */ |
||
76 | 1 | private function removeMappingsFromTraits(ClassMetadata $metadata) |
|
103 | |||
104 | /** |
||
105 | * Get ALL traits used by one class. |
||
106 | * |
||
107 | * This method is copied from https://github.com/RunOpenCode/traitor-bundle/blob/master/src/RunOpenCode/Bundle/Traitor/Utils/ClassUtils.php |
||
108 | * |
||
109 | * @param object|string $objectOrClass Instance of class or FQCN |
||
110 | * @param bool $autoload Weather to autoload class. |
||
111 | * |
||
112 | * @throws \InvalidArgumentException |
||
113 | * @throws \RuntimeException |
||
114 | * |
||
115 | * @return array Used traits. |
||
116 | */ |
||
117 | 1 | private function getTraits($objectOrClass, $autoload = true) |
|
153 | } |
||
154 |