File indexing completed on 2024-06-16 05:30:23

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 /** @see Zend_Amf_Parse_OutputStream */
0027 // require_once 'Zend/Amf/Parse/OutputStream.php';
0028 
0029 /** @see Zend_Amf_Parse_Amf3_Serializer */
0030 // require_once 'Zend/Amf/Parse/Amf3/Serializer.php';
0031 
0032 /** @see Zend_Amf_Parse_InputStream */
0033 // require_once 'Zend/Amf/Parse/InputStream.php';
0034 
0035 /** @see Zend_Amf_Parse_Amf3_Deserializer */
0036 // require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
0037 
0038 /**
0039  * @category   Zend
0040  * @package    Zend_Serializer
0041  * @subpackage Adapter
0042  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0043  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0044  */
0045 class Zend_Serializer_Adapter_Amf3 extends Zend_Serializer_Adapter_AdapterAbstract
0046 {
0047     /**
0048      * Serialize a PHP value to AMF3 format
0049      *
0050      * @param  mixed $value
0051      * @param  array $opts
0052      * @return string
0053      * @throws Zend_Serializer_Exception
0054      */
0055     public function serialize($value, array $opts = array())
0056     {
0057         try  {
0058             $stream     = new Zend_Amf_Parse_OutputStream();
0059             $serializer = new Zend_Amf_Parse_Amf3_Serializer($stream);
0060             $serializer->writeTypeMarker($value);
0061             return $stream->getStream();
0062         } catch (Exception $e) {
0063             // require_once 'Zend/Serializer/Exception.php';
0064             throw new Zend_Serializer_Exception('Serialization failed by previous error', 0, $e);
0065         }
0066     }
0067 
0068     /**
0069      * Deserialize an AMF3 value to PHP
0070      *
0071      * @param  mixed $value
0072      * @param  array $opts
0073      * @return string
0074      * @throws Zend_Serializer_Exception
0075      */
0076     public function unserialize($value, array $opts = array())
0077     {
0078         try {
0079             $stream       = new Zend_Amf_Parse_InputStream($value);
0080             $deserializer = new Zend_Amf_Parse_Amf3_Deserializer($stream);
0081             return $deserializer->readTypeMarker();
0082         } catch (Exception $e) {
0083             // require_once 'Zend/Serializer/Exception.php';
0084             throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
0085         }
0086     }
0087 }