Skip to content

Commit

Permalink
calls previous wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 4, 2021
1 parent e829e22 commit aa88248
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/BypassFinals.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ class BypassFinals
/** @var array */
private static $pathWhitelist = ['*'];

/** @var ?object */
private static $prevWrapper;


public static function enable(): void
{
$meta = stream_get_meta_data(fopen(__FILE__, 'r'));
self::$prevWrapper = $meta['wrapper_data'] ?? null;
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, self::class);
}
Expand Down Expand Up @@ -147,8 +152,17 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
{
$usePath = (bool) ($options & STREAM_USE_PATH);
if ($mode === 'rb' && pathinfo($path, PATHINFO_EXTENSION) === 'php' && self::isPathInWhiteList($path)) {
$content = $this->native('file_get_contents', $path, $usePath, $this->context);
if ($content === false) {
if (self::$prevWrapper) {
$content = null;
self::$prevWrapper->stream_open($path, $mode, $options, $openedPath);
while (!self::$prevWrapper->stream_eof()) {
$content .= self::$prevWrapper->stream_read(8192);
}
self::$prevWrapper->stream_close();
} else {
$content = $this->native('file_get_contents', $path, $usePath, $this->context);
}
if (!is_string($content)) {
return false;
}
$modified = self::cachedRemoveFinals($content);
Expand Down

0 comments on commit aa88248

Please sign in to comment.