22
33namespace LaravelDoctrine \Fluent \Builders \Overrides ;
44
5- use ArrayAccess ;
6- use Doctrine \ORM \Mapping \AssociationMapping ;
75use Doctrine \ORM \Mapping \Builder \ClassMetadataBuilder ;
86use Doctrine \ORM \Mapping \ClassMetadata ;
9- use Doctrine \ORM \Mapping \JoinColumnMapping ;
10- use Doctrine \ORM \Mapping \JoinTableMapping ;
117use Doctrine \ORM \Mapping \NamingStrategy ;
128use InvalidArgumentException ;
139use LaravelDoctrine \Fluent \Buildable ;
@@ -77,7 +73,7 @@ public function build()
7773 $ builder = $ this ->newClassMetadataBuilder ();
7874 $ source = $ this ->convertToMappingArray ($ this ->builder );
7975
80- if (!isset ($ this ->relations [$ source-> type () ])) {
76+ if (!isset ($ this ->relations [$ source[ ' type ' ] ])) {
8177 throw new InvalidArgumentException ('Only ManyToMany and ManyToOne relations can be overridden ' );
8278 }
8379
@@ -86,8 +82,8 @@ public function build()
8682
8783 // Give the original join table name, so we won't
8884 // accidentally remove custom join table names
89- if ($ this ->hasJoinTable (( array ) $ source )) {
90- $ associationBuilder ->setJoinTable ($ source-> joinTable -> name );
85+ if ($ this ->hasJoinTable ($ source )) {
86+ $ associationBuilder ->setJoinTable ($ source[ ' joinTable ' ][ ' name ' ] );
9187 }
9288
9389 $ association = $ callback ($ associationBuilder );
@@ -101,26 +97,26 @@ public function build()
10197 }
10298
10399 $ association instanceof AssociationCache ?
104- $ association ->build ($ source-> targetEntity ) :
100+ $ association ->build ($ source[ ' targetEntity ' ] ) :
105101 $ association ->build ();
106102
107103 $ target = $ this ->convertToMappingArray ($ builder );
108104
109105 $ overrideMapping = [];
110106
111107 // ManyToMany mappings
112- if ($ this ->hasJoinTable (( array ) $ target )) {
108+ if ($ this ->hasJoinTable ($ target )) {
113109 $ overrideMapping ['joinTable ' ] = $ this ->mapJoinTable (
114- $ target-> joinTable ,
115- $ source-> joinTable
110+ ( array ) $ target[ ' joinTable ' ] ,
111+ ( array ) $ source[ ' joinTable ' ]
116112 );
117113 }
118114
119115 // ManyToOne mappings
120- if ($ this ->hasJoinColumns (( array ) $ target )) {
116+ if ($ this ->hasJoinColumns ($ target )) {
121117 $ overrideMapping ['joinColumns ' ] = $ this ->mapJoinColumns (
122- $ target-> joinColumns ,
123- $ source-> joinColumns
118+ $ target[ ' joinColumns ' ] ,
119+ $ source[ ' joinColumns ' ]
124120 );
125121 }
126122
@@ -135,13 +131,16 @@ public function build()
135131 *
136132 * @throws \Doctrine\ORM\Mapping\MappingException
137133 *
138- * @return AssociationMapping
134+ * @return array
139135 */
140136 protected function convertToMappingArray (ClassMetadataBuilder $ builder )
141137 {
142138 $ metadata = $ builder ->getClassMetadata ();
143139
144- return $ metadata ->getAssociationMapping ($ this ->name );
140+ $ associationMappingArray = (array ) $ metadata ->getAssociationMapping ($ this ->name );
141+ $ associationMappingArray ['type ' ] = $ metadata ->getAssociationMapping ($ this ->name )->type ();
142+
143+ return $ associationMappingArray ;
145144 }
146145
147146 /**
@@ -155,45 +154,51 @@ protected function newClassMetadataBuilder()
155154 }
156155
157156 /**
157+ * @param $builder
158+ * @param $source
159+ *
158160 * @return mixed
159161 */
160- protected function getAssociationBuilder (ClassMetadataBuilder $ builder , AssociationMapping $ source )
162+ protected function getAssociationBuilder (ClassMetadataBuilder $ builder , array $ source )
161163 {
162- return new $ this ->relations [$ source-> type () ](
164+ return new $ this ->relations [$ source[ ' type ' ] ](
163165 $ builder ,
164166 $ this ->namingStrategy ,
165167 $ this ->name ,
166- $ source-> targetEntity
168+ $ source[ ' targetEntity ' ]
167169 );
168170 }
169171
170172 /**
173+ * @param array $target
174+ * @param array $source
175+ *
171176 * @return array
172177 */
173- protected function mapJoinTable (JoinTableMapping $ target, JoinTableMapping $ source )
178+ protected function mapJoinTable (array $ target = [], array $ source = [] )
174179 {
175- $ joinTable ['name ' ] = $ target-> name ;
180+ $ joinTable ['name ' ] = $ target[ ' name ' ] ;
176181
177- if ($ this ->hasJoinColumns (( array ) $ target )) {
182+ if ($ this ->hasJoinColumns ($ target )) {
178183 $ joinTable ['joinColumns ' ] = $ this ->mapJoinColumns (
179- $ target-> joinColumns ,
180- $ source-> joinColumns
184+ $ target[ ' joinColumns ' ] ,
185+ $ source[ ' joinColumns ' ]
181186 );
182187 }
183188
184- if ($ this ->hasInverseJoinColumns (( array ) $ target )) {
189+ if ($ this ->hasInverseJoinColumns ($ target )) {
185190 $ joinTable ['inverseJoinColumns ' ] = $ this ->mapJoinColumns (
186- $ target-> inverseJoinColumns ,
187- $ source-> inverseJoinColumns
191+ $ target[ ' inverseJoinColumns ' ] ,
192+ $ source[ ' inverseJoinColumns ' ]
188193 );
189194 }
190195
191196 return $ joinTable ;
192197 }
193198
194199 /**
195- * @param array<JoinColumnMapping> $target
196- * @param array<JoinColumnMapping> $source
200+ * @param array $target
201+ * @param array $source
197202 *
198203 * @return mixed
199204 *
0 commit comments