|
| 1 | +## File multiple column |
| 2 | + |
| 3 | +This Anonymizer will anonymize multiple columns at once using value rows from a |
| 4 | +input file. As of now, only CSV files are supported. |
| 5 | + |
| 6 | +This aninymizer behaves like any other multiple column anonymizer and allows you |
| 7 | +to arbitrarily map any sample column into any database table column using the |
| 8 | +anonymizer options. |
| 9 | + |
| 10 | +Given the following file: |
| 11 | + |
| 12 | +```txt |
| 13 | +Number,Foo,Animal |
| 14 | +1,foo,cat |
| 15 | +2,bar,dog |
| 16 | +3,baz,girafe |
| 17 | +``` |
| 18 | + |
| 19 | +Then: |
| 20 | + |
| 21 | +@@@ standalone docker |
| 22 | + |
| 23 | +```yaml [YAML] |
| 24 | +# db_tools.config.yaml |
| 25 | +anonymization: |
| 26 | + default: |
| 27 | + customer: |
| 28 | + my_data: |
| 29 | + anonymizer: file_column |
| 30 | + options: |
| 31 | + source: ./resources/my_data.csv |
| 32 | + # Define your CSV file column names. |
| 33 | + columns: [number, foo, animal] |
| 34 | + # Other allowed options. |
| 35 | + file_skip_header: true |
| 36 | + # Now your columns, keys are CSV column names |
| 37 | + # you set upper, values are your database column |
| 38 | + # names. |
| 39 | + number: my_integer_column |
| 40 | + foo: my_foo_column |
| 41 | + animal: my_animal_column |
| 42 | + #... |
| 43 | +``` |
| 44 | + |
| 45 | +@@@ |
| 46 | +@@@ symfony |
| 47 | + |
| 48 | +::: code-group |
| 49 | +```php [Attribute] |
| 50 | +namespace App\Entity; |
| 51 | + |
| 52 | +use Doctrine\ORM\Mapping as ORM; |
| 53 | +use MakinaCorpus\DbToolsBundle\Attribute\Anonymize; |
| 54 | + |
| 55 | +#[ORM\Entity()] |
| 56 | +#[ORM\Table(name: 'customer')] |
| 57 | +#[Anonymize(type: 'string', options: [ // [!code ++] |
| 58 | + 'source' => './resources/my_data.csv', // [!code ++] |
| 59 | + // Define your CSV file column names. // [!code ++] |
| 60 | + 'columns': ['number', 'foo', 'animal'], // [!code ++] |
| 61 | + // Other allowed options. // [!code ++] |
| 62 | + 'file_skip_header' => true, // [!code ++] |
| 63 | + // Now your columns, keys are CSV column names // [!code ++] |
| 64 | + // you set upper, values are your database column // [!code ++] |
| 65 | + // names. // [!code ++] |
| 66 | + 'number' => 'my_integer_column', // [!code ++] |
| 67 | + 'foo' => 'my_foo_column', // [!code ++] |
| 68 | + 'animal' => 'my_animal_column', // [!code ++] |
| 69 | +])] // [!code ++] |
| 70 | +class Customer |
| 71 | +{ |
| 72 | + // ... |
| 73 | + |
| 74 | + #[ORM\Column(length: 255)] |
| 75 | + private ?string $myNumber = null; |
| 76 | + |
| 77 | + #[ORM\Column(length: 255)] |
| 78 | + private ?string $myFoo = null; |
| 79 | + |
| 80 | + #[ORM\Column(length: 255)] |
| 81 | + private ?string $myAnimal = null; |
| 82 | + |
| 83 | + // ... |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +```yaml [YAML] |
| 88 | +# config/anonymization.yaml |
| 89 | +customer: |
| 90 | + my_data: |
| 91 | + anonymizer: file_column |
| 92 | + options: |
| 93 | + source: ./resources/my_data.csv |
| 94 | + # Define your CSV file column names. |
| 95 | + columns: [number, foo, animal] |
| 96 | + # Other allowed options. |
| 97 | + file_skip_header: true |
| 98 | + # Now your columns, keys are CSV column names |
| 99 | + # you set upper, values are your database column |
| 100 | + # names. |
| 101 | + number: my_integer_column |
| 102 | + foo: my_foo_column |
| 103 | + animal: my_animal_column |
| 104 | + #... |
| 105 | +``` |
| 106 | +::: |
| 107 | + |
| 108 | +:::warning |
| 109 | +This anonymizer works at the *table level* which means that the PHP attribute |
| 110 | +cannot target object properties: you must specify table column names and not |
| 111 | +PHP class property names. |
| 112 | +::: |
| 113 | + |
| 114 | +@@@ |
| 115 | + |
| 116 | +When parsing a file file, you can set the following options as well: |
| 117 | + - `file_csv_enclosure`: if file is a CSV, use this as the enclosure character (default is `'"'`). |
| 118 | + - `file_csv_escape`: if file is a CSV, use this as the escape character (default is `'\\'`). |
| 119 | + - `file_csv_separator`: if file is a CSV, use this as the separator character (default is `','`). |
| 120 | + - `file_skip_header`: when reading any file, set this to true to skip the first line (default is `false`). |
| 121 | + |
| 122 | +:::tip |
| 123 | +The filename can be absolute, or relative. For relative file resolution |
| 124 | +please see [*File name resolution*](#file-name-resolution) |
| 125 | +::: |
0 commit comments