PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
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 / Query / JsonExpression.php

JsonExpression.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at vendor/wpfluent/framework/src/WPFluent/Database/Query/JsonExpression.php

72 lines 1.5 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\Query;
4
5 use InvalidArgumentException;
6 use FluentBooking\Framework\Database\Query\Expression;
7
8 class JsonExpression extends Expression
9 {
10 /**
11 * The value of the expression.
12 *
13 * @var mixed
14 */
15 protected $value;
16
17 /**
18 * Create a new raw query expression.
19 *
20 * @param mixed $value
21 * @return void
22 */
23 public function __construct($value)
24 {
25 $this->value = $this->getJsonBindingParameter($value);
26 }
27
28 /**
29 * Translate the given value into the appropriate JSON binding parameter.
30 *
31 * @param mixed $value
32 * @return string
33 */
34 protected function getJsonBindingParameter($value)
35 {
36 switch ($type = gettype($value)) {
37 case 'boolean':
38 return $value ? 'true' : 'false';
39 case 'integer':
40 case 'double':
41 return $value;
42 case 'string':
43 return '?';
44 case 'object':
45 case 'array':
46 return '?';
47 }
48
49 throw new InvalidArgumentException('JSON value is of illegal type: '.$type);
50 }
51
52 /**
53 * Get the value of the expression.
54 *
55 * @return mixed
56 */
57 public function getValue()
58 {
59 return $this->value;
60 }
61
62 /**
63 * Get the value of the expression.
64 *
65 * @return string
66 */
67 public function __toString()
68 {
69 return (string) $this->getValue();
70 }
71 }
72