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