Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Created September 22, 2020 10:06
Show Gist options
  • Save putzflorian/e8a187d6e7bf66cfc52fc18ec3e6d62f to your computer and use it in GitHub Desktop.
Save putzflorian/e8a187d6e7bf66cfc52fc18ec3e6d62f to your computer and use it in GitHub Desktop.
<?php
/**
* @return resource
*/
public function getStream()
{
if ($this->stream) {
if(get_resource_type($this->stream) != "stream"){
$this->stream = null;
}else{
$streamMeta = stream_get_meta_data($this->stream);
if (!@rewind($this->stream) && $streamMeta['stream_type'] === 'STDIO') {
$this->stream = null;
}
}
}
if (!$this->stream && $this->getType() != 'folder') {
if (file_exists($this->getFileSystemPath())) {
$this->stream = fopen($this->getFileSystemPath(), 'r', false, File::getContext());
} else {
$this->stream = tmpfile();
}
}
return $this->stream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment