web/lib/Zend/Serializer/Adapter/Wddx.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Serializer
    16  * @package    Zend_Serializer
    17  * @subpackage Adapter
    17  * @subpackage Adapter
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Wddx.php 20574 2010-01-24 17:39:14Z mabe $
    20  * @version    $Id: Wddx.php 25033 2012-08-17 19:50:08Z matthew $
    21  */
    21  */
    22 
    22 
    23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
    23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
    24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
    24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
    25 
    25 
    27  * @link       http://www.infoloom.com/gcaconfs/WEB/chicago98/simeonov.HTM
    27  * @link       http://www.infoloom.com/gcaconfs/WEB/chicago98/simeonov.HTM
    28  * @link       http://en.wikipedia.org/wiki/WDDX
    28  * @link       http://en.wikipedia.org/wiki/WDDX
    29  * @category   Zend
    29  * @category   Zend
    30  * @package    Zend_Serializer
    30  * @package    Zend_Serializer
    31  * @subpackage Adapter
    31  * @subpackage Adapter
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  */
    34  */
    35 class Zend_Serializer_Adapter_Wddx extends Zend_Serializer_Adapter_AdapterAbstract
    35 class Zend_Serializer_Adapter_Wddx extends Zend_Serializer_Adapter_AdapterAbstract
    36 {
    36 {
    37     /**
    37     /**
    41         'comment' => null,
    41         'comment' => null,
    42     );
    42     );
    43 
    43 
    44     /**
    44     /**
    45      * Constructor
    45      * Constructor
    46      * 
    46      *
    47      * @param  array $opts 
    47      * @param  array $opts
    48      * @return void
    48      * @return void
    49      * @throws Zend_Serializer_Exception if wddx extension not found
    49      * @throws Zend_Serializer_Exception if wddx extension not found
    50      */
    50      */
    51     public function __construct($opts = array())
    51     public function __construct($opts = array())
    52     {
    52     {
    58         parent::__construct($opts);
    58         parent::__construct($opts);
    59     }
    59     }
    60 
    60 
    61     /**
    61     /**
    62      * Serialize PHP to WDDX
    62      * Serialize PHP to WDDX
    63      * 
    63      *
    64      * @param  mixed $value 
    64      * @param  mixed $value
    65      * @param  array $opts 
    65      * @param  array $opts
    66      * @return string
    66      * @return string
    67      * @throws Zend_Serializer_Exception on wddx error
    67      * @throws Zend_Serializer_Exception on wddx error
    68      */
    68      */
    69     public function serialize($value, array $opts = array())
    69     public function serialize($value, array $opts = array())
    70     {
    70     {
    84         return $wddx;
    84         return $wddx;
    85     }
    85     }
    86 
    86 
    87     /**
    87     /**
    88      * Unserialize from WDDX to PHP
    88      * Unserialize from WDDX to PHP
    89      * 
    89      *
    90      * @param  string $wddx 
    90      * @param  string $wddx
    91      * @param  array $opts 
    91      * @param  array $opts
    92      * @return mixed
    92      * @return mixed
    93      * @throws Zend_Serializer_Exception on wddx error
    93      * @throws Zend_Serializer_Exception on wddx error
    94      */
    94      */
    95     public function unserialize($wddx, array $opts = array())
    95     public function unserialize($wddx, array $opts = array())
    96     {
    96     {
    98 
    98 
    99         if ($ret === null) {
    99         if ($ret === null) {
   100             // check if the returned NULL is valid
   100             // check if the returned NULL is valid
   101             // or based on an invalid wddx string
   101             // or based on an invalid wddx string
   102             try {
   102             try {
   103                 $simpleXml = new SimpleXMLElement($wddx);
   103                 $oldLibxmlDisableEntityLoader = libxml_disable_entity_loader(true);
       
   104                 $dom = new DOMDocument;
       
   105                 $dom->loadXML($wddx);
       
   106                 foreach ($dom->childNodes as $child) {
       
   107                     if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
       
   108                         require_once 'Zend/Serializer/Exception.php';
       
   109                         throw new Zend_Serializer_Exception(
       
   110                             'Invalid XML: Detected use of illegal DOCTYPE'
       
   111                         );
       
   112                     }
       
   113                 }
       
   114                 $simpleXml = simplexml_import_dom($dom);
       
   115                 libxml_disable_entity_loader($oldLibxmlDisableEntityLoader);
   104                 if (isset($simpleXml->data[0]->null[0])) {
   116                 if (isset($simpleXml->data[0]->null[0])) {
   105                     return null; // valid null
   117                     return null; // valid null
   106                 }
   118                 }
   107                 $errMsg = 'Can\'t unserialize wddx string';
   119                 $errMsg = 'Can\'t unserialize wddx string';
   108             } catch (Exception $e) {
   120             } catch (Exception $e) {