Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
albert committed Aug 25, 2019
1 parent 3e31899 commit 550ac2e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/PhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@
*/
class PhpParser implements ParserInterface
{
/**
* @var bool whether [igbinary serialization](https://pecl.php.net/package/igbinary) is available or not.
*/
private $igbinaryAvailable = false;

/**
* PhpParser constructor.
*/
public function __construct()
{
$this->igbinaryAvailable = \extension_loaded('igbinary');
}

/**
* @param mixed $data
* @return string
*/
public function encode($data): string
{
return \serialize($data);
return $this->igbinaryAvailable ? \igbinary_serialize($data) : \serialize($data);
}

/**
Expand All @@ -29,6 +42,7 @@ public function encode($data): string
*/
public function decode(string $data)
{
return \unserialize($data, ['allowed_classes' => false]);
return $this->igbinaryAvailable ? \igbinary_unserialize($data) : \unserialize($data,
['allowed_classes' => false]);
}
}

0 comments on commit 550ac2e

Please sign in to comment.