PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / symfony / process / InputStream.php

InputStream.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/symfony/process/InputStream.php

93 lines 2.3 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 class InputStream implements \IteratorAggregate
22 {
23 /** @var callable|null */
24 private $onEmpty = null;
25 private $input = [];
26 private $open = true;
27
28 /**
29 * Sets a callback that is called when the write buffer becomes empty.
30 */
31 public function onEmpty(callable $onEmpty = null)
32 {
33 $this->onEmpty = $onEmpty;
34 }
35
36 /**
37 * Appends an input to the write buffer.
38 *
39 * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar,
40 * stream resource or \Traversable
41 */
42 public function write($input)
43 {
44 if (null === $input) {
45 return;
46 }
47 if ($this->isClosed()) {
48 throw new RuntimeException(sprintf('"%s" is closed.', static::class));
49 }
50 $this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
51 }
52
53 /**
54 * Closes the write buffer.
55 */
56 public function close()
57 {
58 $this->open = false;
59 }
60
61 /**
62 * Tells whether the write buffer is closed or not.
63 */
64 public function isClosed()
65 {
66 return !$this->open;
67 }
68
69 public function getIterator()
70 {
71 $this->open = true;
72
73 while ($this->open || $this->input) {
74 if (!$this->input) {
75 yield '';
76 continue;
77 }
78 $current = array_shift($this->input);
79
80 if ($current instanceof \Iterator) {
81 foreach ($current as $cur) {
82 yield $cur;
83 }
84 } else {
85 yield $current;
86 }
87 if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) {
88 $this->write($onEmpty($this));
89 }
90 }
91 }
92 }
93