Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
AbstractPipes.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Process\Pipes;
013
014 use Symfony\Component\Process\Exception\InvalidArgumentException;
015
016 /**
017 * @author Romain Neutron <imprec@gmail.com>
018 *
019 * @internal
020 */
021 abstract class AbstractPipes implements PipesInterface
022 {
023 public $pipes = [];
024
025 private $inputBuffer = '';
026 private $input;
027 private $blocked = true;
028 private $lastError;
029
030 /**
031 * @param resource|string|int|float|bool|\Iterator|null $input
032 */
033 public function __construct($input)
034 {
035 if (\is_resource($input) || $input instanceof \Iterator) {
036 $this->input = $input;
037 } elseif (\is_string($input)) {
038 $this->inputBuffer = $input;
039 } else {
040 $this->inputBuffer = (string) $input;
041 }
042 }
043
044 /**
045 * {@inheritdoc}
046 */
047 public function close()
048 {
049 foreach ($this->pipes as $pipe) {
050 fclose($pipe);
051 }
052 $this->pipes = [];
053 }
054
055 /**
056 * Returns true if a system call has been interrupted.
057 *
058 * @return bool
059 */
060 protected function hasSystemCallBeenInterrupted()
061 {
062 $lastError = $this->lastError;
063 $this->lastError = null;
064
065 // stream_select returns false when the `select` system call is interrupted by an incoming signal
066 return null !== $lastError && false !== stripos($lastError, 'interrupted system call');
067 }
068
069 /**
070 * Unblocks streams.
071 */
072 protected function unblock()
073 {
074 if (!$this->blocked) {
075 return;
076 }
077
078 foreach ($this->pipes as $pipe) {
079 stream_set_blocking($pipe, 0);
080 }
081 if (\is_resource($this->input)) {
082 stream_set_blocking($this->input, 0);
083 }
084
085 $this->blocked = false;
086 }
087
088 /**
089 * Writes input to stdin.
090 *
091 * @return array|null
092 *
093 * @throws InvalidArgumentException When an input iterator yields a non supported value
094 */
095 protected function write()
096 {
097 if (!isset($this->pipes[0])) {
098 return null;
099 }
100 $input = $this->input;
101
102 if ($input instanceof \Iterator) {
103 if (!$input->valid()) {
104 $input = null;
105 } elseif (\is_resource($input = $input->current())) {
106 stream_set_blocking($input, 0);
107 } elseif (!isset($this->inputBuffer[0])) {
108 if (!\is_string($input)) {
109 if (!is_scalar($input)) {
110 throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class($this->input), \gettype($input)));
111 }
112 $input = (string) $input;
113 }
114 $this->inputBuffer = $input;
115 $this->input->next();
116 $input = null;
117 } else {
118 $input = null;
119 }
120 }
121
122 $r = $e = [];
123 $w = [$this->pipes[0]];
124
125 // let's have a look if something changed in streams
126 if (false === @stream_select($r, $w, $e, 0, 0)) {
127 return null;
128 }
129
130 foreach ($w as $stdin) {
131 if (isset($this->inputBuffer[0])) {
132 $written = fwrite($stdin, $this->inputBuffer);
133 $this->inputBuffer = substr($this->inputBuffer, $written);
134 if (isset($this->inputBuffer[0])) {
135 return [$this->pipes[0]];
136 }
137 }
138
139 if ($input) {
140 for (;;) {
141 $data = fread($input, self::CHUNK_SIZE);
142 if (!isset($data[0])) {
143 break;
144 }
145 $written = fwrite($stdin, $data);
146 $data = substr($data, $written);
147 if (isset($data[0])) {
148 $this->inputBuffer = $data;
149
150 return [$this->pipes[0]];
151 }
152 }
153 if (feof($input)) {
154 if ($this->input instanceof \Iterator) {
155 $this->input->next();
156 } else {
157 $this->input = null;
158 }
159 }
160 }
161 }
162
163 // no input to read on resource, buffer is empty
164 if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
165 $this->input = null;
166 fclose($this->pipes[0]);
167 unset($this->pipes[0]);
168 } elseif (!$w) {
169 return [$this->pipes[0]];
170 }
171
172 return null;
173 }
174
175 /**
176 * @internal
177 */
178 public function handleError($type, $msg)
179 {
180 $this->lastError = $msg;
181 }
182 }
183