ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
InputStream.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.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
13
15
21class InputStream implements \IteratorAggregate
22{
23 private $onEmpty = null;
24 private $input = array();
25 private $open = true;
26
30 public function onEmpty(callable $onEmpty = null)
31 {
32 $this->onEmpty = $onEmpty;
33 }
34
40 public function write($input)
41 {
42 if (null === $input) {
43 return;
44 }
45 if ($this->isClosed()) {
46 throw new RuntimeException(sprintf('%s is closed', static::class));
47 }
48 $this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
49 }
50
54 public function close()
55 {
56 $this->open = false;
57 }
58
62 public function isClosed()
63 {
64 return !$this->open;
65 }
66
67 public function getIterator()
68 {
69 $this->open = true;
70
71 while ($this->open || $this->input) {
72 if (!$this->input) {
73 yield '';
74 continue;
75 }
76 $current = array_shift($this->input);
77
78 if ($current instanceof \Iterator) {
79 foreach ($current as $cur) {
80 yield $cur;
81 }
82 } else {
83 yield $current;
84 }
85 if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) {
86 $this->write($onEmpty($this));
87 }
88 }
89 }
90}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
RuntimeException for the Process Component.
Provides a way to continuously write to the input of a Process until the InputStream is closed.
Definition: InputStream.php:22
close()
Closes the write buffer.
Definition: InputStream.php:54
onEmpty(callable $onEmpty=null)
Sets a callback that is called when the write buffer becomes empty.
Definition: InputStream.php:30
isClosed()
Tells whether the write buffer is closed or not.
Definition: InputStream.php:62
write($input)
Appends an input to the write buffer.
Definition: InputStream.php:40
static validateInput($caller, $input)
Validates and normalizes a Process input.
input
Definition: langcheck.php:166