class-delete.php
6 months ago
class-export.php
1 week ago
class-global-replace.php
6 months ago
class-modify.php
6 months ago
class-nothing.php
6 months ago
class-run.php
1 week ago
class-global-replace.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Action\Type; |
| 4 | |
| 5 | use SearchRegex\Schema; |
| 6 | |
| 7 | /** |
| 8 | * Global replace. This emulates the previous searchregex |
| 9 | */ |
| 10 | class Global_Replace extends Modify { |
| 11 | /** |
| 12 | * Constructor |
| 13 | * |
| 14 | * @param array<string, mixed>|string $options Options. |
| 15 | * @param Schema\Schema $schema Schema. |
| 16 | */ |
| 17 | public function __construct( $options, Schema\Schema $schema ) { |
| 18 | /** @var array<int, array<string, mixed>> $converted */ |
| 19 | $converted = []; |
| 20 | |
| 21 | if ( is_array( $options ) ) { |
| 22 | foreach ( $schema->get_sources() as $source ) { |
| 23 | foreach ( $source->get_global_columns() as $column ) { |
| 24 | $converted[] = [ |
| 25 | 'column' => $column->get_column(), |
| 26 | 'source' => $source->get_type(), |
| 27 | 'operation' => 'replace', |
| 28 | 'searchValue' => $options['search'], |
| 29 | 'replaceValue' => $options['replacement'], |
| 30 | 'searchFlags' => $options['flags'], |
| 31 | ]; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | parent::__construct( $converted, $schema ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @return array<string, mixed> |
| 41 | */ |
| 42 | public function to_json() { |
| 43 | return [ |
| 44 | 'action' => 'replace', |
| 45 | 'actionOption' => [], |
| 46 | ]; |
| 47 | } |
| 48 | } |
| 49 |