|
4 | 4 |
|
5 | 5 | namespace MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer; |
6 | 6 |
|
7 | | -/** |
8 | | - * @todo |
9 | | - * Remove "extends Options" in 3.0. Change AbstractAnonymizer::__construct() signature accordingly. |
10 | | - */ |
11 | | -class Context extends Options |
| 7 | +class Context |
12 | 8 | { |
13 | | - public function __construct( |
14 | | - public Options $options = new Options(), |
15 | | - ) {} |
16 | | - |
17 | | - public function withOptions(Options $options): Context |
18 | | - { |
19 | | - return new self($options); |
20 | | - } |
21 | | - |
22 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
23 | | - private function throwOptionsDeprecation(string $method): never |
24 | | - { |
25 | | - throw new \LogicException(\sprintf("Calling %s::%s() is forbidden, this method only exists for backward compatibility purpose..", static::class, $method)); |
26 | | - } |
27 | | - |
28 | | - #[\Override] |
29 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
30 | | - public function has(string $name): bool |
31 | | - { |
32 | | - $this->throwOptionsDeprecation(__METHOD__); |
33 | | - } |
| 9 | + public readonly string $salt; |
34 | 10 |
|
35 | | - #[\Override] |
36 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
37 | | - public function get(string $name, mixed $default = null, bool $required = false): mixed |
38 | | - { |
39 | | - $this->throwOptionsDeprecation(__METHOD__); |
40 | | - } |
41 | | - |
42 | | - #[\Override] |
43 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
44 | | - public function all(): array |
45 | | - { |
46 | | - $this->throwOptionsDeprecation(__METHOD__); |
47 | | - } |
48 | | - |
49 | | - #[\Override] |
50 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
51 | | - public function count(): int |
52 | | - { |
53 | | - $this->throwOptionsDeprecation(__METHOD__); |
54 | | - } |
55 | | - |
56 | | - #[\Override] |
57 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
58 | | - public function with(array $options): Options |
59 | | - { |
60 | | - $this->throwOptionsDeprecation(__METHOD__); |
61 | | - } |
62 | | - |
63 | | - #[\Override] |
64 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
65 | | - public function toDisplayString(): string |
66 | | - { |
67 | | - $this->throwOptionsDeprecation(__METHOD__); |
68 | | - } |
69 | | - |
70 | | - #[\Override] |
71 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
72 | | - public function getString(string $name, ?string $default = null, bool $required = false): ?string |
73 | | - { |
74 | | - $this->throwOptionsDeprecation(__METHOD__); |
75 | | - } |
76 | | - |
77 | | - #[\Override] |
78 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
79 | | - public function getBool(string $name, ?bool $default = null, bool $required = false): ?bool |
80 | | - { |
81 | | - $this->throwOptionsDeprecation(__METHOD__); |
82 | | - } |
83 | | - |
84 | | - #[\Override] |
85 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
86 | | - public function getInt(string $name, ?int $default = null, bool $required = false): ?int |
87 | | - { |
88 | | - $this->throwOptionsDeprecation(__METHOD__); |
89 | | - } |
90 | | - |
91 | | - #[\Override] |
92 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
93 | | - public function getFloat(string $name, ?float $default = null, bool $required = false): ?float |
94 | | - { |
95 | | - $this->throwOptionsDeprecation(__METHOD__); |
96 | | - } |
97 | | - |
98 | | - #[\Override] |
99 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
100 | | - public function getDate(string $name, ?\DateTimeImmutable $default = null, bool $required = false): ?\DateTimeImmutable |
101 | | - { |
102 | | - $this->throwOptionsDeprecation(__METHOD__); |
| 11 | + public function __construct( |
| 12 | + ?string $salt = null, |
| 13 | + ) { |
| 14 | + $this->salt = $salt ?? self::generateRandomSalt(); |
103 | 15 | } |
104 | 16 |
|
105 | | - #[\Override] |
106 | | - #[\Deprecated(message: "Only exists for class signature backward compatibility.", since: "2.1.0")] |
107 | | - public function getInterval(string $name, ?\DateInterval $default = null, bool $required = false): ?\DateInterval |
| 17 | + public static function generateRandomSalt(): string |
108 | 18 | { |
109 | | - $this->throwOptionsDeprecation(__METHOD__); |
| 19 | + return \base64_encode(\random_bytes(12)); |
110 | 20 | } |
111 | 21 | } |
0 commit comments