PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.1.1
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.1.1
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Database / Concerns / CompilesJsonPaths.php

CompilesJsonPaths.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.1.1, at vendor/wpfluent/framework/src/WPFluent/Database/Concerns/CompilesJsonPaths.php

66 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\Framework\Database\Concerns;
4
5 use FluentBooking\Framework\Support\Str;
6 use FluentBooking\Framework\Support\Helper;
7
8 trait CompilesJsonPaths
9 {
10 /**
11 * Split the given JSON selector into the field and the optional path and wrap them separately.
12 *
13 * @param string $column
14 * @return array
15 */
16 protected function wrapJsonFieldAndPath($column)
17 {
18 $parts = explode('->', $column, 2);
19
20 $field = $this->wrap($parts[0]);
21
22 $path = count($parts) > 1 ? ', '.$this->wrapJsonPath($parts[1], '->') : '';
23
24 return [$field, $path];
25 }
26
27 /**
28 * Wrap the given JSON path.
29 *
30 * @param string $value
31 * @param string $delimiter
32 * @return string
33 */
34 protected function wrapJsonPath($value, $delimiter = '->')
35 {
36 $value = preg_replace("/([\\\\]+)?\\'/", "''", $value);
37
38 $jsonPath = Helper::collect(explode($delimiter, $value))
39 ->map(fn ($segment) => $this->wrapJsonPathSegment($segment))
40 ->join('.');
41
42 return "'$".(str_starts_with($jsonPath, '[') ? '' : '.').$jsonPath."'";
43 }
44
45 /**
46 * Wrap the given JSON path segment.
47 *
48 * @param string $segment
49 * @return string
50 */
51 protected function wrapJsonPathSegment($segment)
52 {
53 if (preg_match('/(\[[^\]]+\])+$/', $segment, $parts)) {
54 $key = Str::beforeLast($segment, $parts[0]);
55
56 if (! empty($key)) {
57 return '"'.$key.'"'.$parts[0];
58 }
59
60 return $parts[0];
61 }
62
63 return '"'.$segment.'"';
64 }
65 }
66