3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Serializer\Adapter
;
12 use Zend\Serializer\Exception
;
13 use Zend\Stdlib\ErrorHandler
;
15 class IgBinary
extends AbstractAdapter
18 * @var string Serialized null value
20 private static $serializedNull = null;
25 * @throws Exception\ExtensionNotLoadedException If igbinary extension is not present
27 public function __construct($options = null)
29 if (!extension_loaded('igbinary')) {
30 throw new Exception\
ExtensionNotLoadedException(
31 'PHP extension "igbinary" is required for this adapter'
35 if (static::$serializedNull === null) {
36 static::$serializedNull = igbinary_serialize(null);
39 parent
::__construct($options);
43 * Serialize PHP value to igbinary
47 * @throws Exception\RuntimeException on igbinary error
49 public function serialize($value)
51 ErrorHandler
::start();
52 $ret = igbinary_serialize($value);
53 $err = ErrorHandler
::stop();
56 throw new Exception\
RuntimeException('Serialization failed', 0, $err);
63 * Deserialize igbinary string to PHP value
65 * @param string $serialized
67 * @throws Exception\RuntimeException on igbinary error
69 public function unserialize($serialized)
71 if ($serialized === static::$serializedNull) {
75 ErrorHandler
::start();
76 $ret = igbinary_unserialize($serialized);
77 $err = ErrorHandler
::stop();
80 throw new Exception\
RuntimeException('Unserialization failed', 0, $err);