PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.1
4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / third-party / vendor / league / csv / src / AbstractCsv.php
wp-user-avatar / third-party / vendor / league / csv / src Last commit date
AbstractCsv.php 2 months ago ByteSequence.php 2 months ago CannotInsertRecord.php 2 months ago CharsetConverter.php 2 months ago ColumnConsistency.php 2 months ago EncloseField.php 2 months ago EscapeFormula.php 2 months ago Exception.php 2 months ago HTMLConverter.php 2 months ago Info.php 2 months ago InvalidArgument.php 2 months ago MapIterator.php 2 months ago RFC4180Field.php 2 months ago Reader.php 2 months ago ResultSet.php 2 months ago Statement.php 2 months ago Stream.php 2 months ago SyntaxError.php 2 months ago TabularDataReader.php 2 months ago UnableToProcessCsv.php 2 months ago UnavailableFeature.php 2 months ago UnavailableStream.php 2 months ago Writer.php 2 months ago XMLConverter.php 2 months ago functions.php 2 months ago functions_include.php 2 months ago
AbstractCsv.php
428 lines
1 <?php
2
3 /**
4 * League.Csv (https://csv.thephpleague.com)
5 *
6 * (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 declare (strict_types=1);
12 namespace ProfilePressVendor\League\Csv;
13
14 use Generator;
15 use SplFileObject;
16 use function filter_var;
17 use function get_class;
18 use function mb_strlen;
19 use function rawurlencode;
20 use function sprintf;
21 use function str_replace;
22 use function str_split;
23 use function strcspn;
24 use function strlen;
25 use const FILTER_FLAG_STRIP_HIGH;
26 use const FILTER_FLAG_STRIP_LOW;
27 use const FILTER_UNSAFE_RAW;
28 /**
29 * An abstract class to enable CSV document loading.
30 */
31 abstract class AbstractCsv implements ByteSequence
32 {
33 protected const STREAM_FILTER_MODE = \STREAM_FILTER_READ;
34 /** @var SplFileObject|Stream The CSV document. */
35 protected $document;
36 /** @var array<string, bool> collection of stream filters. */
37 protected array $stream_filters = [];
38 protected ?string $input_bom = null;
39 protected string $output_bom = '';
40 protected string $delimiter = ',';
41 protected string $enclosure = '"';
42 protected string $escape = '\\';
43 protected bool $is_input_bom_included = \false;
44 /**
45 * @final This method should not be overwritten in child classes
46 *
47 * @param SplFileObject|Stream $document The CSV Object instance
48 */
49 protected function __construct($document)
50 {
51 $this->document = $document;
52 [$this->delimiter, $this->enclosure, $this->escape] = $this->document->getCsvControl();
53 $this->resetProperties();
54 }
55 /**
56 * Reset dynamic object properties to improve performance.
57 */
58 abstract protected function resetProperties(): void;
59 public function __destruct()
60 {
61 unset($this->document);
62 }
63 public function __clone()
64 {
65 throw UnavailableStream::dueToForbiddenCloning(static::class);
66 }
67 /**
68 * Return a new instance from a SplFileObject.
69 *
70 * @return static
71 */
72 public static function createFromFileObject(SplFileObject $file)
73 {
74 return new static($file);
75 }
76 /**
77 * Return a new instance from a PHP resource stream.
78 *
79 * @param resource $stream
80 *
81 * @return static
82 */
83 public static function createFromStream($stream)
84 {
85 return new static(new Stream($stream));
86 }
87 /**
88 * Return a new instance from a string.
89 *
90 * @return static
91 */
92 public static function createFromString(string $content = '')
93 {
94 return new static(Stream::createFromString($content));
95 }
96 /**
97 * Return a new instance from a file path.
98 *
99 * @param resource|null $context the resource context
100 *
101 * @return static
102 */
103 public static function createFromPath(string $path, string $open_mode = 'r+', $context = null)
104 {
105 return new static(Stream::createFromPath($path, $open_mode, $context));
106 }
107 /**
108 * Returns the current field delimiter.
109 */
110 public function getDelimiter(): string
111 {
112 return $this->delimiter;
113 }
114 /**
115 * Returns the current field enclosure.
116 */
117 public function getEnclosure(): string
118 {
119 return $this->enclosure;
120 }
121 /**
122 * Returns the pathname of the underlying document.
123 */
124 public function getPathname(): string
125 {
126 return $this->document->getPathname();
127 }
128 /**
129 * Returns the current field escape character.
130 */
131 public function getEscape(): string
132 {
133 return $this->escape;
134 }
135 /**
136 * Returns the BOM sequence in use on Output methods.
137 */
138 public function getOutputBOM(): string
139 {
140 return $this->output_bom;
141 }
142 /**
143 * Returns the BOM sequence of the given CSV.
144 */
145 public function getInputBOM(): string
146 {
147 if (null !== $this->input_bom) {
148 return $this->input_bom;
149 }
150 $this->document->setFlags(SplFileObject::READ_CSV);
151 $this->document->rewind();
152 $this->input_bom = Info::fetchBOMSequence((string) $this->document->fread(4)) ?? '';
153 return $this->input_bom;
154 }
155 /**
156 * DEPRECATION WARNING! This method will be removed in the next major point release.
157 *
158 * @deprecated since version 9.7.0
159 * @see AbstractCsv::supportsStreamFilterOnRead
160 * @see AbstractCsv::supportsStreamFilterOnWrite
161 *
162 * Returns the stream filter mode.
163 */
164 public function getStreamFilterMode(): int
165 {
166 return static::STREAM_FILTER_MODE;
167 }
168 /**
169 * DEPRECATION WARNING! This method will be removed in the next major point release.
170 *
171 * @deprecated since version 9.7.0
172 * @see AbstractCsv::supportsStreamFilterOnRead
173 * @see AbstractCsv::supportsStreamFilterOnWrite
174 *
175 * Tells whether the stream filter capabilities can be used.
176 */
177 public function supportsStreamFilter(): bool
178 {
179 return $this->document instanceof Stream;
180 }
181 /**
182 * Tells whether the stream filter read capabilities can be used.
183 */
184 public function supportsStreamFilterOnRead(): bool
185 {
186 return $this->document instanceof Stream && (static::STREAM_FILTER_MODE & \STREAM_FILTER_READ) === \STREAM_FILTER_READ;
187 }
188 /**
189 * Tells whether the stream filter write capabilities can be used.
190 */
191 public function supportsStreamFilterOnWrite(): bool
192 {
193 return $this->document instanceof Stream && (static::STREAM_FILTER_MODE & \STREAM_FILTER_WRITE) === \STREAM_FILTER_WRITE;
194 }
195 /**
196 * Tell whether the specify stream filter is attach to the current stream.
197 */
198 public function hasStreamFilter(string $filtername): bool
199 {
200 return $this->stream_filters[$filtername] ?? \false;
201 }
202 /**
203 * Tells whether the BOM can be stripped if presents.
204 */
205 public function isInputBOMIncluded(): bool
206 {
207 return $this->is_input_bom_included;
208 }
209 /**
210 * Returns the CSV document as a Generator of string chunk.
211 *
212 * @param int $length number of bytes read
213 *
214 * @throws Exception if the number of bytes is lesser than 1
215 */
216 public function chunk(int $length): Generator
217 {
218 if ($length < 1) {
219 throw InvalidArgument::dueToInvalidChunkSize($length, __METHOD__);
220 }
221 $input_bom = $this->getInputBOM();
222 $this->document->rewind();
223 $this->document->setFlags(0);
224 $this->document->fseek(strlen($input_bom));
225 /** @var array<int, string> $chunks */
226 $chunks = str_split($this->output_bom . $this->document->fread($length), $length);
227 foreach ($chunks as $chunk) {
228 yield $chunk;
229 }
230 while ($this->document->valid()) {
231 yield $this->document->fread($length);
232 }
233 }
234 /**
235 * DEPRECATION WARNING! This method will be removed in the next major point release.
236 *
237 * @deprecated since version 9.1.0
238 * @see AbstractCsv::toString
239 *
240 * Retrieves the CSV content
241 */
242 public function __toString(): string
243 {
244 return $this->toString();
245 }
246 /**
247 * Retrieves the CSV content.
248 *
249 * DEPRECATION WARNING! This method will be removed in the next major point release
250 *
251 * @deprecated since version 9.7.0
252 * @see AbstractCsv::toString
253 */
254 public function getContent(): string
255 {
256 return $this->toString();
257 }
258 /**
259 * Retrieves the CSV content.
260 *
261 * @throws Exception If the string representation can not be returned
262 */
263 public function toString(): string
264 {
265 $raw = '';
266 foreach ($this->chunk(8192) as $chunk) {
267 $raw .= $chunk;
268 }
269 return $raw;
270 }
271 /**
272 * Outputs all data on the CSV file.
273 *
274 * @return int Returns the number of characters read from the handle
275 * and passed through to the output.
276 */
277 public function output(string $filename = null): int
278 {
279 if (null !== $filename) {
280 $this->sendHeaders($filename);
281 }
282 $this->document->rewind();
283 if (!$this->is_input_bom_included) {
284 $this->document->fseek(strlen($this->getInputBOM()));
285 }
286 echo $this->output_bom;
287 return strlen($this->output_bom) + (int) $this->document->fpassthru();
288 }
289 /**
290 * Send the CSV headers.
291 *
292 * Adapted from Symfony\Component\HttpFoundation\ResponseHeaderBag::makeDisposition
293 *
294 * @throws Exception if the submitted header is invalid according to RFC 6266
295 *
296 * @see https://tools.ietf.org/html/rfc6266#section-4.3
297 */
298 protected function sendHeaders(string $filename): void
299 {
300 if (strlen($filename) != strcspn($filename, '\/')) {
301 throw InvalidArgument::dueToInvalidHeaderFilename($filename);
302 }
303 $flag = FILTER_FLAG_STRIP_LOW;
304 if (strlen($filename) !== mb_strlen($filename)) {
305 $flag |= FILTER_FLAG_STRIP_HIGH;
306 }
307 /** @var string $filtered_name */
308 $filtered_name = filter_var($filename, FILTER_UNSAFE_RAW, $flag);
309 $filename_fallback = str_replace('%', '', $filtered_name);
310 $disposition = sprintf('attachment; filename="%s"', str_replace('"', '\"', $filename_fallback));
311 if ($filename !== $filename_fallback) {
312 $disposition .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
313 }
314 header('Content-Type: text/csv');
315 header('Content-Transfer-Encoding: binary');
316 header('Content-Description: File Transfer');
317 header('Content-Disposition: ' . $disposition);
318 }
319 /**
320 * Sets the field delimiter.
321 *
322 * @throws InvalidArgument If the Csv control character is not one character only.
323 *
324 * @return static
325 */
326 public function setDelimiter(string $delimiter): self
327 {
328 if ($delimiter === $this->delimiter) {
329 return $this;
330 }
331 if (1 !== strlen($delimiter)) {
332 throw InvalidArgument::dueToInvalidDelimiterCharacter($delimiter, __METHOD__);
333 }
334 $this->delimiter = $delimiter;
335 $this->resetProperties();
336 return $this;
337 }
338 /**
339 * Sets the field enclosure.
340 *
341 * @throws InvalidArgument If the Csv control character is not one character only.
342 *
343 * @return static
344 */
345 public function setEnclosure(string $enclosure): self
346 {
347 if ($enclosure === $this->enclosure) {
348 return $this;
349 }
350 if (1 !== strlen($enclosure)) {
351 throw InvalidArgument::dueToInvalidEnclosureCharacter($enclosure, __METHOD__);
352 }
353 $this->enclosure = $enclosure;
354 $this->resetProperties();
355 return $this;
356 }
357 /**
358 * Sets the field escape character.
359 *
360 * @throws InvalidArgument If the Csv control character is not one character only.
361 *
362 * @return static
363 */
364 public function setEscape(string $escape): self
365 {
366 if ($escape === $this->escape) {
367 return $this;
368 }
369 if ('' !== $escape && 1 !== strlen($escape)) {
370 throw InvalidArgument::dueToInvalidEscapeCharacter($escape, __METHOD__);
371 }
372 $this->escape = $escape;
373 $this->resetProperties();
374 return $this;
375 }
376 /**
377 * Enables BOM Stripping.
378 *
379 * @return static
380 */
381 public function skipInputBOM(): self
382 {
383 $this->is_input_bom_included = \false;
384 return $this;
385 }
386 /**
387 * Disables skipping Input BOM.
388 *
389 * @return static
390 */
391 public function includeInputBOM(): self
392 {
393 $this->is_input_bom_included = \true;
394 return $this;
395 }
396 /**
397 * Sets the BOM sequence to prepend the CSV on output.
398 *
399 * @return static
400 */
401 public function setOutputBOM(string $str): self
402 {
403 $this->output_bom = $str;
404 return $this;
405 }
406 /**
407 * append a stream filter.
408 *
409 * @param null|array $params
410 *
411 * @throws InvalidArgument If the stream filter API can not be appended
412 * @throws UnavailableFeature If the stream filter API can not be used
413 *
414 * @return static
415 */
416 public function addStreamFilter(string $filtername, $params = null): self
417 {
418 if (!$this->document instanceof Stream) {
419 throw UnavailableFeature::dueToUnsupportedStreamFilterApi(get_class($this->document));
420 }
421 $this->document->appendFilter($filtername, static::STREAM_FILTER_MODE, $params);
422 $this->stream_filters[$filtername] = \true;
423 $this->resetProperties();
424 $this->input_bom = null;
425 return $this;
426 }
427 }
428