Skip to content

Commit

Permalink
Merge c6c4430 into f4aabeb
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Dec 17, 2015
2 parents f4aabeb + c6c4430 commit 9a5bc4d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/php/org/bovigo/vfs/vfsStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ protected function resolvePath($path)
*/
public function stream_open($path, $mode, $options, $opened_path)
{
$this->omode = $mode;
$extended = ((strstr($mode, '+') !== false) ? (true) : (false));
$mode = str_replace(array('t', 'b', '+'), '', $mode);
if (in_array($mode, array('r', 'w', 'a', 'x', 'c')) === false) {
Expand Down Expand Up @@ -413,6 +414,15 @@ protected function calculateMode($mode, $extended)
*/
public function stream_close()
{
if (isset($this->fp)) {
fseek($this->fp, 0, SEEK_END);
$length = ftell($this->fp);
rewind($this->fp);
$this->content->setContent(fread($this->fp, $length));
fclose($this->fp);
$this->fp = null;
}

$this->content->lock($this, LOCK_UN);
}

Expand Down Expand Up @@ -672,11 +682,17 @@ public function stream_stat()
* @param int $cast_as
* @since 0.9.0
* @see https://github.com/mikey179/vfsStream/issues/3
* @return bool
* @return bool|resource
*/
public function stream_cast($cast_as)
{
return false;
$this->fp = fopen('php://temp', 'wb+');
if ($this->content->size() > 0 ) {
fwrite($this->fp, $this->content->getContent());
rewind($this->fp);
}

return $this->fp;
}

/**
Expand Down

0 comments on commit 9a5bc4d

Please sign in to comment.