$this->find, 'replace' => $this->replace, 'case_sensitive' => $this->case_sensitive, 'tables' => $this->tables, 'generated' => $this->generated, ]; } /** * Whether this rule may touch the given table. * * A scope can be prefixed or bare. Bare is portable, since a rule written on one * site must mean the same on another with a different prefix. * * @param string $table Prefixed table name. * @param string $prefix Site prefix if known. Without it a bare name matches * nothing rather than everything. */ public function applies_to_table( string $table, string $prefix = '' ): bool { if ( null === $this->tables ) { return true; } if ( in_array( $table, $this->tables, true ) ) { return true; } return '' !== $prefix && str_starts_with( $table, $prefix ) && in_array( substr( $table, strlen( $prefix ) ), $this->tables, true ); } /** * An empty list would make the rule touch nothing, never intended, so it is * treated as unscoped. * * @param mixed $tables Raw value from a request or a stored rule. * * @return string[]|null */ private static function normalise_tables( mixed $tables ): ?array { if ( ! is_array( $tables ) ) { return null; } $clean = array_values( array_unique( array_map( 'strval', $tables ) ) ); sort( $clean ); return [] === $clean ? null : $clean; } }