PluginProbe ʕ •ᴥ•ʔ
Search Regex / 3.4
Search Regex v3.4
trunk 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 2.0 2.0.1 2.1 2.2 2.2.1 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1 3.1.1 3.1.2 3.2 3.3 3.3.0 3.3.1 3.4 3.4.1 3.4.2
search-regex / includes / sql / where / class-where.php
search-regex / includes / sql / where Last commit date
class-where-and.php 5 months ago class-where-date.php 5 months ago class-where-in.php 5 months ago class-where-integer.php 5 months ago class-where-null.php 5 months ago class-where-or.php 5 months ago class-where-string.php 5 months ago class-where.php 5 months ago
class-where.php
83 lines
1 <?php
2
3 namespace SearchRegex\Sql\Where;
4
5 use SearchRegex\Sql;
6
7 /**
8 * SQL WHERE
9 */
10 class Where {
11 /**
12 * Column
13 *
14 * @readonly
15 */
16 protected ?Sql\Select\Select $column;
17
18 /**
19 * WHERE logic
20 *
21 * @readonly
22 */
23 protected string $logic;
24
25 /**
26 * WHERE value
27 *
28 * @readonly
29 * @var string|integer|list<string|int>
30 */
31 protected $value;
32
33 /**
34 * Constructor
35 *
36 * @param Sql\Select\Select $column Column.
37 * @param string $logic Logic.
38 * @param string|integer|list<string|int> $value Value.
39 */
40 protected function __construct( Sql\Select\Select $column, $logic, $value = '' ) {
41 $this->column = $column;
42 $this->value = $value; // Sanitized in get_value
43 $this->logic = $logic;
44 }
45
46 /**
47 * Get as SQL
48 *
49 * @return string
50 */
51 public function get_as_sql() {
52 if ( $this->column !== null ) {
53 return $this->column->get_column_or_alias() . ' ' . $this->logic . ' ' . $this->get_value();
54 }
55
56 return '';
57 }
58
59 /**
60 * Change the column
61 *
62 * @param string $column Column.
63 * @param string $updated_column New column.
64 * @return void
65 */
66 public function update_column( $column, $updated_column ) {
67 if ( $this->column !== null ) {
68 $this->column->update_column( $column, $updated_column );
69 }
70 }
71
72 /**
73 * Get the WHERE value
74 *
75 * @return string
76 */
77 public function get_value() {
78 global $wpdb;
79
80 return $wpdb->prepare( '%s', $this->value );
81 }
82 }
83