|
2 | 2 |
|
3 | 3 | namespace Illuminate\Database\Query\Grammars; |
4 | 4 |
|
| 5 | +use Illuminate\Database\Concerns\CompilesJsonPaths; |
5 | 6 | use Illuminate\Database\Grammar as BaseGrammar; |
6 | 7 | use Illuminate\Database\Query\Builder; |
7 | 8 | use Illuminate\Database\Query\JoinClause; |
8 | 9 | use Illuminate\Support\Arr; |
9 | | -use Illuminate\Support\Str; |
10 | 10 | use RuntimeException; |
11 | 11 |
|
12 | 12 | class Grammar extends BaseGrammar |
13 | 13 | { |
| 14 | + use CompilesJsonPaths; |
| 15 | + |
14 | 16 | /** |
15 | 17 | * The grammar specific operators. |
16 | 18 | * |
@@ -1259,64 +1261,6 @@ protected function wrapJsonBooleanValue($value) |
1259 | 1261 | return $value; |
1260 | 1262 | } |
1261 | 1263 |
|
1262 | | - /** |
1263 | | - * Split the given JSON selector into the field and the optional path and wrap them separately. |
1264 | | - * |
1265 | | - * @param string $column |
1266 | | - * @return array |
1267 | | - */ |
1268 | | - protected function wrapJsonFieldAndPath($column) |
1269 | | - { |
1270 | | - $parts = explode('->', $column, 2); |
1271 | | - |
1272 | | - $field = $this->wrap($parts[0]); |
1273 | | - |
1274 | | - $path = count($parts) > 1 ? ', '.$this->wrapJsonPath($parts[1], '->') : ''; |
1275 | | - |
1276 | | - return [$field, $path]; |
1277 | | - } |
1278 | | - |
1279 | | - /** |
1280 | | - * Wrap the given JSON path. |
1281 | | - * |
1282 | | - * @param string $value |
1283 | | - * @param string $delimiter |
1284 | | - * @return string |
1285 | | - */ |
1286 | | - protected function wrapJsonPath($value, $delimiter = '->') |
1287 | | - { |
1288 | | - $value = preg_replace("/([\\\\]+)?\\'/", "''", $value); |
1289 | | - |
1290 | | - $jsonPath = collect(explode($delimiter, $value)) |
1291 | | - ->map(function ($segment) { |
1292 | | - return $this->wrapJsonPathSegment($segment); |
1293 | | - }) |
1294 | | - ->join('.'); |
1295 | | - |
1296 | | - return "'$".(str_starts_with($jsonPath, '[') ? '' : '.').$jsonPath."'"; |
1297 | | - } |
1298 | | - |
1299 | | - /** |
1300 | | - * Wrap the given JSON path segment. |
1301 | | - * |
1302 | | - * @param string $segment |
1303 | | - * @return string |
1304 | | - */ |
1305 | | - protected function wrapJsonPathSegment($segment) |
1306 | | - { |
1307 | | - if (preg_match('/(\[[^\]]+\])+$/', $segment, $parts)) { |
1308 | | - $key = Str::beforeLast($segment, $parts[0]); |
1309 | | - |
1310 | | - if (! empty($key)) { |
1311 | | - return '"'.$key.'"'.$parts[0]; |
1312 | | - } |
1313 | | - |
1314 | | - return $parts[0]; |
1315 | | - } |
1316 | | - |
1317 | | - return '"'.$segment.'"'; |
1318 | | - } |
1319 | | - |
1320 | 1264 | /** |
1321 | 1265 | * Concatenate an array of segments, removing empties. |
1322 | 1266 | * |
|
0 commit comments