PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.2
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / process / InputStream.php

InputStream.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.2, at vendor/symfony/process/InputStream.php

100 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Process;
13
14 use Symfony\Component\Process\Exception\RuntimeException;
15
16 /**
17 * Provides a way to continuously write to the input of a Process until the InputStream is closed.
18 *
19 * @author Nicolas Grekas <[email protected]>
20 *
21 * @implements \IteratorAggregate<int, string>
22 */
23 class InputStream implements \IteratorAggregate
24 {
25 private ?\Closure $onEmpty = null;
26 private array $input = [];
27 private bool $open = true;
28
29 /**
30 * Sets a callback that is called when the write buffer becomes empty.
31 *
32 * @return void
33 */
34 public function onEmpty(?callable $onEmpty = null)
35 {
36 $this->onEmpty = null !== $onEmpty ? $onEmpty(...) : null;
37 }
38
39 /**
40 * Appends an input to the write buffer.
41 *
42 * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar,
43 * stream resource or \Traversable
44 *
45 * @return void
46 */
47 public function write(mixed $input)
48 {
49 if (null === $input) {
50 return;
51 }
52 if ($this->isClosed()) {
53 throw new RuntimeException(\sprintf('"%s" is closed.', static::class));
54 }
55 $this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
56 }
57
58 /**
59 * Closes the write buffer.
60 *
61 * @return void
62 */
63 public function close()
64 {
65 $this->open = false;
66 }
67
68 /**
69 * Tells whether the write buffer is closed or not.
70 *
71 * @return bool
72 */
73 public function isClosed()
74 {
75 return !$this->open;
76 }
77
78 public function getIterator(): \Traversable
79 {
80 $this->open = true;
81
82 while ($this->open || $this->input) {
83 if (!$this->input) {
84 yield '';
85 continue;
86 }
87 $current = array_shift($this->input);
88
89 if ($current instanceof \Iterator) {
90 yield from $current;
91 } else {
92 yield $current;
93 }
94 if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) {
95 $this->write($onEmpty($this));
96 }
97 }
98 }
99 }
100