2
2
3
3
namespace LaravelDoctrine \Fluent \Builders \Overrides ;
4
4
5
- use ArrayAccess ;
6
- use Doctrine \ORM \Mapping \AssociationMapping ;
7
5
use Doctrine \ORM \Mapping \Builder \ClassMetadataBuilder ;
8
6
use Doctrine \ORM \Mapping \ClassMetadata ;
9
- use Doctrine \ORM \Mapping \JoinColumnMapping ;
10
- use Doctrine \ORM \Mapping \JoinTableMapping ;
11
7
use Doctrine \ORM \Mapping \NamingStrategy ;
12
8
use InvalidArgumentException ;
13
9
use LaravelDoctrine \Fluent \Buildable ;
@@ -77,7 +73,7 @@ public function build()
77
73
$ builder = $ this ->newClassMetadataBuilder ();
78
74
$ source = $ this ->convertToMappingArray ($ this ->builder );
79
75
80
- if (!isset ($ this ->relations [$ source-> type () ])) {
76
+ if (!isset ($ this ->relations [$ source[ ' type ' ] ])) {
81
77
throw new InvalidArgumentException ('Only ManyToMany and ManyToOne relations can be overridden ' );
82
78
}
83
79
@@ -86,8 +82,8 @@ public function build()
86
82
87
83
// Give the original join table name, so we won't
88
84
// 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 ' ] );
91
87
}
92
88
93
89
$ association = $ callback ($ associationBuilder );
@@ -101,26 +97,26 @@ public function build()
101
97
}
102
98
103
99
$ association instanceof AssociationCache ?
104
- $ association ->build ($ source-> targetEntity ) :
100
+ $ association ->build ($ source[ ' targetEntity ' ] ) :
105
101
$ association ->build ();
106
102
107
103
$ target = $ this ->convertToMappingArray ($ builder );
108
104
109
105
$ overrideMapping = [];
110
106
111
107
// ManyToMany mappings
112
- if ($ this ->hasJoinTable (( array ) $ target )) {
108
+ if ($ this ->hasJoinTable ($ target )) {
113
109
$ overrideMapping ['joinTable ' ] = $ this ->mapJoinTable (
114
- $ target-> joinTable ,
115
- $ source-> joinTable
110
+ ( array ) $ target[ ' joinTable ' ] ,
111
+ ( array ) $ source[ ' joinTable ' ]
116
112
);
117
113
}
118
114
119
115
// ManyToOne mappings
120
- if ($ this ->hasJoinColumns (( array ) $ target )) {
116
+ if ($ this ->hasJoinColumns ($ target )) {
121
117
$ overrideMapping ['joinColumns ' ] = $ this ->mapJoinColumns (
122
- $ target-> joinColumns ,
123
- $ source-> joinColumns
118
+ $ target[ ' joinColumns ' ] ,
119
+ $ source[ ' joinColumns ' ]
124
120
);
125
121
}
126
122
@@ -135,13 +131,16 @@ public function build()
135
131
*
136
132
* @throws \Doctrine\ORM\Mapping\MappingException
137
133
*
138
- * @return AssociationMapping
134
+ * @return array
139
135
*/
140
136
protected function convertToMappingArray (ClassMetadataBuilder $ builder )
141
137
{
142
138
$ metadata = $ builder ->getClassMetadata ();
143
139
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 ;
145
144
}
146
145
147
146
/**
@@ -155,45 +154,51 @@ protected function newClassMetadataBuilder()
155
154
}
156
155
157
156
/**
157
+ * @param $builder
158
+ * @param $source
159
+ *
158
160
* @return mixed
159
161
*/
160
- protected function getAssociationBuilder (ClassMetadataBuilder $ builder , AssociationMapping $ source )
162
+ protected function getAssociationBuilder (ClassMetadataBuilder $ builder , array $ source )
161
163
{
162
- return new $ this ->relations [$ source-> type () ](
164
+ return new $ this ->relations [$ source[ ' type ' ] ](
163
165
$ builder ,
164
166
$ this ->namingStrategy ,
165
167
$ this ->name ,
166
- $ source-> targetEntity
168
+ $ source[ ' targetEntity ' ]
167
169
);
168
170
}
169
171
170
172
/**
173
+ * @param array $target
174
+ * @param array $source
175
+ *
171
176
* @return array
172
177
*/
173
- protected function mapJoinTable (JoinTableMapping $ target, JoinTableMapping $ source )
178
+ protected function mapJoinTable (array $ target = [], array $ source = [] )
174
179
{
175
- $ joinTable ['name ' ] = $ target-> name ;
180
+ $ joinTable ['name ' ] = $ target[ ' name ' ] ;
176
181
177
- if ($ this ->hasJoinColumns (( array ) $ target )) {
182
+ if ($ this ->hasJoinColumns ($ target )) {
178
183
$ joinTable ['joinColumns ' ] = $ this ->mapJoinColumns (
179
- $ target-> joinColumns ,
180
- $ source-> joinColumns
184
+ $ target[ ' joinColumns ' ] ,
185
+ $ source[ ' joinColumns ' ]
181
186
);
182
187
}
183
188
184
- if ($ this ->hasInverseJoinColumns (( array ) $ target )) {
189
+ if ($ this ->hasInverseJoinColumns ($ target )) {
185
190
$ joinTable ['inverseJoinColumns ' ] = $ this ->mapJoinColumns (
186
- $ target-> inverseJoinColumns ,
187
- $ source-> inverseJoinColumns
191
+ $ target[ ' inverseJoinColumns ' ] ,
192
+ $ source[ ' inverseJoinColumns ' ]
188
193
);
189
194
}
190
195
191
196
return $ joinTable ;
192
197
}
193
198
194
199
/**
195
- * @param array<JoinColumnMapping> $target
196
- * @param array<JoinColumnMapping> $source
200
+ * @param array $target
201
+ * @param array $source
197
202
*
198
203
* @return mixed
199
204
*
0 commit comments