Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Serializer / Adapter / PhpSerialize.php
blobd715cdce2f7d7a578b262d929642636043f11f02
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Serializer\Adapter;
12 use Zend\Serializer\Exception;
13 use Zend\Stdlib\ErrorHandler;
15 class PhpSerialize extends AbstractAdapter
17 /**
18 * Serialized boolean false value
20 * @var null|string
22 private static $serializedFalse = null;
24 /**
25 * Constructor
27 public function __construct($options = null)
29 // needed to check if a returned false is based on a serialize false
30 // or based on failure (igbinary can overwrite [un]serialize functions)
31 if (static::$serializedFalse === null) {
32 static::$serializedFalse = serialize(false);
35 parent::__construct($options);
38 /**
39 * Serialize using serialize()
41 * @param mixed $value
42 * @return string
43 * @throws Exception\RuntimeException On serialize error
45 public function serialize($value)
47 ErrorHandler::start();
48 $ret = serialize($value);
49 $err = ErrorHandler::stop();
50 if ($err) {
51 throw new Exception\RuntimeException(
52 'Serialization failed', 0, $err
56 return $ret;
59 /**
60 * Unserialize
62 * @todo Allow integration with unserialize_callback_func
63 * @param string $serialized
64 * @return mixed
65 * @throws Exception\RuntimeException on unserialize error
67 public function unserialize($serialized)
69 if (!is_string($serialized) || !preg_match('/^((s|i|d|b|a|O|C):|N;)/', $serialized)) {
70 return $serialized;
73 // If we have a serialized boolean false value, just return false;
74 // prevents the unserialize handler from creating an error.
75 if ($serialized === static::$serializedFalse) {
76 return false;
79 ErrorHandler::start(E_NOTICE);
80 $ret = unserialize($serialized);
81 $err = ErrorHandler::stop();
82 if ($ret === false) {
83 throw new Exception\RuntimeException('Unserialization failed', 0, $err);
86 return $ret;