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 ValidatorMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Szendi committed Nov 4, 2013
159 parents a2b3a39 + cbb5bf2 + 3ef3347 + bc77506 + e5e4203 + 2a10a27 + 8ba934c + 23ca50c + fd53025 + d95e884 + fb9734f + c781722 + a76fdf6 + 7f04465 + 3bc62a9 + f574eb9 + 52d314b + bada1dc + 842e034 + b44331a + 8d1b4e9 + 59d10c2 + e630f51 + 96f4abb + bfcf88b + e2e6ee0 + bd53446 + 62fffaa + 075b3a5 + dfc876b + 2056187 + ccaac9b + 5088038 + e4fa7ad + efc7cf5 + 0f33a2d + a3589c7 + 3ddf1a3 + d86b089 + 491f302 + c0efd18 + f9e572c + 3077af2 + a811b75 + 585f923 + 9b385ff + ec1f853 + b1a5d58 + a1cf97e + c1b8314 + 1482b41 + 7d80b85 + 869bbf8 + 403ce8d + 008804b + 87522da + d31ec42 + 2f2a15a + 585cc82 + a9438e2 + d59be1f + 643e2df + a49e8f2 + 08fd26d + b52d5dc + de5abc1 + 48f2d19 + 34ca3a0 + 5169094 + 25abd15 + baa09a1 + 355680a + b2b0d91 + 6986810 + 7b1513c + 6f9a6cc + 39a1c1e + 92dbdb3 + ac3a5aa + ee15c3a + 67f414a + 49138fb + a4ebc7b + 6b11637 + f128e27 + 41746af + cc083fe + 3d54828 + ccb0392 + a8ab5b0 + 1128b0c + b5ca6d2 + 5ef536e + 6878fa7 + 66a7225 + 869024d + 82f5ac4 + a831196 + dde75d7 + 9aba77c + 8474496 + 7c3bb76 + ad8e418 + a262925 + ee212be + 7f01229 + 42758bb + e91fa40 + 21394b2 + c56da7c + 9327465 + 95794f5 + 86491b5 + b24dc4f + 295467a + dc56d1e + d4c89e8 + ddd7418 + 8d06baa + ba834b9 + 292f809 + d235382 + 2b8ddfb + a90e617 + 8897e13 + 88b1391 + dc0450d + 9fa0112 + 7b9adef + 8010d61 + 8aa284d + d94ef71 + a3e5e8a + 6601fe6 + 6290724 + 5e7c801 + d74f16a + f3c55cf + f7787b1 + e1c3e3c + 88e1629 + 3314d9a + 09dfc28 + 6eac5f2 + aa1a1a6 + c602a92 + 9275250 + 11d2caa + d3c8400 + 295642a + 3c03bad + 87df75a + 89e1265 + 5bc0027 + 83fd9fa + 3844e27 + bcf5cb7 + 1f38df6 + 5ea4665 commit c66b1db
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 107 deletions.
4 changes: 2 additions & 2 deletions src/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* 'integer' => 9,
* 'string' => 'test string',
* 'function' => Zend\Json\Expr(
* 'function() { window.alert("javascript function encoded by Zend\Json\Json") }'
* 'function () { window.alert("javascript function encoded by Zend\Json\Json") }'
* ),
* );
*
* Zend\Json\Json::encode($foo, false, array('enableJsonExprFinder' => true));
* // it will returns json encoded string:
* // {"integer":9,"string":"test string","function":function() {window.alert("javascript function encoded by Zend\Json\Json")}}
* // {"integer":9,"string":"test string","function":function () {window.alert("javascript function encoded by Zend\Json\Json")}}
* </code>
*/
class Expr
Expand Down
2 changes: 1 addition & 1 deletion src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Json
*
* @var int
*/
public static $maxRecursionDepthAllowed=25;
public static $maxRecursionDepthAllowed = 25;

/**
* @var bool
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function doRequest($request)

$this->lastResponse = $response;

// import all response data form JSON HTTP response
// import all response data from JSON HTTP response
$response->loadJson($httpResponse->getBody());

return $response;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Error
{
const ERROR_PARSE = -32768;
const ERROR_PARSE = -32700;
const ERROR_INVALID_REQUEST = -32600;
const ERROR_INVALID_METHOD = -32601;
const ERROR_INVALID_PARAMS = -32602;
Expand Down
24 changes: 22 additions & 2 deletions src/Server/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class Request
*/
protected $isMethodError = false;

/**
* Flag
* @var bool
*/
protected $isParseError = false;

/**
* Requested method
* @var string
Expand Down Expand Up @@ -178,6 +184,16 @@ public function isMethodError()
return $this->isMethodError;
}

/**
* Was a malformed JSON provided?
*
* @return bool
*/
public function isParseError()
{
return $this->isParseError;
}

/**
* Set request identifier
*
Expand Down Expand Up @@ -234,8 +250,12 @@ public function getVersion()
*/
public function loadJson($json)
{
$options = Json\Json::decode($json, Json\Json::TYPE_ARRAY);
$this->setOptions($options);
try {
$options = Json\Json::decode($json, Json\Json::TYPE_ARRAY);
$this->setOptions($options);
} catch(\Exception $e) {
$this->isParseError = true;
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function addFunction($function, $namespace = '')
$argv = array_slice($argv, 2);
}

$class = null;
if (is_string($function)) {
$method = Reflection::reflectFunction($function, $argv, $namespace);
} else {
Expand All @@ -106,7 +107,7 @@ public function addFunction($function, $namespace = '')
}
}

$definition = $this->_buildSignature($method);
$definition = $this->_buildSignature($method, $class);
$this->_addMethodServiceMap($definition);

return $this;
Expand Down Expand Up @@ -483,6 +484,10 @@ protected function _handle()
{
$request = $this->getRequest();

if($request->isParseError()){
return $this->fault('Parse error', Error::ERROR_PARSE);
}

if (!$request->isMethodError() && (null === $request->getMethod())) {
return $this->fault('Invalid Request', Error::ERROR_INVALID_REQUEST);
}
Expand Down
15 changes: 5 additions & 10 deletions test/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
* @link https://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;

use Zend\Json;

/**
* @category Zend
* @package Zend_JSON
* @subpackage UnitTests
* @group Zend_JSON
*/
class JsonTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -307,7 +303,7 @@ protected function _toArray($value)
}

$array = array();
foreach ((array)$value as $k => $v) {
foreach ((array) $value as $k => $v) {
$array[$k] = $this->_toArray($v);
}
return $array;
Expand Down Expand Up @@ -543,12 +539,12 @@ public function testEncodingMultipleNestedSwitchingSameNameKeysWithDifferentJSON
{
$data = array(
0 => array(
"alpha" => new Json\Expr("function() {}"),
"alpha" => new Json\Expr("function () {}"),
"beta" => "gamma",
),
1 => array(
"alpha" => "gamma",
"beta" => new Json\Expr("function() {}"),
"beta" => new Json\Expr("function () {}"),
),
2 => array(
"alpha" => "gamma",
Expand All @@ -558,7 +554,7 @@ public function testEncodingMultipleNestedSwitchingSameNameKeysWithDifferentJSON
$result = Json\Json::encode($data, false, array('enableJsonExprFinder' => true));

$this->assertEquals(
'[{"alpha":function() {},"beta":"gamma"},{"alpha":"gamma","beta":function() {}},{"alpha":"gamma","beta":"gamma"}]',
'[{"alpha":function () {},"beta":"gamma"},{"alpha":"gamma","beta":function () {}},{"alpha":"gamma","beta":"gamma"}]',
$result
);
}
Expand Down Expand Up @@ -598,7 +594,7 @@ public function testDisabledJSONExprFinder()

$data = array(
0 => array(
"alpha" => new Json\Expr("function() {}"),
"alpha" => new Json\Expr("function () {}"),
"beta" => "gamma",
),
);
Expand Down Expand Up @@ -1012,7 +1008,6 @@ public function toJson()

/**
* ISSUE ZF-4946
*
*/
class ToJSONWithExpr
{
Expand Down
4 changes: 0 additions & 4 deletions test/JsonXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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;
Expand All @@ -23,9 +22,6 @@
*/

/**
* @category Zend
* @package Zend_JSON
* @subpackage UnitTests
* @group Zend_JSON
*/
class JsonXmlTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Server/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server;
Expand All @@ -15,9 +14,6 @@
/**
* Test class for Zend_JSON_Server_Cache
*
* @category Zend
* @package Zend_JSON_Server
* @subpackage UnitTests
* @group Zend_JSON
* @group Zend_JSON_Server
*/
Expand Down
4 changes: 0 additions & 4 deletions test/Server/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server;
Expand All @@ -18,9 +17,6 @@
use Zend\Json\Server\Response;

/**
* @category Zend
* @package Zend_Json
* @subpackage UnitTests
* @group Zend_XmlRpc
*/
class ClientTest extends \PHPUnit_Framework_TestCase
Expand Down
8 changes: 2 additions & 6 deletions test/Server/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server;
Expand All @@ -16,9 +15,6 @@
/**
* Test class for Zend_JSON_Server_Error
*
* @category Zend
* @package Zend_JSON_Server
* @subpackage UnitTests
* @group Zend_JSON
* @group Zend_JSON_Server
*/
Expand Down Expand Up @@ -52,8 +48,8 @@ public function testCodeShouldBeErrOtherByDefault()

public function testSetCodeShouldCastToInteger()
{
$this->error->setCode('-32768');
$this->assertEquals(-32768, $this->error->getCode());
$this->error->setCode('-32700');
$this->assertEquals(-32700, $this->error->getCode());
}

public function testCodeShouldBeLimitedToStandardIntegers()
Expand Down
11 changes: 7 additions & 4 deletions test/Server/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
* @link https://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\Server;

use Zend\Json;

/**
* @category Zend
* @package Zend_JSON_Server
* @subpackage UnitTests
* @group Zend_JSON
* @group Zend_JSON_Server
*/
Expand Down Expand Up @@ -233,6 +229,13 @@ public function testMethodNamesShouldAllowDotNamespacing()
$this->assertEquals('foo.bar', $this->request->getMethod());
}

public function testIsParseErrorSetOnMalformedJson()
{
$testJson = '{"id":1, "method": "test", "params:"[1,2,3]}';
$this->request->loadJson($testJson);
$this->assertTrue($this->request->isParseError());
}

public function getOptions()
{
return array(
Expand Down
4 changes: 0 additions & 4 deletions test/Server/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server;
Expand All @@ -16,9 +15,6 @@
/**
* Test class for Zend_JSON_Server_Response
*
* @category Zend
* @package Zend_JSON_Server
* @subpackage UnitTests
* @group Zend_JSON
* @group Zend_JSON_Server
*/
Expand Down
4 changes: 0 additions & 4 deletions test/Server/Smd/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server\Smd;
Expand All @@ -16,9 +15,6 @@
/**
* Test class for Zend_JSON_Server_Smd_Service
*
* @category Zend
* @package Zend_JSON_Server
* @subpackage UnitTests
* @group Zend_JSON
* @group Zend_JSON_Server
*/
Expand Down
4 changes: 0 additions & 4 deletions test/Server/SmdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link https://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\Server;
Expand All @@ -19,9 +18,6 @@
/**
* Test class for Zend_JSON_Server_Smd
*
* @category Zend
* @package Zend_Json_Server
* @subpackage UnitTests
* @group Zend_Json
* @group Zend_Json_Server
*/
Expand Down
Loading

0 comments on commit c66b1db

Please sign in to comment.