function QuestionHelper::cloneInputStream
Clones an input stream in order to act on one instance of the same stream without affecting the other instance.
Parameters
resource $inputStream The handler resource:
Return value
resource|null The cloned resource, null in case it could not be cloned
1 call to QuestionHelper::cloneInputStream()
- QuestionHelper::readInput in vendor/
symfony/ console/ Helper/ QuestionHelper.php - Reads one or more lines of input and returns what is read.
File
-
vendor/
symfony/ console/ Helper/ QuestionHelper.php, line 564
Class
- QuestionHelper
- The QuestionHelper class provides helpers to interact with the user.
Namespace
Symfony\Component\Console\HelperCode
private function cloneInputStream($inputStream) {
$streamMetaData = stream_get_meta_data($inputStream);
$seekable = $streamMetaData['seekable'] ?? false;
$mode = $streamMetaData['mode'] ?? 'rb';
$uri = $streamMetaData['uri'] ?? null;
if (null === $uri) {
return null;
}
$cloneStream = fopen($uri, $mode);
// For seekable and writable streams, add all the same data to the
// cloned stream and then seek to the same offset.
if (true === $seekable && !\in_array($mode, [
'r',
'rb',
'rt',
])) {
$offset = ftell($inputStream);
rewind($inputStream);
stream_copy_to_stream($inputStream, $cloneStream);
fseek($inputStream, $offset);
fseek($cloneStream, $offset);
}
return $cloneStream;
}