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-or.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-or.php
57 lines
1 <?php
2
3 namespace SearchRegex\Sql\Where;
4
5 class Where_Or extends Where {
6 /**
7 * Array of WHERE objects that will be ORd together
8 *
9 * @readonly
10 * @var array<Where>
11 */
12 protected array $wheres;
13
14 /**
15 * Constructor
16 *
17 * @param array<Where> $wheres Wheres.
18 * @phpstan-ignore constructor.missingParentCall
19 */
20 public function __construct( array $wheres ) {
21 $this->wheres = $wheres;
22 }
23
24 /**
25 * Get the WHEREs as a group
26 *
27 * @param string $logic Logic.
28 * @return string
29 */
30 protected function get_group( $logic ) {
31 $start = '';
32 $end = '';
33
34 if ( count( $this->wheres ) > 1 ) {
35 $start = '(';
36 $end = ')';
37 }
38
39 $sql = array_map(
40 fn( $where ) => $where->get_as_sql(),
41 $this->wheres
42 );
43
44 return $start . implode( ' ' . $logic . ' ', $sql ) . $end;
45 }
46
47 public function get_as_sql() {
48 return $this->get_group( 'OR' );
49 }
50
51 public function update_column( $column, $updated_column ) {
52 foreach ( $this->wheres as $where ) {
53 $where->update_column( $column, $updated_column );
54 }
55 }
56 }
57