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

Commit

Permalink
Merge branch 'develop' of git://github.com/zendframework/zf2 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Encoder.php
Expand Up @@ -427,7 +427,7 @@ public static function encodeClasses(array $classNames, $package = '')
{
$result = '';
foreach ($classNames as $className) {
$result .= self::encodeClass($className, $package);
$result .= static::encodeClass($className, $package);
}

return $result;
Expand Down
28 changes: 14 additions & 14 deletions src/Json.php
Expand Up @@ -57,7 +57,7 @@ class Json
public static function decode($encodedValue, $objectDecodeType = self::TYPE_OBJECT)
{
$encodedValue = (string) $encodedValue;
if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) {
if (function_exists('json_decode') && static::$useBuiltinEncoderDecoder !== true) {
$decode = json_decode($encodedValue, $objectDecodeType);

switch (json_last_error()) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public static function encode($valueToEncode, $cycleCheck = false, $options = ar
if (method_exists($valueToEncode, 'toJson')) {
return $valueToEncode->toJson();
} elseif (method_exists($valueToEncode, 'toArray')) {
return self::encode($valueToEncode->toArray(), $cycleCheck, $options);
return static::encode($valueToEncode->toArray(), $cycleCheck, $options);
}
}

Expand All @@ -114,11 +114,11 @@ public static function encode($valueToEncode, $cycleCheck = false, $options = ar
if (isset($options['enableJsonExprFinder'])
&& ($options['enableJsonExprFinder'] == true)
) {
$valueToEncode = self::_recursiveJsonExprFinder($valueToEncode, $javascriptExpressions);
$valueToEncode = static::_recursiveJsonExprFinder($valueToEncode, $javascriptExpressions);
}

// Encoding
if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
if (function_exists('json_encode') && static::$useBuiltinEncoderDecoder !== true) {
$encodedResult = json_encode(
$valueToEncode,
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
Expand Down Expand Up @@ -175,11 +175,11 @@ protected static function _recursiveJsonExprFinder(
$value = $magicKey;
} elseif (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = self::_recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k);
$value[$k] = static::_recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k);
}
} elseif (is_object($value)) {
foreach ($value as $k => $v) {
$value->$k = self::_recursiveJsonExprFinder($value->$k, $javascriptExpressions, $k);
$value->$k = static::_recursiveJsonExprFinder($value->$k, $javascriptExpressions, $k);
}
}
return $value;
Expand Down Expand Up @@ -229,23 +229,23 @@ protected static function _getXmlValue($simpleXmlElementObject)
protected static function _processXml($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth = 0)
{
// Keep an eye on how deeply we are involved in recursion.
if ($recursionDepth > self::$maxRecursionDepthAllowed) {
if ($recursionDepth > static::$maxRecursionDepthAllowed) {
// XML tree is too deep. Exit now by throwing an exception.
throw new RecursionException(
"Function _processXml exceeded the allowed recursion depth of "
. self::$maxRecursionDepthAllowed
. static::$maxRecursionDepthAllowed
);
}

$children = $simpleXmlElementObject->children();
$name = $simpleXmlElementObject->getName();
$value = self::_getXmlValue($simpleXmlElementObject);
$value = static::_getXmlValue($simpleXmlElementObject);
$attributes = (array) $simpleXmlElementObject->attributes();

if (!count($children)) {
if (!empty($attributes) && !$ignoreXmlAttributes) {
foreach ($attributes['@attributes'] as $k => $v) {
$attributes['@attributes'][$k] = self::_getXmlValue($v);
$attributes['@attributes'][$k] = static::_getXmlValue($v);
}
if (!empty($value)) {
$attributes['@text'] = $value;
Expand All @@ -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 = static::_processXml($child, $ignoreXmlAttributes, $recursionDepth + 1);
if (array_key_exists($childname, $childArray)) {
if (empty($subChild[$childname])) {
$childArray[$childname] = array($childArray[$childname]);
Expand All @@ -273,7 +273,7 @@ protected static function _processXml($simpleXmlElementObject, $ignoreXmlAttribu

if (!empty($attributes) && !$ignoreXmlAttributes) {
foreach ($attributes['@attributes'] as $k => $v) {
$attributes['@attributes'][$k] = self::_getXmlValue($v);
$attributes['@attributes'][$k] = static::_getXmlValue($v);
}
$childArray['@attributes'] = $attributes['@attributes'];
}
Expand Down Expand Up @@ -323,11 +323,11 @@ public static function fromXml ($xmlStringContents, $ignoreXmlAttributes=true)
$resultArray = null;

// Call the recursive function to convert the XML into a PHP array.
$resultArray = self::_processXml($simpleXmlElementObject, $ignoreXmlAttributes);
$resultArray = static::_processXml($simpleXmlElementObject, $ignoreXmlAttributes);

// Convert the PHP array to JSON using Zend_Json encode method.
// It is just that simple.
$jsonStringOutput = self::encode($resultArray);
$jsonStringOutput = static::encode($resultArray);
return($jsonStringOutput);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Server/Response.php
Expand Up @@ -118,10 +118,10 @@ public function getResult()
/**
* Set result error
*
* @param Error $error
* @param mixed $error
* @return Response
*/
public function setError(Error $error)
public function setError(Error $error = null)
{
$this->error = $error;
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Smd.php
Expand Up @@ -382,7 +382,7 @@ public function toArray()
$transport = $this->getTransport();
$envelope = $this->getEnvelope();
$contentType = $this->getContentType();
$SMDVersion = self::SMD_VERSION;
$SMDVersion = static::SMD_VERSION;
$service = compact('transport', 'envelope', 'contentType', 'SMDVersion');

if (null !== ($target = $this->getTarget())) {
Expand Down
7 changes: 7 additions & 0 deletions test/Server/ResponseTest.php
Expand Up @@ -67,6 +67,13 @@ public function testShouldBeAbleToRetrieveErrorObject()
$this->assertSame($error, $this->response->getError());
}

public function testErrorAccesorsShouldWorkWithNullInput()
{
$this->response->setError(null);
$this->assertNull($this->response->getError());
$this->assertFalse($this->response->isError());
}

public function testIdShouldBeNullByDefault()
{
$this->assertNull($this->response->getId());
Expand Down

0 comments on commit 6601fe6

Please sign in to comment.