Skip to content

Commit

Permalink
Make bypassing readonly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
x3rAx committed Jun 27, 2023
1 parent f7f832a commit 1b90c37
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/BypassFinals.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class BypassFinals
/** @var ?string */
private static $cacheDir;

/** @var bool */
private static $bypassReadonly = false;


public static function enable(): void
{
Expand Down Expand Up @@ -59,6 +62,11 @@ public static function setCacheDirectory(?string $dir): void
self::$cacheDir = $dir;
}

public static function setBypassReadonly(bool $value = true)
{
self::$bypassReadonly = $value;
}


public function stream_open(string $path, string $mode, int $options, ?string &$openedPath): bool
{
Expand Down Expand Up @@ -141,7 +149,7 @@ public static function removeFinals(string $code): string

$code .= match ($token[0]) {
T_FINAL => '',
T_READONLY => '',
T_READONLY => (self::$bypassReadonly ? '' : $token[1]),
default => $token[1],
};
}
Expand Down

0 comments on commit 1b90c37

Please sign in to comment.