Skip to content

Commit

Permalink
implement streamWrapper stream_set_option
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Jan 3, 2020
1 parent 3bb56d4 commit d88d27f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/Debug/FileStreamWrapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPDebugConsole
*
Expand Down Expand Up @@ -73,7 +74,7 @@ public static function register($pathsExclude = array())
a) want to make sure we modify required files
b) don't want to cache modified files
*/
\ini_set('opcache.enable', 0);
\ini_set('opcache.enable', '0');
}

/**
Expand Down Expand Up @@ -428,7 +429,7 @@ public function stream_read($count)
$isRequire = !\in_array($backtrace[1]['function'], array('file_get_contents'));
if (!$this->declaredTicks && $isRequire) {
foreach (self::$pathsExclude as $excludePath) {
if (\strpos($this->filepath, $excludePath.DIRECTORY_SEPARATOR) === 0) {
if (\strpos($this->filepath, $excludePath . DIRECTORY_SEPARATOR) === 0) {
$this->declaredTicks = true;
}
}
Expand All @@ -444,7 +445,7 @@ public function stream_read($count)
$this->declaredTicks = true;
self::$filesModified[] = $this->filepath;
}
$buffer = $this->bufferPrepend.$buffer;
$buffer = $this->bufferPrepend . $buffer;
$bufferLenAfter = \strlen($buffer);
$diff = $bufferLenAfter - $bufferLen;
$this->bufferPrepend = '';
Expand Down Expand Up @@ -478,6 +479,40 @@ public function stream_seek($offset, $whence = SEEK_SET)
return $success;
}

/**
* Change stream options
*
* @param integer $option [description]
* @param integer $arg1 [description]
* @param integer $arg2 [description]
*
* @return boolean
*/
public function stream_set_option($option, $arg1, $arg2)
{
if (!$this->handle || \get_resource_type($this->handle) !== 'stream') {
\trigger_error(\sprintf('The "$handle" property of "%s" need to be a stream.', __CLASS__), E_USER_WARNING);
return false;
}
self::restorePrev();
switch ($option) {
case STREAM_OPTION_BLOCKING:
$return = \stream_set_blocking($this->handle, $arg1);
break;
case STREAM_OPTION_READ_TIMEOUT:
$return = \stream_set_timeout($this->handle, $arg1, $arg2);
break;
case STREAM_OPTION_WRITE_BUFFER:
$return = \stream_set_write_buffer($this->handle, $arg1);
break;
default:
\trigger_error(\sprintf('The option "%s" is unknown for "stream_set_option" method', $option), E_ERROR);
$return = false;
}
self::register();
return $return;
}

/**
* Retrieve information about a file resource
*
Expand Down

0 comments on commit d88d27f

Please sign in to comment.