This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4534 from gwis/feature/jsonserializable-polyfill
Introduce JsonSerializable polyfill and support in Zend\Json\Encoder
- Loading branch information
Showing
6 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib; | ||
|
||
if (version_compare(PHP_VERSION, '5.4.0', 'lt')) { | ||
class_alias( | ||
'Zend\Stdlib\JsonSerializable\PhpLegacyCompatibility', | ||
'JsonSerializable' | ||
); | ||
} | ||
|
||
/** | ||
* Polyfill for JsonSerializable | ||
* | ||
* JsonSerializable was introduced in PHP 5.4.0. | ||
* | ||
* @see http://php.net/manual/class.jsonserializable.php | ||
*/ | ||
interface JsonSerializable extends \JsonSerializable | ||
{ | ||
} |
28 changes: 28 additions & 0 deletions
28
library/Zend/Stdlib/JsonSerializable/PhpLegacyCompatibility.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib\JsonSerializable; | ||
|
||
/** | ||
* Interface compatible with the built-in JsonSerializable interface | ||
* | ||
* JsonSerializable was introduced in PHP 5.4.0. | ||
* | ||
* @see http://php.net/manual/class.jsonserializable.php | ||
*/ | ||
interface PhpLegacyCompatibility | ||
{ | ||
/** | ||
* Returns data which can be serialized by json_encode(). | ||
* | ||
* @return mixed | ||
* @see http://php.net/manual/jsonserializable.jsonserialize.php | ||
*/ | ||
public function jsonSerialize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/ZendTest/Json/TestAsset/JsonSerializableBuiltinImpl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Json | ||
*/ | ||
|
||
namespace ZendTest\Json\TestAsset; | ||
|
||
use JsonSerializable; | ||
|
||
/** | ||
* Implementation of the built-in JsonSerializable interface. | ||
* | ||
* This asset will not work in PHP <5.4.0. | ||
*/ | ||
class JsonSerializableBuiltinImpl implements JsonSerializable | ||
{ | ||
public function jsonSerialize() | ||
{ | ||
return array(__FUNCTION__); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Json | ||
*/ | ||
|
||
namespace ZendTest\Json\TestAsset; | ||
|
||
use Zend\Stdlib\JsonSerializable; | ||
|
||
class JsonSerializableZFImpl implements JsonSerializable | ||
{ | ||
public function jsonSerialize() | ||
{ | ||
return array(__FUNCTION__); | ||
} | ||
} |