|
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: Amf3.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 /** @see Zend_Amf_Parse_OutputStream */ |
|
27 require_once 'Zend/Amf/Parse/OutputStream.php'; |
|
28 |
|
29 /** @see Zend_Amf_Parse_Amf3_Serializer */ |
|
30 require_once 'Zend/Amf/Parse/Amf3/Serializer.php'; |
|
31 |
|
32 /** @see Zend_Amf_Parse_InputStream */ |
|
33 require_once 'Zend/Amf/Parse/InputStream.php'; |
|
34 |
|
35 /** @see Zend_Amf_Parse_Amf3_Deserializer */ |
|
36 require_once 'Zend/Amf/Parse/Amf3/Deserializer.php'; |
|
37 |
|
38 /** |
|
39 * @category Zend |
|
40 * @package Zend_Serializer |
|
41 * @subpackage Adapter |
|
42 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
43 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
44 */ |
|
45 class Zend_Serializer_Adapter_Amf3 extends Zend_Serializer_Adapter_AdapterAbstract |
|
46 { |
|
47 /** |
|
48 * Serialize a PHP value to AMF3 format |
|
49 * |
|
50 * @param mixed $value |
|
51 * @param array $opts |
|
52 * @return string |
|
53 * @throws Zend_Serializer_Exception |
|
54 */ |
|
55 public function serialize($value, array $opts = array()) |
|
56 { |
|
57 try { |
|
58 $stream = new Zend_Amf_Parse_OutputStream(); |
|
59 $serializer = new Zend_Amf_Parse_Amf3_Serializer($stream); |
|
60 $serializer->writeTypeMarker($value); |
|
61 return $stream->getStream(); |
|
62 } catch (Exception $e) { |
|
63 require_once 'Zend/Serializer/Exception.php'; |
|
64 throw new Zend_Serializer_Exception('Serialization failed by previous error', 0, $e); |
|
65 } |
|
66 } |
|
67 |
|
68 /** |
|
69 * Deserialize an AMF3 value to PHP |
|
70 * |
|
71 * @param mixed $value |
|
72 * @param array $opts |
|
73 * @return string |
|
74 * @throws Zend_Serializer_Exception |
|
75 */ |
|
76 public function unserialize($value, array $opts = array()) |
|
77 { |
|
78 try { |
|
79 $stream = new Zend_Amf_Parse_InputStream($value); |
|
80 $deserializer = new Zend_Amf_Parse_Amf3_Deserializer($stream); |
|
81 return $deserializer->readTypeMarker(); |
|
82 } catch (Exception $e) { |
|
83 require_once 'Zend/Serializer/Exception.php'; |
|
84 throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e); |
|
85 } |
|
86 } |
|
87 } |