File indexing completed on 2024-12-22 05:37:00
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Serializer 0017 * @subpackage Adapter 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** @see Zend_Serializer_Adapter_AdapterAbstract */ 0024 // require_once 'Zend/Serializer/Adapter/AdapterAbstract.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Serializer 0029 * @subpackage Adapter 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Serializer_Adapter_PhpSerialize extends Zend_Serializer_Adapter_AdapterAbstract 0034 { 0035 /** 0036 * @var null|string Serialized boolean false value 0037 */ 0038 private static $_serializedFalse = null; 0039 0040 /** 0041 * Constructor 0042 * 0043 * @param array|Zend_Config $opts 0044 * @return void 0045 */ 0046 public function __construct($opts = array()) 0047 { 0048 parent::__construct($opts); 0049 0050 if (self::$_serializedFalse === null) { 0051 self::$_serializedFalse = serialize(false); 0052 } 0053 } 0054 0055 /** 0056 * Serialize using serialize() 0057 * 0058 * @param mixed $value 0059 * @param array $opts 0060 * @return string 0061 * @throws Zend_Serializer_Exception On serialize error 0062 */ 0063 public function serialize($value, array $opts = array()) 0064 { 0065 $ret = serialize($value); 0066 if ($ret === false) { 0067 $lastErr = error_get_last(); 0068 // require_once 'Zend/Serializer/Exception.php'; 0069 throw new Zend_Serializer_Exception($lastErr['message']); 0070 } 0071 return $ret; 0072 } 0073 0074 /** 0075 * Unserialize 0076 * 0077 * @todo Allow integration with unserialize_callback_func 0078 * @param string $serialized 0079 * @param array $opts 0080 * @return mixed 0081 * @throws Zend_Serializer_Exception on unserialize error 0082 */ 0083 public function unserialize($serialized, array $opts = array()) 0084 { 0085 // TODO: @see php.ini directive "unserialize_callback_func" 0086 $ret = @unserialize($serialized); 0087 if ($ret === false && $serialized !== self::$_serializedFalse) { 0088 $lastErr = error_get_last(); 0089 // require_once 'Zend/Serializer/Exception.php'; 0090 throw new Zend_Serializer_Exception($lastErr['message']); 0091 } 0092 return $ret; 0093 } 0094 }