Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit ddc2fa8

Browse files
committed
Merge branch 'master' into markup
Conflicts: library/Zend/Markup/Parser/BBCode.php library/Zend/Markup/Renderer/HTML.php library/Zend/Markup/Renderer/RendererAbstract.php
4 parents a51c1a6 + 06fbdf6 + ec2d4d3 + e3c3d67 commit ddc2fa8

20 files changed

+143
-102
lines changed

src/Adapter/AMF0.php renamed to src/Adapter/Amf0.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
namespace Zend\Serializer\Adapter;
2727

2828
use Zend\Serializer\Exception as SerializationException,
29-
Zend\AMF\Parser as AMFParser;
29+
Zend\Amf\Parser as AMFParser;
3030

3131
/**
32-
* @uses Zend\AMF\Parser\AMF0\Deserializer
33-
* @uses Zend\AMF\Parser\AMF0\Serializer
34-
* @uses Zend\AMF\Parser\InputStream
35-
* @uses Zend\AMF\Parser\OutputStream
32+
* @uses Zend\Amf\Parser\Amf0\Deserializer
33+
* @uses Zend\Amf\Parser\Amf0\Serializer
34+
* @uses Zend\Amf\Parser\InputStream
35+
* @uses Zend\Amf\Parser\OutputStream
3636
* @uses Zend\Serializer\Adapter\AbstractAdapter
3737
* @uses Zend\Serializer\Exception
3838
* @category Zend
@@ -55,7 +55,7 @@ public function serialize($value, array $opts = array())
5555
{
5656
try {
5757
$stream = new AMFParser\OutputStream();
58-
$serializer = new AMFParser\AMF0\Serializer($stream);
58+
$serializer = new AMFParser\Amf0\Serializer($stream);
5959
$serializer->writeTypeMarker($value);
6060
return $stream->getStream();
6161
} catch (\Exception $e) {
@@ -75,7 +75,7 @@ public function unserialize($value, array $opts = array())
7575
{
7676
try {
7777
$stream = new AMFParser\InputStream($value);
78-
$deserializer = new AMFParser\AMF0\Deserializer($stream);
78+
$deserializer = new AMFParser\Amf0\Deserializer($stream);
7979
return $deserializer->readTypeMarker();
8080
} catch (\Exception $e) {
8181
throw new SerializationException('Unserialization failed by previous error', 0, $e);

src/Adapter/AMF3.php renamed to src/Adapter/Amf3.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
namespace Zend\Serializer\Adapter;
2727

2828
use Zend\Serializer\Exception as SerializationException,
29-
Zend\AMF\Parser as AMFParser;
29+
Zend\Amf\Parser as AMFParser;
3030

3131
/**
32-
* @uses Zend\AMF\Parser\AMF3\Deserializer
33-
* @uses Zend\AMF\Parser\AMF3\Serializer
34-
* @uses Zend\AMF\Parser\InputStream
35-
* @uses Zend\AMF\Parser\OutputStream
32+
* @uses Zend\Amf\Parser\Amf3\Deserializer
33+
* @uses Zend\Amf\Parser\Amf3\Serializer
34+
* @uses Zend\Amf\Parser\InputStream
35+
* @uses Zend\Amf\Parser\OutputStream
3636
* @uses Zend\Serializer\Adapter\AbstractAdapter
3737
* @uses Zend\Serializer\Exception
3838
* @category Zend
@@ -55,7 +55,7 @@ public function serialize($value, array $opts = array())
5555
{
5656
try {
5757
$stream = new AMFParser\OutputStream();
58-
$serializer = new AMFParser\AMF3\Serializer($stream);
58+
$serializer = new AMFParser\Amf3\Serializer($stream);
5959
$serializer->writeTypeMarker($value);
6060
return $stream->getStream();
6161
} catch (\Exception $e) {
@@ -75,7 +75,7 @@ public function unserialize($value, array $opts = array())
7575
{
7676
try {
7777
$stream = new AMFParser\InputStream($value);
78-
$deserializer = new AMFParser\AMF3\Deserializer($stream);
78+
$deserializer = new AMFParser\Amf3\Deserializer($stream);
7979
return $deserializer->readTypeMarker();
8080
} catch (\Exception $e) {
8181
throw new SerializationException('Unserialization failed by previous error', 0, $e);

src/Adapter/Igbinary.php renamed to src/Adapter/IgBinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
3737
* @license http://framework.zend.com/license/new-bsd New BSD License
3838
*/
39-
class Igbinary extends AbstractAdapter
39+
class IgBinary extends AbstractAdapter
4040
{
4141
/**
4242
* @var string Serialized null value

src/Adapter/JSON.php renamed to src/Adapter/Json.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
namespace Zend\Serializer\Adapter;
2727

2828
use Zend\Serializer\Exception as SerializationException,
29-
Zend\JSON\JSON as ZendJSON;
29+
Zend\Json\Json as ZendJson;
3030

3131
/**
32-
* @uses Zend\JSON\JSON
32+
* @uses Zend\Json\Json
3333
* @uses Zend\Serializer\Adapter\AbstractAdapter
3434
* @uses Zend\Serializer\Exception
3535
* @category Zend
@@ -38,15 +38,15 @@
3838
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
3939
* @license http://framework.zend.com/license/new-bsd New BSD License
4040
*/
41-
class JSON extends AbstractAdapter
41+
class Json extends AbstractAdapter
4242
{
4343
/**
4444
* @var array Default options
4545
*/
4646
protected $_options = array(
4747
'cycleCheck' => false,
4848
'enableJsonExprFinder' => false,
49-
'objectDecodeType' => ZendJSON::TYPE_ARRAY,
49+
'objectDecodeType' => ZendJson::TYPE_ARRAY,
5050
);
5151

5252
/**
@@ -62,7 +62,7 @@ public function serialize($value, array $opts = array())
6262
$opts = $opts + $this->_options;
6363

6464
try {
65-
return ZendJSON::encode($value, $opts['cycleCheck'], $opts);
65+
return ZendJson::encode($value, $opts['cycleCheck'], $opts);
6666
} catch (\Exception $e) {
6767
throw new SerializationException('Serialization failed', 0, $e);
6868
}
@@ -80,7 +80,7 @@ public function unserialize($json, array $opts = array())
8080
$opts = $opts + $this->_options;
8181

8282
try {
83-
$ret = ZendJSON::decode($json, $opts['objectDecodeType']);
83+
$ret = ZendJson::decode($json, $opts['objectDecodeType']);
8484
} catch (\Exception $e) {
8585
throw new SerializationException('Unserialization failed by previous error', 0, $e);
8686
}

src/Adapter/PHPCode.php renamed to src/Adapter/PhpCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
3737
* @license http://framework.zend.com/license/new-bsd New BSD License
3838
*/
39-
class PHPCode extends AbstractAdapter
39+
class PhpCode extends AbstractAdapter
4040
{
4141
/**
4242
* Serialize PHP using var_export

src/Adapter/PHPSerialize.php renamed to src/Adapter/PhpSerialize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
3737
* @license http://framework.zend.com/license/new-bsd New BSD License
3838
*/
39-
class PHPSerialize extends AbstractAdapter
39+
class PhpSerialize extends AbstractAdapter
4040
{
4141
/**
4242
* @var null|string Serialized boolean false value

src/Adapter/PythonPickle.php

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ class PythonPickle extends AbstractAdapter
106106
const OP_BINBYTES = 'B'; // push bytes; counted binary string argument
107107
const OP_SHORT_BINBYTES = 'C'; // " " ; " " " " < 256 bytes
108108

109-
/**
110-
* @var bool Whether or not this is a PHP 6 binary
111-
*/
112-
protected static $_isPhp6 = null;
113-
114109
/**
115110
* @var bool Whether or not the system is little-endian
116111
*/
@@ -162,9 +157,6 @@ public function __construct($opts=array())
162157
if (self::$_isLittleEndian === null) {
163158
self::$_isLittleEndian = (pack('l', 1) === "\x01\x00\x00\x00");
164159
}
165-
if (self::$_isPhp6 === null) {
166-
self::$_isPhp6 = !version_compare(PHP_VERSION, '6.0.0', '<');
167-
}
168160

169161
$this->_marker = new \stdClass();
170162
}
@@ -441,7 +433,7 @@ protected function _writeFloat($value)
441433
*/
442434
protected function _writeString($value)
443435
{
444-
if ( ($id=$this->_searchMomo($value)) !== false ) {
436+
if ( ($id=$this->_searchMemo($value)) !== false ) {
445437
$this->_writeGet($id);
446438
return;
447439
}
@@ -463,24 +455,24 @@ protected function _writeString($value)
463455
$this->_pickle .= self::OP_STRING . $this->_quoteString($value) . "\r\n";
464456
}
465457

466-
$this->_momorize($value);
458+
$this->_memorize($value);
467459
}
468460

469461
/**
470462
* Write an associative array value as dictionary
471463
*
472-
* @param array $value
464+
* @param array|Traversable $value
473465
* @return void
474466
*/
475-
protected function _writeArrayDict(array $value)
467+
protected function _writeArrayDict($value)
476468
{
477-
if (($id=$this->_searchMomo($value)) !== false) {
478-
$this->_writeGet($id);;
469+
if (($id=$this->_searchMemo($value)) !== false) {
470+
$this->_writeGet($id);
479471
return;
480472
}
481473

482474
$this->_pickle .= self::OP_MARK . self::OP_DICT;
483-
$this->_momorize($value);
475+
$this->_memorize($value);
484476

485477
foreach ($value as $k => $v) {
486478
$this->_pickle .= $this->_write($k)
@@ -497,15 +489,15 @@ protected function _writeArrayDict(array $value)
497489
*/
498490
protected function _writeArrayList(array $value)
499491
{
500-
if (($id = $this->_searchMomo($value)) !== false) {
492+
if (($id = $this->_searchMemo($value)) !== false) {
501493
$this->_writeGet($id);
502494
return;
503495
}
504496

505497
$this->_pickle .= self::OP_MARK . self::OP_LIST;
506-
$this->_momorize($value);
498+
$this->_memorize($value);
507499

508-
foreach ($value as $k => $v) {
500+
foreach ($value as $v) {
509501
$this->_pickle .= $this->_write($v) . self::OP_APPEND;
510502
}
511503
}
@@ -518,8 +510,25 @@ protected function _writeArrayList(array $value)
518510
*/
519511
protected function _writeObject($value)
520512
{
521-
// can't serialize php objects to python objects yet
522-
$this->_writeArrayDict(get_object_vars($value));
513+
// The main differences between a SplFixedArray and a normal PHP array is
514+
// that the SplFixedArray is of fixed length and allows only integers
515+
// within the range as indexes.
516+
if ($value instanceof \SplFixedArray) {
517+
$this->_writeArrayList($value->toArray());
518+
519+
// Use the object method toArray if available
520+
} elseif (method_exists($value, 'toArray')) {
521+
$this->_writeArrayDict($value->toArray());
522+
523+
// If the object is an iterator simply iterate it
524+
// and convert it to an dictionary
525+
} elseif ($value instanceof \Traversable) {
526+
$this->_writeArrayDict($value);
527+
528+
// other objects are simply converted by using its properties
529+
} else {
530+
$this->_writeArrayDict(get_object_vars($value));
531+
}
523532
}
524533

525534
/**
@@ -540,20 +549,20 @@ protected function _writeStop()
540549
* @param mixed $value
541550
* @return void
542551
*/
543-
protected function _momorize($value)
552+
protected function _memorize($value)
544553
{
545554
$id = count($this->_memo);
546555
$this->_memo[$id] = $value;
547556
$this->_writePut($id);
548557
}
549558

550559
/**
551-
* Search a value in the meno and return the id
560+
* Search a value in the memo and return the id
552561
*
553562
* @param mixed $value
554563
* @return int|false The id or false
555564
*/
556-
protected function _searchMomo($value)
565+
protected function _searchMemo($value)
557566
{
558567
return array_search($value, $this->_memo, true);
559568
}
@@ -1100,10 +1109,6 @@ protected function _loadUnicode()
11001109
$pattern = '/\\\\u([a-fA-F0-9]{4})/u'; // \uXXXX
11011110
$data = preg_replace_callback($pattern, array($this, '_convertMatchingUnicodeSequence2Utf8'), $data);
11021111

1103-
if (self::$_isPhp6) {
1104-
$data = unicode_decode($data, 'UTF-8');
1105-
}
1106-
11071112
$this->_stack[] = $data;
11081113
}
11091114

@@ -1168,10 +1173,6 @@ protected function _loadBinUnicode()
11681173
list(, $n) = unpack('l', $n);
11691174
$data = $this->_read($n);
11701175

1171-
if (self::$_isPhp6) {
1172-
$data = unicode_decode($data, 'UTF-8');
1173-
}
1174-
11751176
$this->_stack[] = $data;
11761177
}
11771178

src/Adapter/WDDX.php renamed to src/Adapter/Wddx.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
4040
* @license http://framework.zend.com/license/new-bsd New BSD License
4141
*/
42-
class WDDX extends AbstractAdapter
42+
class Wddx extends AbstractAdapter
4343
{
4444
/**
4545
* @var array Default options

src/Serializer.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
*/
2525
namespace Zend\Serializer;
2626

27-
use Zend\Loader\PluginLoader;
27+
use Zend\Loader\PluginLoader,
28+
Zend\Loader\ShortNameLocater;
2829

2930
/**
30-
* @uses Zend\Loader\PluginLoader\PluginLoader
31+
* @uses Zend\Loader\PluginLoader
3132
* @uses Zend\Serializer\Exception
3233
* @category Zend
3334
* @package Zend_Serializer
@@ -39,7 +40,7 @@ class Serializer
3940
/**
4041
* Plugin loader to load adapter.
4142
*
42-
* @var null|Zend\Loader\PluginLoader\PluginLoader
43+
* @var null|Zend\Loader\ShortNameLocater
4344
*/
4445
private static $_adapterLoader = null;
4546

@@ -48,7 +49,7 @@ class Serializer
4849
*
4950
* @var string|Zend\Serializer\Adapter
5051
*/
51-
protected static $_defaultAdapter = 'PHPSerialize';
52+
protected static $_defaultAdapter = 'PhpSerialize';
5253

5354
/**
5455
* Create a serializer adapter instance.
@@ -82,7 +83,7 @@ public static function factory($adapterName, $opts = array())
8283
/**
8384
* Get the adapter plugin loader.
8485
*
85-
* @return Zend\Loader\PluginLoader\PluginLoader
86+
* @return Zend\Loader\ShortNameLocater
8687
*/
8788
public static function getAdapterLoader()
8889
{
@@ -95,18 +96,18 @@ public static function getAdapterLoader()
9596
/**
9697
* Change the adapter plugin load.
9798
*
98-
* @param Zend\Loader\PluginLoader\PluginLoader $pluginLoader
99+
* @param Zend\Loader\ShortNameLocater $pluginLoader
99100
* @return void
100101
*/
101-
public static function setAdapterLoader(PluginLoader\PluginLoader $pluginLoader)
102+
public static function setAdapterLoader(ShortNameLocater $pluginLoader)
102103
{
103104
self::$_adapterLoader = $pluginLoader;
104105
}
105106

106107
/**
107108
* Resets the internal adapter plugin loader
108109
*
109-
* @return Zend\Loader\PluginLoader\PluginLoader
110+
* @return Zend\Loader\ShortNameLocater
110111
*/
111112
public static function resetAdapterLoader()
112113
{
@@ -117,11 +118,11 @@ public static function resetAdapterLoader()
117118
/**
118119
* Returns a default adapter plugin loader
119120
*
120-
* @return Zend\Loader\PluginLoader\PluginLoader
121+
* @return Zend\Loader\PluginLoader
121122
*/
122123
protected static function _getDefaultAdapterLoader()
123124
{
124-
$loader = new PluginLoader\PluginLoader();
125+
$loader = new PluginLoader();
125126
$loader->addPrefixPath('Zend\\Serializer\\Adapter\\', __DIR__ . '/Serializer/Adapter');
126127
return $loader;
127128
}

0 commit comments

Comments
 (0)