1 | <?php |
||
16 | class PathNamingStrategy implements NamingStrategyInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var array<string, string[]> |
||
20 | */ |
||
21 | private $options; |
||
22 | |||
23 | /** |
||
24 | * @param array<string, string[]> $options available options: |
||
25 | * - hash_headers: the list of header names to hash, |
||
26 | * - hash_body_methods: Methods for which the body will be hashed (Default: PUT, POST, PATCH) |
||
27 | */ |
||
28 | 8 | public function __construct(array $options = []) |
|
34 | |||
35 | 8 | public function name(RequestInterface $request): string |
|
55 | |||
56 | 8 | private function configureOptions(OptionsResolver $resolver): void |
|
57 | { |
||
58 | 8 | $resolver->setDefaults([ |
|
59 | 8 | 'hash_headers' => [], |
|
60 | 'hash_body_methods' => ['PUT', 'POST', 'PATCH'], |
||
61 | ]); |
||
62 | |||
63 | 8 | $resolver->setAllowedTypes('hash_headers', 'string[]'); |
|
64 | 8 | $resolver->setAllowedTypes('hash_body_methods', 'string[]'); |
|
65 | |||
66 | $normalizer = function (Options $options, $value) { |
||
67 | 8 | return \is_array($value) ? array_map('strtoupper', $value) : $value; |
|
68 | 8 | }; |
|
69 | 8 | $resolver->setNormalizer('hash_headers', $normalizer); |
|
70 | 8 | $resolver->setNormalizer('hash_body_methods', $normalizer); |
|
71 | 8 | } |
|
72 | |||
73 | 5 | private function hash(string $value): string |
|
77 | |||
78 | 8 | private function getHeaderHash(RequestInterface $request): ?string |
|
90 | } |
||
91 |