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

Commit

Permalink
Merge branch 'master' into hotfix/translator-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 41 deletions.
14 changes: 8 additions & 6 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Json;

use stdClass;
use Zend\Json\Exception\InvalidArgumentException;
use Zend\Json\Exception\RuntimeException;

Expand Down Expand Up @@ -85,6 +86,7 @@ class Decoder
* @param int $decodeType How objects should be decoded -- see
* {@link Zend_Json::TYPE_ARRAY} and {@link Zend_Json::TYPE_OBJECT} for
* valid values
* @throws InvalidArgumentException
* @return void
*/
protected function __construct($source, $decodeType)
Expand Down Expand Up @@ -176,8 +178,8 @@ protected function _decodeValue()
* {@link $decodeType}. If invalid $decodeType present, returns as an
* array.
*
* @return array|StdClass
* @throws Zend\Json\Exception\RuntimeException
* @return array|stdClass
* @throws RuntimeException
*/
protected function _decodeObject()
{
Expand Down Expand Up @@ -214,7 +216,7 @@ protected function _decodeObject()
switch ($this->decodeType) {
case Json::TYPE_OBJECT:
// Create new StdClass and populate with $members
$result = new \stdClass();
$result = new stdClass();
foreach ($members as $key => $value) {
if ($key === '') {
$key = '_empty_';
Expand All @@ -237,7 +239,7 @@ protected function _decodeObject()
* [element, element2,...,elementN]
*
* @return array
* @throws Zend\Json\Exception\RuntimeException
* @throws RuntimeException
*/
protected function _decodeArray()
{
Expand Down Expand Up @@ -288,7 +290,7 @@ protected function _eatWhitespace()
* Retrieves the next token from the source stream
*
* @return int Token constant value specified in class definition
* @throws Zend\Json\Exception\RuntimeException
* @throws RuntimeException
*/
protected function _getNextToken()
{
Expand Down Expand Up @@ -447,7 +449,7 @@ protected function _getNextToken()
*
* @link http://solarphp.com/
* @link http://svn.solarphp.com/core/trunk/Solar/Json.php
* @param string $value
* @param string $chrs
* @return string
*/
public static function decodeUnicodeString($chrs)
Expand Down
26 changes: 13 additions & 13 deletions src/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Iterator;
use IteratorAggregate;
use ReflectionClass;
use Zend\Json\Exception\InvalidArgumentException;
use Zend\Json\Exception\RecursionException;

Expand Down Expand Up @@ -49,7 +50,7 @@ class Encoder
*
* @param boolean $cycleCheck Whether or not to check for recursion when encoding
* @param array $options Additional options used during encoding
* @return void
* @return Encoder
*/
protected function __construct($cycleCheck = false, $options = array())
{
Expand Down Expand Up @@ -94,7 +95,6 @@ protected function _encodeValue(&$value)
}



/**
* Encode an object to JSON by encoding each of the public properties
*
Expand All @@ -104,8 +104,8 @@ protected function _encodeValue(&$value)
*
* @param $value object
* @return string
* @throws Zend\Json\Exception\RecursionException If recursive checks are enabled
* and the object has been serialized previously
* @throws RecursionException If recursive checks are enabled and the
* object has been serialized previously
*/
protected function _encodeObject(&$value)
{
Expand All @@ -131,7 +131,7 @@ protected function _encodeObject(&$value)
$props = '';

if (method_exists($value, 'toJson')) {
$props =',' . preg_replace("/^\{(.*)\}$/","\\1",$value->toJson());
$props =',' . preg_replace("/^\{(.*)\}$/","\\1", $value->toJson());
} else {
if ($value instanceof IteratorAggregate) {
$propCollection = $value->getIterator();
Expand Down Expand Up @@ -247,7 +247,7 @@ protected function _encodeDatum(&$value)
/**
* JSON encode a string value by escaping characters as necessary
*
* @param $value string
* @param string $string
* @return string
*/
protected function _encodeString(&$string)
Expand All @@ -272,10 +272,10 @@ protected function _encodeString(&$string)
* Encode the constants associated with the ReflectionClass
* parameter. The encoding format is based on the class2 format
*
* @param $cls ReflectionClass
* @param ReflectionClass $cls
* @return string Encoded constant block in class2 format
*/
private static function _encodeConstants(\ReflectionClass $cls)
private static function _encodeConstants(ReflectionClass $cls)
{
$result = "constants : {";
$constants = $cls->getConstants();
Expand All @@ -297,11 +297,11 @@ private static function _encodeConstants(\ReflectionClass $cls)
* Encode the public methods of the ReflectionClass in the
* class2 format
*
* @param $cls ReflectionClass
* @param ReflectionClass $cls
* @return string Encoded method fragment
*
*/
private static function _encodeMethods(\ReflectionClass $cls)
private static function _encodeMethods(ReflectionClass $cls)
{
$methods = $cls->getMethods();
$result = 'methods:{';
Expand Down Expand Up @@ -361,11 +361,11 @@ private static function _encodeMethods(\ReflectionClass $cls)
* Encode the public properties of the ReflectionClass in the class2
* format.
*
* @param $cls ReflectionClass
* @param ReflectionClass $cls
* @return string Encode properties list
*
*/
private static function _encodeVariables(\ReflectionClass $cls)
private static function _encodeVariables(ReflectionClass $cls)
{
$properties = $cls->getProperties();
$propValues = get_class_vars($cls->getName());
Expand Down Expand Up @@ -398,7 +398,7 @@ private static function _encodeVariables(\ReflectionClass $cls)
* @param $package string Optional package name appended to JavaScript
* proxy class name
* @return string The class2 (JavaScript) encoding of the class
* @throws Zend\Json\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function encodeClass($className, $package = '')
{
Expand Down
14 changes: 7 additions & 7 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Json;

use SimpleXMLElement;
use Zend\Json\Exception\RecursionException;
use Zend\Json\Exception\RuntimeException;

Expand Down Expand Up @@ -51,7 +52,7 @@ class Json
* @param int $objectDecodeType Optional; flag indicating how to decode
* objects. See {@link Zend_Json_Decoder::decode()} for details.
* @return mixed
* @throws Zend\Json\Exception\RuntimeException
* @throws RuntimeException
*/
public static function decode($encodedValue, $objectDecodeType = self::TYPE_OBJECT)
{
Expand Down Expand Up @@ -192,7 +193,7 @@ protected static function _recursiveJsonExprFinder(
* if it matches, we return a new Zend_Json_Expr instead of a text node
*
* @param SimpleXMLElement $simpleXmlElementObject
* @return Zend_Json_Expr|string
* @return Expr|string
*/
protected static function _getXmlValue($simpleXmlElementObject)
{
Expand All @@ -201,10 +202,10 @@ protected static function _getXmlValue($simpleXmlElementObject)
$match = preg_match($pattern, $simpleXmlElementObject, $matchings);
if ($match) {
return new Expr($matchings[1]);
} else {
return (trim(strval($simpleXmlElementObject)));
}
return (trim(strval($simpleXmlElementObject)));
}

/**
* _processXml - Contains the logic for xml2json
*
Expand All @@ -219,11 +220,10 @@ protected static function _getXmlValue($simpleXmlElementObject)
* calling a recursive (protected static) function in this class. Once all
* the XML elements are stored in the PHP array, it is returned to the caller.
*
* Throws a Zend\Json\RecursionException if the XML tree is deeper than the allowed limit.
*
* @param SimpleXMLElement $simpleXmlElementObject
* @param boolean $ignoreXmlAttributes
* @param integer $recursionDepth
* @throws Exception\RecursionException if the XML tree is deeper than the allowed limit.
* @return array
*/
protected static function _processXml($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth = 0)
Expand Down Expand Up @@ -259,7 +259,7 @@ protected static function _processXml($simpleXmlElementObject, $ignoreXmlAttribu
$childArray = array();
foreach ($children as $child) {
$childname = $child->getName();
$element = self::_processXml($child,$ignoreXmlAttributes,$recursionDepth + 1);
$element = self::_processXml($child, $ignoreXmlAttributes, $recursionDepth + 1);
if (array_key_exists($childname, $childArray)) {
if (empty($subChild[$childname])) {
$childArray[$childname] = array($childArray[$childname]);
Expand Down
8 changes: 6 additions & 2 deletions src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Server extends AbstractServer
*
* @param string|array|callable $function Valid PHP callback
* @param string $namespace Ignored
* @throws Exception\InvalidArgumentException if function invalid or not callable
* @return Server
*/
public function addFunction($function, $namespace = '')
Expand Down Expand Up @@ -145,7 +146,8 @@ public function setClass($class, $namespace = '', $argv = null)
*
* @param string $fault
* @param int $code
* @return false
* @param mixed $data
* @return Error
*/
public function fault($fault = null, $code = 404, $data = null)
{
Expand All @@ -158,6 +160,7 @@ public function fault($fault = null, $code = 404, $data = null)
* Handle request
*
* @param Request $request
* @throws Exception\InvalidArgumentException
* @return null|Response
*/
public function handle($request = false)
Expand Down Expand Up @@ -188,6 +191,7 @@ public function handle($request = false)
* Load function definitions
*
* @param array|Definition $definition
* @throws Exception\InvalidArgumentException
* @return void
*/
public function loadFunctions($definition)
Expand Down Expand Up @@ -462,7 +466,7 @@ protected function _getSmdMethods()
if (null === $this->smdMethods) {
$this->smdMethods = array();
$methods = get_class_methods('Zend\\Json\\Server\\Smd');
foreach ($methods as $key => $method) {
foreach ($methods as $method) {
if (!preg_match('/^(set|get)/', $method)) {
continue;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Server/Smd.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function setOptions(array $options)
* Set transport
*
* @param string $transport
* @throws Exception\InvalidArgumentException
* @return \Zend\Json\Server\Smd
*/
public function setTransport($transport)
Expand All @@ -139,6 +140,7 @@ public function getTransport()
* Set envelope
*
* @param string $envelopeType
* @throws Exception\InvalidArgumentException
* @return Smd
*/
public function setEnvelope($envelopeType)
Expand All @@ -165,6 +167,7 @@ public function getEnvelope()
* Set content type
*
* @param string $type
* @throws Exception\InvalidArgumentException
* @return \Zend\Json\Server\Smd
*/
public function setContentType($type)
Expand Down Expand Up @@ -211,7 +214,7 @@ public function getTarget()
/**
* Set service ID
*
* @param string $Id
* @param string $id
* @return Smd
*/
public function setId($id)
Expand Down Expand Up @@ -278,6 +281,8 @@ public function isDojoCompatible()
* Add Service
*
* @param Smd\Service|array $service
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
* @return Smd
*/
public function addService($service)
Expand Down
Loading

0 comments on commit 21394b2

Please sign in to comment.