File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
src/MySQLReplication/Config Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ Based on a great work of creators:https://github.com/noplay/python-mysql-repli
14
14
15
15
** Note:** Resolve these issues:
16
16
17
+ - Add regular expression matching support for ` DatabasesOnly ` or ` TablesOnly ` of ` Config ` .
17
18
- Resolve [ krowinski/php-mysql-replication #94 ] ( https://github.com/krowinski/php-mysql-replication/issues/94 ) , change static config properties to non-static.
18
19
- Add retry feature.
19
20
``` php
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ public function getTableCacheSize(): int
177
177
178
178
public function checkDataBasesOnly (string $ database ): bool
179
179
{
180
- return [] !== $ this ->getDatabasesOnly () && !in_array ($ database , $ this ->getDatabasesOnly (), true );
180
+ return [] !== $ this ->getDatabasesOnly () && !self :: matchNames ($ database , $ this ->getDatabasesOnly ());
181
181
}
182
182
183
183
public function getDatabasesOnly (): array
@@ -187,7 +187,18 @@ public function getDatabasesOnly(): array
187
187
188
188
public function checkTablesOnly (string $ table ): bool
189
189
{
190
- return [] !== $ this ->getTablesOnly () && !in_array ($ table , $ this ->getTablesOnly (), true );
190
+ return [] !== $ this ->getTablesOnly () && !self ::matchNames ($ table , $ this ->getTablesOnly ());
191
+ }
192
+
193
+ private static function matchNames (string $ subject , array $ names ): bool
194
+ {
195
+ foreach ($ names as $ name ) {
196
+ if (preg_match ("/ $ name/ " , $ subject )) {
197
+ return true ;
198
+ }
199
+ }
200
+
201
+ return false ;
191
202
}
192
203
193
204
public function getTablesOnly (): array
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ public function shouldCheckDataBasesOnly(): void
93
93
94
94
$ config = (new ConfigBuilder ())->withDatabasesOnly (['foo ' ])->build ();
95
95
self ::assertTrue ($ config ->checkDataBasesOnly ('bar ' ));
96
+
97
+ $ config = (new ConfigBuilder ())->withDatabasesOnly (['foo_.* ' ])->build ();
98
+ self ::assertFalse ($ config ->checkDataBasesOnly ('foo_123 ' ));
96
99
}
97
100
98
101
/**
@@ -111,6 +114,9 @@ public function shouldCheckTablesOnly(): void
111
114
112
115
$ config = (new ConfigBuilder ())->withTablesOnly (['foo ' ])->build ();
113
116
self ::assertTrue ($ config ->checkTablesOnly ('bar ' ));
117
+
118
+ $ config = (new ConfigBuilder ())->withTablesOnly (['foo_.* ' ])->build ();
119
+ self ::assertFalse ($ config ->checkDataBasesOnly ('foo_123 ' ));
114
120
}
115
121
116
122
/**
You can’t perform that action at this time.
0 commit comments