Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Context/Normalizer/UnwrappingDenormalizerContextBuilder.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Context\Normalizer;
13
14 use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
15 use Symfony\Component\PropertyAccess\PropertyPath;
16 use Symfony\Component\Serializer\Context\ContextBuilderInterface;
17 use Symfony\Component\Serializer\Context\ContextBuilderTrait;
18 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
19 use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
20
21 /**
22 * A helper providing autocompletion for available UnwrappingDenormalizer options.
23 *
24 * @author Mathias Arlaud <[email protected]>
25 */
26 final class UnwrappingDenormalizerContextBuilder implements ContextBuilderInterface
27 {
28 use ContextBuilderTrait;
29
30 /**
31 * Configures the path of wrapped data during denormalization.
32 *
33 * Eg: [foo].bar[bar]
34 *
35 * @see https://symfony.com/doc/current/components/property_access.html
36 *
37 * @throws InvalidArgumentException
38 */
39 public function withUnwrapPath(?string $unwrapPath): static
40 {
41 if (null === $unwrapPath) {
42 return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, null);
43 }
44
45 try {
46 new PropertyPath($unwrapPath);
47 } catch (InvalidPropertyPathException $e) {
48 throw new InvalidArgumentException(\sprintf('The "%s" property path is not valid.', $unwrapPath), previous: $e);
49 }
50
51 return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, $unwrapPath);
52 }
53 }