| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 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\CsvEncoder; |
| 17 |
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
final class CsvEncoderContextBuilder implements ContextBuilderInterface |
| 25 |
{ |
| 26 |
use ContextBuilderTrait; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function withDelimiter(?string $delimiter): static |
| 36 |
{ |
| 37 |
if (null !== $delimiter && 1 !== \strlen($delimiter)) { |
| 38 |
throw new InvalidArgumentException(\sprintf('The "%s" delimiter must be a single character.', $delimiter)); |
| 39 |
} |
| 40 |
|
| 41 |
return $this->with(CsvEncoder::DELIMITER_KEY, $delimiter); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function withEnclosure(?string $enclosure): static |
| 52 |
{ |
| 53 |
if (null !== $enclosure && 1 !== \strlen($enclosure)) { |
| 54 |
throw new InvalidArgumentException(\sprintf('The "%s" enclosure must be a single character.', $enclosure)); |
| 55 |
} |
| 56 |
|
| 57 |
return $this->with(CsvEncoder::ENCLOSURE_KEY, $enclosure); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function withEscapeChar(?string $escapeChar): static |
| 70 |
{ |
| 71 |
trigger_deprecation('symfony/serializer', '7.2', 'The "%s" method is deprecated. It will be removed in 8.0.', __METHOD__); |
| 72 |
|
| 73 |
if (null !== $escapeChar && \strlen($escapeChar) > 1) { |
| 74 |
throw new InvalidArgumentException(\sprintf('The "%s" escape character must be empty or a single character.', $escapeChar)); |
| 75 |
} |
| 76 |
|
| 77 |
return $this->with(CsvEncoder::ESCAPE_CHAR_KEY, $escapeChar); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function withKeySeparator(?string $keySeparator): static |
| 84 |
{ |
| 85 |
return $this->with(CsvEncoder::KEY_SEPARATOR_KEY, $keySeparator); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public function withHeaders(?array $headers): static |
| 94 |
{ |
| 95 |
return $this->with(CsvEncoder::HEADERS_KEY, $headers); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public function withEscapedFormulas(?bool $escapedFormulas): static |
| 102 |
{ |
| 103 |
return $this->with(CsvEncoder::ESCAPE_FORMULAS_KEY, $escapedFormulas); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public function withAsCollection(?bool $asCollection): static |
| 111 |
{ |
| 112 |
return $this->with(CsvEncoder::AS_COLLECTION_KEY, $asCollection); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public function withNoHeaders(?bool $noHeaders): static |
| 119 |
{ |
| 120 |
return $this->with(CsvEncoder::NO_HEADERS_KEY, $noHeaders); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public function withEndOfLine(?string $endOfLine): static |
| 127 |
{ |
| 128 |
return $this->with(CsvEncoder::END_OF_LINE, $endOfLine); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public function withOutputUtf8Bom(?bool $outputUtf8Bom): static |
| 136 |
{ |
| 137 |
return $this->with(CsvEncoder::OUTPUT_UTF8_BOM_KEY, $outputUtf8Bom); |
| 138 |
} |
| 139 |
} |