@@ -92,7 +92,57 @@ protected function _truncate(string $table): string
92
92
*/
93
93
public function join (string $ table , string $ cond , string $ type = '' , ?bool $ escape = null )
94
94
{
95
- parent ::join ($ table , $ cond , $ type , $ escape );
95
+ if ($ type !== '' ) {
96
+ $ type = strtoupper (trim ($ type ));
97
+
98
+ if (! in_array ($ type , $ this ->joinTypes , true )) {
99
+ $ type = '' ;
100
+ } else {
101
+ $ type .= ' ' ;
102
+ }
103
+ }
104
+
105
+ // Extract any aliases that might exist. We use this information
106
+ // in the protectIdentifiers to know whether to add a table prefix
107
+ $ this ->trackAliases ($ table );
108
+
109
+ if (! is_bool ($ escape )) {
110
+ $ escape = $ this ->db ->protectIdentifiers ;
111
+ }
112
+
113
+ if (! $ this ->hasOperator ($ cond )) {
114
+ $ cond = ' USING ( ' . ($ escape ? $ this ->db ->escapeIdentifiers ($ cond ) : $ cond ) . ') ' ;
115
+ } elseif ($ escape === false ) {
116
+ $ cond = ' ON ' . $ cond ;
117
+ } else {
118
+ // Split multiple conditions
119
+ if (preg_match_all ('/\sAND\s|\sOR\s/i ' , $ cond , $ joints , PREG_OFFSET_CAPTURE )) {
120
+ $ conditions = [];
121
+ $ joints = $ joints [0 ];
122
+ array_unshift ($ joints , ['' , 0 ]);
123
+
124
+ for ($ i = count ($ joints ) - 1 , $ pos = strlen ($ cond ); $ i >= 0 ; $ i --) {
125
+ $ joints [$ i ][1 ] += strlen ($ joints [$ i ][0 ]); // offset
126
+ $ conditions [$ i ] = substr ($ cond , $ joints [$ i ][1 ], $ pos - $ joints [$ i ][1 ]);
127
+ $ pos = $ joints [$ i ][1 ] - strlen ($ joints [$ i ][0 ]);
128
+ $ joints [$ i ] = $ joints [$ i ][0 ];
129
+ }
130
+
131
+ ksort ($ conditions );
132
+ } else {
133
+ $ conditions = [$ cond ];
134
+ $ joints = ['' ];
135
+ }
136
+
137
+ $ cond = ' ON ' ;
138
+
139
+ foreach ($ conditions as $ i => $ condition ) {
140
+ $ operator = $ this ->getOperator ($ condition );
141
+
142
+ $ cond .= $ joints [$ i ];
143
+ $ cond .= preg_match ('/(\(*)?([\[\]\w\. \'-]+) ' . preg_quote ($ operator , '/ ' ) . '(.*)/i ' , $ condition , $ match ) ? $ match [1 ] . $ this ->db ->protectIdentifiers ($ match [2 ]) . $ operator . $ this ->db ->protectIdentifiers ($ match [3 ]) : $ condition ;
144
+ }
145
+ }
96
146
97
147
// Do we want to escape the table name?
98
148
if ($ escape === true ) {
0 commit comments