Skip to content

Commit

Permalink
feat(igbinary): check if extension is loaded, and disable auto select…
Browse files Browse the repository at this point in the history
… driver
  • Loading branch information
h4kuna committed Jul 30, 2024
1 parent a32fd62 commit 7b9c575
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/Driver/IgBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ final class IgBinary implements Driver
{
use StaticClass;

private static ?bool $extension = null;

private const NULL = "\x00";

/** @var array<string> */
Expand Down Expand Up @@ -52,6 +54,10 @@ public static function decode(string $value)
return $data;
}

public static function isIgbinaryLoaded(): bool
{
return self::$extension ??= extension_loaded('igbinary');
}

public static function serializationCheckIgbinary(string $value): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function decode(string $value)
return false;
}
error_clear_last();
if (IgBinary::serializationCheckIgbinary($value) === true) {
if (IgBinary::isIgbinaryLoaded() && IgBinary::serializationCheckIgbinary($value)) {
return IgBinary::decode($value);
}

Expand Down
6 changes: 1 addition & 5 deletions src/Driver/SetUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public static function decode(string $value)

private static function boot(): void
{
if (extension_loaded('igbinary')) {
Serialize::setUp(IgBinary::class);
} else {
Serialize::setUp(Php::class);
}
Serialize::setUp(Php::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';
Serialize::setUp(Php::class);

$data = Serialize::encode('foo');
Assert::same('foo', Php::decode($data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';
Serialize::setUp(IgBinary::class);

$data = Serialize::encode('foo');
Assert::same('foo', IgBinary::decode($data));

0 comments on commit 7b9c575

Please sign in to comment.