Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Context/Encoder/XmlEncoderContextBuilder.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\XmlEncoder;
17
18 /**
19 * A helper providing autocompletion for available XmlEncoder options.
20 *
21 * @author Mathias Arlaud <[email protected]>
22 */
23 final class XmlEncoderContextBuilder implements ContextBuilderInterface
24 {
25 use ContextBuilderTrait;
26
27 /**
28 * Configures whether the decoded result should be considered as a collection
29 * or as a single element.
30 */
31 public function withAsCollection(?bool $asCollection): static
32 {
33 return $this->with(XmlEncoder::AS_COLLECTION, $asCollection);
34 }
35
36 /**
37 * Configures node types to ignore while decoding.
38 *
39 * @see https://php.net/dom.constants
40 *
41 * @param list<int>|null $decoderIgnoredNodeTypes
42 */
43 public function withDecoderIgnoredNodeTypes(?array $decoderIgnoredNodeTypes): static
44 {
45 return $this->with(XmlEncoder::DECODER_IGNORED_NODE_TYPES, $decoderIgnoredNodeTypes);
46 }
47
48 /**
49 * Configures node types to ignore while encoding.
50 *
51 * @see https://php.net/dom.constants
52 *
53 * @param list<int>|null $encoderIgnoredNodeTypes
54 */
55 public function withEncoderIgnoredNodeTypes(?array $encoderIgnoredNodeTypes): static
56 {
57 return $this->with(XmlEncoder::ENCODER_IGNORED_NODE_TYPES, $encoderIgnoredNodeTypes);
58 }
59
60 /**
61 * Configures the DOMDocument encoding.
62 *
63 * @see https://php.net/class.domdocument#domdocument.props.encoding
64 */
65 public function withEncoding(?string $encoding): static
66 {
67 return $this->with(XmlEncoder::ENCODING, $encoding);
68 }
69
70 /**
71 * Configures whether to encode with indentation and extra space.
72 *
73 * @see https://php.net/class.domdocument#domdocument.props.formatoutput
74 */
75 public function withFormatOutput(?bool $formatOutput): static
76 {
77 return $this->with(XmlEncoder::FORMAT_OUTPUT, $formatOutput);
78 }
79
80 /**
81 * Configures the DOMDocument::loadXml options bitmask.
82 *
83 * @see https://php.net/libxml.constants
84 *
85 * @param positive-int|null $loadOptions
86 */
87 public function withLoadOptions(?int $loadOptions): static
88 {
89 return $this->with(XmlEncoder::LOAD_OPTIONS, $loadOptions);
90 }
91
92 /**
93 * Configures the DOMDocument::saveXml options bitmask.
94 *
95 * @see https://php.net/libxml.constants
96 *
97 * @param positive-int|null $saveOptions
98 */
99 public function withSaveOptions(?int $saveOptions): static
100 {
101 return $this->with(XmlEncoder::SAVE_OPTIONS, $saveOptions);
102 }
103
104 /**
105 * Configures whether to keep empty nodes.
106 */
107 public function withRemoveEmptyTags(?bool $removeEmptyTags): static
108 {
109 return $this->with(XmlEncoder::REMOVE_EMPTY_TAGS, $removeEmptyTags);
110 }
111
112 /**
113 * Configures name of the root node.
114 */
115 public function withRootNodeName(?string $rootNodeName): static
116 {
117 return $this->with(XmlEncoder::ROOT_NODE_NAME, $rootNodeName);
118 }
119
120 /**
121 * Configures whether the document will be standalone.
122 *
123 * @see https://php.net/class.domdocument#domdocument.props.xmlstandalone
124 */
125 public function withStandalone(?bool $standalone): static
126 {
127 return $this->with(XmlEncoder::STANDALONE, $standalone);
128 }
129
130 /**
131 * Configures whether casting numeric string attributes to integers or floats.
132 */
133 public function withTypeCastAttributes(?bool $typeCastAttributes): static
134 {
135 return $this->with(XmlEncoder::TYPE_CAST_ATTRIBUTES, $typeCastAttributes);
136 }
137
138 /**
139 * Configures the version number of the document.
140 *
141 * @see https://php.net/class.domdocument#domdocument.props.xmlversion
142 */
143 public function withVersion(?string $version): static
144 {
145 return $this->with(XmlEncoder::VERSION, $version);
146 }
147
148 /**
149 * Configures whether to wrap strings within CDATA sections.
150 */
151 public function withCdataWrapping(?bool $cdataWrapping): static
152 {
153 return $this->with(XmlEncoder::CDATA_WRAPPING, $cdataWrapping);
154 }
155
156 /**
157 * Configures the pattern used to evaluate if a CDATA section should be added.
158 */
159 public function withCdataWrappingPattern(?string $cdataWrappingPattern): static
160 {
161 return $this->with(XmlEncoder::CDATA_WRAPPING_PATTERN, $cdataWrappingPattern);
162 }
163
164 /**
165 * Configures whether to ignore empty attributes.
166 */
167 public function withIgnoreEmptyAttributes(?bool $ignoreEmptyAttributes): static
168 {
169 return $this->with(XmlEncoder::IGNORE_EMPTY_ATTRIBUTES, $ignoreEmptyAttributes);
170 }
171
172 /**
173 * Configures whether to preserve numeric keys in array.
174 */
175 public function withPreserveNumericKeys(?bool $preserveNumericKeys): static
176 {
177 return $this->with(XmlEncoder::PRESERVE_NUMERIC_KEYS, $preserveNumericKeys);
178 }
179 }