1 | <?php |
||
28 | class EscapeFormula |
||
29 | { |
||
30 | /** |
||
31 | * Special characters that will be escaped |
||
32 | * |
||
33 | * @var string[] |
||
34 | */ |
||
35 | protected $special_chars = []; |
||
36 | |||
37 | /** |
||
38 | * Escape character |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $escape; |
||
43 | |||
44 | /** |
||
45 | * New instance |
||
46 | * |
||
47 | * @param string $escape |
||
48 | * @param string[] $special_chars additional special characters to escape |
||
49 | */ |
||
50 | 8 | public function __construct(string $escape = "\t", array $special_chars = []) |
|
59 | |||
60 | /** |
||
61 | * Filter submitted special characters. |
||
62 | * |
||
63 | * @param string ...$characters |
||
64 | * |
||
65 | * @throws InvalidArgumentException if the string is not a single character |
||
66 | * |
||
67 | * @return string[] |
||
68 | */ |
||
69 | 4 | protected function filterSpecialCharacters(string ...$characters): array |
|
79 | |||
80 | /** |
||
81 | * Returns the list of character the instance will escape. |
||
82 | * |
||
83 | * @return string[] |
||
84 | */ |
||
85 | 2 | public function getSpecialCharacters(): array |
|
89 | |||
90 | /** |
||
91 | * Returns the escape character. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | 2 | public function getEscape(): string |
|
99 | |||
100 | /** |
||
101 | * League CSV formatter hook. |
||
102 | * |
||
103 | * @see escapeRecord |
||
104 | * |
||
105 | * @param array $record |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | 2 | public function __invoke(array $record): array |
|
113 | |||
114 | /** |
||
115 | * Escape a CSV record. |
||
116 | * |
||
117 | * @param array $record |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | 4 | public function escapeRecord(array $record): array |
|
125 | |||
126 | /** |
||
127 | * Escape a CSV cell. |
||
128 | * |
||
129 | * @param mixed $cell |
||
130 | * |
||
131 | * @return mixed |
||
132 | */ |
||
133 | 4 | protected function escapeField($cell) |
|
146 | |||
147 | /** |
||
148 | * Tell whether the submitted value is stringable. |
||
149 | * |
||
150 | * @param mixed $value |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | 4 | protected function isStringable($value): bool |
|
158 | } |
||
159 |