Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Context/Encoder/YamlEncoderContextBuilder.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\Encoder;
13
14 use Symfony\Component\Serializer\Context\ContextBuilderInterface;
15 use Symfony\Component\Serializer\Context\ContextBuilderTrait;
16 use Symfony\Component\Serializer\Encoder\YamlEncoder;
17 use Symfony\Component\Yaml\Yaml;
18
19 /**
20 * A helper providing autocompletion for available YamlEncoder options.
21 *
22 * Note that the "indentation" setting is not offered in this builder because
23 * it can only be set during the construction of the YamlEncoder, but not per
24 * call.
25 *
26 * @author Mathias Arlaud <[email protected]>
27 */
28 final class YamlEncoderContextBuilder implements ContextBuilderInterface
29 {
30 use ContextBuilderTrait;
31
32 /**
33 * Configures the threshold to switch to inline YAML.
34 */
35 public function withInlineThreshold(?int $inlineThreshold): static
36 {
37 return $this->with(YamlEncoder::YAML_INLINE, $inlineThreshold);
38 }
39
40 /**
41 * Configures the indentation level.
42 *
43 * Must be positive.
44 *
45 * @param int<0, max>|null $indentLevel
46 */
47 public function withIndentLevel(?int $indentLevel): static
48 {
49 return $this->with(YamlEncoder::YAML_INDENT, $indentLevel);
50 }
51
52 /**
53 * Configures \Symfony\Component\Yaml\Dumper::dump flags bitmask.
54 *
55 * @see Yaml
56 */
57 public function withFlags(?int $flags): static
58 {
59 return $this->with(YamlEncoder::YAML_FLAGS, $flags);
60 }
61
62 /**
63 * Configures whether to preserve empty objects "{}" or to convert them to null.
64 */
65 public function withPreservedEmptyObjects(?bool $preserveEmptyObjects): static
66 {
67 return $this->with(YamlEncoder::PRESERVE_EMPTY_OBJECTS, $preserveEmptyObjects);
68 }
69 }