web/lib/Zend/Serializer/Adapter/PhpSerialize.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Serializer
       
    17  * @subpackage Adapter
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: PhpSerialize.php 20574 2010-01-24 17:39:14Z mabe $
       
    21  */
       
    22 
       
    23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
       
    24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
       
    25 
       
    26 /**
       
    27  * @category   Zend
       
    28  * @package    Zend_Serializer
       
    29  * @subpackage Adapter
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_Serializer_Adapter_PhpSerialize extends Zend_Serializer_Adapter_AdapterAbstract
       
    34 {
       
    35     /**
       
    36      *  @var null|string Serialized boolean false value
       
    37      */
       
    38     private static $_serializedFalse = null;
       
    39 
       
    40     /**
       
    41      * Constructor
       
    42      * 
       
    43      * @param  array|Zend_Config $opts 
       
    44      * @return void
       
    45      */
       
    46     public function __construct($opts = array()) 
       
    47     {
       
    48         parent::__construct($opts);
       
    49 
       
    50         if (self::$_serializedFalse === null) {
       
    51             self::$_serializedFalse = serialize(false);
       
    52         }
       
    53     }
       
    54 
       
    55     /**
       
    56      * Serialize using serialize()
       
    57      * 
       
    58      * @param  mixed $value 
       
    59      * @param  array $opts 
       
    60      * @return string
       
    61      * @throws Zend_Serializer_Exception On serialize error
       
    62      */
       
    63     public function serialize($value, array $opts = array())
       
    64     {
       
    65         $ret = serialize($value);
       
    66         if ($ret === false) {
       
    67             $lastErr = error_get_last();
       
    68             require_once 'Zend/Serializer/Exception.php';
       
    69             throw new Zend_Serializer_Exception($lastErr['message']);
       
    70         }
       
    71         return $ret;
       
    72     }
       
    73 
       
    74     /**
       
    75      * Unserialize
       
    76      * 
       
    77      * @todo   Allow integration with unserialize_callback_func
       
    78      * @param  string $serialized 
       
    79      * @param  array $opts 
       
    80      * @return mixed
       
    81      * @throws Zend_Serializer_Exception on unserialize error
       
    82      */
       
    83     public function unserialize($serialized, array $opts = array())
       
    84     {
       
    85         // TODO: @see php.ini directive "unserialize_callback_func"
       
    86         $ret = @unserialize($serialized);
       
    87         if ($ret === false && $serialized !== self::$_serializedFalse) {
       
    88             $lastErr = error_get_last();
       
    89             require_once 'Zend/Serializer/Exception.php';
       
    90             throw new Zend_Serializer_Exception($lastErr['message']);
       
    91         }
       
    92         return $ret;
       
    93     }
       
    94 }