1
+ <?php
2
+
3
+ /**
4
+ * Copyright © EcomDev B.V. All rights reserved.
5
+ * See LICENSE for license details.
6
+ */
7
+
8
+ declare (strict_types=1 );
9
+
10
+ namespace EcomDev \MySQL2JSONL \Condition ;
11
+
12
+ use EcomDev \MySQL2JSONL \TableCondition ;
13
+
14
+ final readonly class TableNameCondition implements TableCondition
15
+ {
16
+ use ComposeAndCondition;
17
+
18
+ private const EXACT_MATCH = 'exact ' ;
19
+ private const STARTS_WITH = 'starts ' ;
20
+ private const ENDS_WITH = 'ends ' ;
21
+ private const CONTAINS = 'contains ' ;
22
+ private const REGEXP = 'regexp ' ;
23
+
24
+ private function __construct (private string $ tableName , private string $ matchType )
25
+ {
26
+ }
27
+
28
+ public static function exactMatch (string $ tableName ): TableNameCondition
29
+ {
30
+ return new TableNameCondition ($ tableName , self ::EXACT_MATCH );
31
+ }
32
+
33
+ public static function startsWith (string $ tableName ): TableNameCondition
34
+ {
35
+ return new TableNameCondition ($ tableName , self ::STARTS_WITH );
36
+ }
37
+
38
+ public static function endsWith (string $ tableName ): TableNameCondition
39
+ {
40
+ return new TableNameCondition ($ tableName , self ::ENDS_WITH );
41
+ }
42
+
43
+ public static function contains (string $ tableName ): TableNameCondition
44
+ {
45
+ return new TableNameCondition ($ tableName , self ::CONTAINS );
46
+ }
47
+
48
+ public static function regexp (string $ regexp ): TableNameCondition
49
+ {
50
+ return new TableNameCondition ($ regexp , self ::REGEXP );
51
+ }
52
+
53
+
54
+ public function isSatisfiedBy (string $ tableName , int $ rows ): bool
55
+ {
56
+ return match ($ this ->matchType ) {
57
+ self ::EXACT_MATCH => $ tableName === $ this ->tableName ,
58
+ self ::STARTS_WITH => str_starts_with ($ tableName , $ this ->tableName ),
59
+ self ::ENDS_WITH => str_ends_with ($ tableName , $ this ->tableName ),
60
+ self ::CONTAINS => str_contains ($ tableName , $ this ->tableName ),
61
+ self ::REGEXP => !!preg_match ($ this ->tableName , $ tableName ),
62
+ default => false
63
+ };
64
+ }
65
+ }
0 commit comments