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 /** @see Zend_Amf_Parse_OutputStream */
0027 // require_once 'Zend/Amf/Parse/OutputStream.php';
0028 
0029 /** @see Zend_Amf_Parse_Amf0_Serializer */
0030 // require_once 'Zend/Amf/Parse/Amf0/Serializer.php';
0031 
0032 /** @see Zend_Amf_Parse_InputStream */
0033 // require_once 'Zend/Amf/Parse/InputStream.php';
0034 
0035 /** @see Zend_Amf_Parse_Amf0_Deserializer */
0036 // require_once 'Zend/Amf/Parse/Amf0/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_Amf0 extends Zend_Serializer_Adapter_AdapterAbstract
0046 {
0047     /**
0048      * Serialize a PHP value to AMF0 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_Amf0_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      * Unserialize an AMF0 value to PHP
0070      *
0071      * @param  mixed $value
0072      * @param  array $opts
0073      * @return void
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_Amf0_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 
0088 }