From f449fbd5fc365e754018e57a5a82e2f1c47ba140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Fri, 13 Jan 2012 11:02:12 +0100 Subject: [PATCH 1/7] Unified servers behavior in handling response output. --- src/Server/Server.php | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Server/Server.php b/src/Server/Server.php index 93831b6f2..134ca3d28 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -49,7 +49,7 @@ class Server extends AbstractServer * Flag: whether or not to auto-emit the response * @var bool */ - protected $_autoEmitResponse = true; + protected $returnResponse = false; /** * @var bool Flag; allow overwriting existing methods when creating server definition @@ -194,7 +194,7 @@ public function handle($request = false) $response = $this->_getReadyResponse(); // Emit response? - if ($this->autoEmitResponse()) { + if (!$this->returnResponse) { echo $response; return; } @@ -280,21 +280,49 @@ public function getResponse() * * @param bool $flag * @return Server + * @deprecated Left just for BC, drop it as soon as not used by anyone - use setReturnResponse() with negation instead. */ public function setAutoEmitResponse($flag) { - $this->_autoEmitResponse = (bool) $flag; - return $this; + return $this->setReturnResponse(!$flag); } /** * Will we auto-emit the response? * * @return bool + * @deprecated Left just for BC, drop it as soon as not used by anyone - use getReturnResponse() with negation instead. */ public function autoEmitResponse() { - return $this->_autoEmitResponse; + return !$this->getReturnResponse(); + } + + /** + * Set return response flag + * + * If true, {@link handle()} will return the response instead of + * automatically sending it back to the requesting client. + * + * The response is always available via {@link getResponse()}. + * + * @param boolean $flag + * @return \Zend\Json\Server\Server + */ + public function setReturnResponse($flag = true) + { + $this->returnResponse = ($flag) ? true : false; + return $this; + } + + /** + * Retrieve return response flag + * + * @return boolean + */ + public function getReturnResponse() + { + return $this->returnResponse; } // overloading for SMD metadata From 0945c32f03c155fe5dc4350d2e69887cd1ca0b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Fri, 13 Jan 2012 12:05:59 +0100 Subject: [PATCH 2/7] Implemented Zend\Json\Server\Client exceptions. --- src/Server/Client.php | 13 ++++---- src/Server/Exception/ErrorException.php | 40 +++++++++++++++++++++++++ src/Server/Exception/HttpException.php | 40 +++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/Server/Exception/ErrorException.php create mode 100644 src/Server/Exception/HttpException.php diff --git a/src/Server/Client.php b/src/Server/Client.php index 26bf7eab2..db8bfaf78 100644 --- a/src/Server/Client.php +++ b/src/Server/Client.php @@ -129,7 +129,7 @@ public function getLastResponse() * * @param \Zend\Json\Server\Request $request Request. * @return \Zend\Json\Server\Response Response. - * @throws Exception\HttpException When HTTP communication fails. TODO + * @throws \Zend\Json\Server\Exception\HttpException When HTTP communication fails. */ public function doRequest($request) { @@ -153,7 +153,6 @@ public function doRequest($request) $this->httpClient->setRawBody($request->__toString()); $httpResponse = $this->httpClient->setMethod('POST')->send(); - //TODO: this is temporary placeholder from ChilloutFramework's ChillDev\Json\Client - refactor for ZF2 exceptions if (!$httpResponse->isSuccess()) { throw new Exception\HttpException( $httpResponse->getReasonPhrase(), @@ -177,7 +176,7 @@ public function doRequest($request) * @param string $method Name of the method we want to call. * @param array $params Array of parameters for the method. * @return mixed Method call results. - * @throws Exception\RemoteCallException When remote call fails. TODO + * @throws \Zend\Json\Server\Exception\ErrorExceptionn When remote call fails. */ public function call($method, $params = array()) { @@ -185,13 +184,11 @@ public function call($method, $params = array()) $response = $this->doRequest($request); - //TODO: this is temporary placeholder from ChilloutFramework's ChillDev\Json\Client - refactor for ZF2 exceptions if ($response->isError()) { $error = $response->getError(); - throw new Exception\RemoteCallException( - $request->getMethod(), - $fault->getMessage(), - $fault->getCode() + throw new Exception\ErrorException( + $error->getMessage(), + $error->getCode() ); } diff --git a/src/Server/Exception/ErrorException.php b/src/Server/Exception/ErrorException.php new file mode 100644 index 000000000..e4c5a31aa --- /dev/null +++ b/src/Server/Exception/ErrorException.php @@ -0,0 +1,40 @@ + Date: Fri, 13 Jan 2012 13:04:26 +0100 Subject: [PATCH 3/7] Unified $argv argument handling in RPC servers setClass() method. --- src/Server/Server.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Server/Server.php b/src/Server/Server.php index 134ca3d28..f0217d6f2 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -144,10 +144,9 @@ public function addFunction($function, $namespace = '') */ public function setClass($class, $namespace = '', $argv = null) { - $argv = null; - if (3 < func_num_args()) { + if (2 < func_num_args()) { $argv = func_get_args(); - $argv = array_slice($argv, 3); + $argv = array_slice($argv, 2); } $reflection = Reflection::reflectClass($class, $argv, $namespace); From 6f7ca442a7e56fec65c2f9b78eced9dc6971b906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Fri, 13 Jan 2012 13:52:01 +0100 Subject: [PATCH 4/7] Unit tests for Zend\Json\Server\Client. --- test/Server/ClientTest.php | 303 +++++++++++++++++++++++++++++++++++ test/Server/ResponseTest.php | 31 ++++ test/ServerTest.php | 24 +-- 3 files changed, 346 insertions(+), 12 deletions(-) create mode 100644 test/Server/ClientTest.php diff --git a/test/Server/ClientTest.php b/test/Server/ClientTest.php new file mode 100644 index 000000000..f18a7bea6 --- /dev/null +++ b/test/Server/ClientTest.php @@ -0,0 +1,303 @@ +httpAdapter = new TestAdapter(); + $this->httpClient = new HttpClient('http://foo', + array('adapter' => $this->httpAdapter)); + + $this->jsonClient = new Client('http://foo'); + $this->jsonClient->setHttpClient($this->httpClient); + } + + // HTTP Client + + public function testGettingDefaultHttpClient() + { + $jsonClient = new Client('http://foo'); + $httpClient = $jsonClient->getHttpClient(); + //$this->assertInstanceOf('Zend\\Http\\Client', $httpClient); + $this->assertSame($httpClient, $jsonClient->getHttpClient()); + } + + public function testSettingAndGettingHttpClient() + { + $jsonClient = new Client('http://foo'); + $this->assertNotSame($this->httpClient, $jsonClient->getHttpClient()); + + $jsonClient->setHttpClient($this->httpClient); + $this->assertSame($this->httpClient, $jsonClient->getHttpClient()); + } + + public function testSettingHttpClientViaContructor() + { + $jsonClient = new Client('http://foo', $this->httpClient); + $httpClient = $jsonClient->getHttpClient(); + $this->assertSame($this->httpClient, $httpClient); + } + + // Request & Response + + public function testLastRequestAndResponseAreInitiallyNull() + { + $this->assertNull($this->jsonClient->getLastRequest()); + $this->assertNull($this->jsonClient->getLastResponse()); + } + + public function testLastRequestAndResponseAreSetAfterRpcMethodCall() + { + $this->setServerResponseTo(true); + $this->jsonClient->call('foo'); + + //$this->assertInstanceOf('Zend\\Json\\Server\\Request', $this->jsonClient->getLastRequest()); + //$this->assertInstanceOf('Zend\\Json\\Server\\Response', $this->jsonClient->getLastResponse()); + } + + public function testSuccessfulRpcMethodCallWithNoParameters() + { + $expectedMethod = 'foo'; + $expectedReturn = 7; + + $this->setServerResponseTo($expectedReturn); + $this->assertSame($expectedReturn, $this->jsonClient->call($expectedMethod)); + + $request = $this->jsonClient->getLastRequest(); + $response = $this->jsonClient->getLastResponse(); + + $this->assertSame($expectedMethod, $request->getMethod()); + $this->assertSame(array(), $request->getParams()); + $this->assertSame($expectedReturn, $response->getResult()); + $this->assertFalse($response->isError()); + } + + public function testSuccessfulRpcMethodCallWithParameters() + { + $expectedMethod = 'foobar'; + $expectedParams = array(1, 1.1, true, 'foo' => 'bar'); + $expectedReturn = array(7, false, 'foo' => 'bar'); + + $this->setServerResponseTo($expectedReturn); + + $actualReturn = $this->jsonClient->call($expectedMethod, $expectedParams); + $this->assertSame($expectedReturn, $actualReturn); + + $request = $this->jsonClient->getLastRequest(); + $response = $this->jsonClient->getLastResponse(); + + $this->assertSame($expectedMethod, $request->getMethod()); + $params = $request->getParams(); + $this->assertSame(count($expectedParams), count($params)); + $this->assertSame($expectedParams[0], $params[0]); + $this->assertSame($expectedParams[1], $params[1]); + $this->assertSame($expectedParams[2], $params[2]); + $this->assertSame($expectedParams['foo'], $params['foo']); + + $this->assertSame($expectedReturn, $response->getResult()); + $this->assertFalse($response->isError()); + } + + // Faults + + public function testRpcMethodCallThrowsOnHttpFailure() + { + $status = 404; + $message = 'Not Found'; + $body = 'oops'; + + $response = $this->makeHttpResponseFrom($body, $status, $message); + $this->httpAdapter->setResponse($response); + + $this->setExpectedException('Zend\\Json\\Server\\Exception\\HttpException', $message, $status); + $this->jsonClient->call('foo'); + } + + public function testRpcMethodCallThrowsOnJsonRpcFault() + { + $code = -32050; + $message = 'foo'; + + $error = new Error($message, $code); + $response = new Response(); + $response->setError($error); + $json = $response->toJson(); + + $response = $this->makeHttpResponseFrom($json); + $this->httpAdapter->setResponse($response); + + $this->setExpectedException('Zend\\Json\\Server\\Exception\\ErrorException', $message, $code); + $this->jsonClient->call('foo'); + } + + // HTTP handling + + public function testSettingUriOnHttpClientIsNotOverwrittenByJsonRpcClient() + { + $changedUri = 'http://bar:80'; + // Overwrite: http://foo:80 + $this->setServerResponseTo(null); + $this->jsonClient->getHttpClient()->setUri($changedUri); + $this->jsonClient->call('foo'); + $uri = $this->jsonClient->getHttpClient()->getUri()->toString(); + + $this->assertEquals($changedUri, $uri); + } + + public function testSettingNoHttpClientUriForcesClientToSetUri() + { + $baseUri = 'http://foo:80'; + $this->httpAdapter = new TestAdapter(); + $this->httpClient = new HttpClient(null, array('adapter' => $this->httpAdapter)); + + $this->jsonClient = new Client($baseUri); + $this->jsonClient->setHttpClient($this->httpClient); + + $this->setServerResponseTo(null); + $this->assertNull($this->jsonClient->getHttpClient()->getRequest()->getUri()); + $this->jsonClient->call('foo'); + $uri = $this->jsonClient->getHttpClient()->getUri(); + + $this->assertEquals($baseUri, $uri->toString()); + } + + public function testCustomHttpClientUserAgentIsNotOverridden() + { + $this->assertFalse( + $this->httpClient->getHeader('User-Agent'), + 'UA is null if no request was made' + ); + $this->setServerResponseTo(null); + $this->assertNull($this->jsonClient->call('method')); + $this->assertSame( + 'Zend_Json_Server_Client', + $this->httpClient->getHeader('User-Agent'), + 'If no custom UA is set, set Zend_Json_Server_Client' + ); + + $expectedUserAgent = 'Zend_Json_Server_Client (custom)'; + $this->httpClient->setHeaders(array('User-Agent' => $expectedUserAgent)); + + $this->setServerResponseTo(null); + $this->assertNull($this->jsonClient->call('method')); + $this->assertSame($expectedUserAgent, $this->httpClient->getHeader('User-Agent')); + } + + // Helpers + public function setServerResponseTo($nativeVars) + { + $response = $this->getServerResponseFor($nativeVars); + $this->httpAdapter->setResponse($response); + } + + public function getServerResponseFor($nativeVars) + { + $response = new Response(); + $response->setResult($nativeVars); + $json = $response->toJson(); + + $response = $this->makeHttpResponseFrom($json); + return $response; + } + + public function makeHttpResponseFrom($data, $status=200, $message='OK') + { + $headers = array("HTTP/1.1 $status $message", + "Status: $status", + 'Content-Type: application/json', + 'Content-Length: ' . strlen($data) + ); + return implode("\r\n", $headers) . "\r\n\r\n$data\r\n\r\n"; + } + + //TODO:BEGIN + public function makeHttpResponseFor($nativeVars) + { + $response = $this->getServerResponseFor($nativeVars); + return HttpResponse::fromString($response); + } + + public function mockHttpClient() + { + $this->mockedHttpClient = $this->getMock('Zend\\Http\\Client'); + $this->jsonClient->setHttpClient($this->mockedHttpClient); + } +} + +/* + * @throws \Zend\Json\Server\Exception\HttpException When HTTP communication fails. + + * @throws \Zend\Json\Server\Exception\ErrorExceptionn When remote call fails. + public function call($method, $params = array()) + { + $request = $this->createRequest($method, $params); + + $response = $this->doRequest($request); + + if ($response->isError()) { + $error = $response->getError(); + throw new Exception\ErrorException( + $error->getMessage(), + $error->getCode() + ); + } + + return $response->getResult(); + } +*/ diff --git a/test/Server/ResponseTest.php b/test/Server/ResponseTest.php index f11211ab9..14e8221c1 100644 --- a/test/Server/ResponseTest.php +++ b/test/Server/ResponseTest.php @@ -108,6 +108,25 @@ public function testVersionShouldBeLimitedToV2() } } + public function testShouldBeAbleToLoadResponseFromJSONString() + { + $options = $this->getOptions(); + $json = Json\Json::encode($options); + $this->response->loadJSON($json); + + $this->assertEquals('foobar', $this->response->getId()); + $this->assertEquals($options['result'], $this->response->getResult()); + } + + public function testLoadingFromJSONShouldSetJSONRpcVersionWhenPresent() + { + $options = $this->getOptions(); + $options['jsonrpc'] = '2.0'; + $json = Json\Json::encode($options); + $this->response->loadJSON($json); + $this->assertEquals('2.0', $this->response->getVersion()); + } + public function testResponseShouldBeAbleToCastToJSON() { $this->response->setResult(true) @@ -165,4 +184,16 @@ public function testCastToStringShouldCastToJSON() $this->assertTrue($test['result']); $this->assertEquals($this->response->getId(), $test['id']); } + + public function getOptions() + { + return array( + 'result' => array( + 5, + 'four', + true, + ), + 'id' => 'foobar' + ); + } } diff --git a/test/ServerTest.php b/test/ServerTest.php index 0bc3b75ac..9c5bb1a23 100644 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -189,14 +189,14 @@ public function testFaultShouldCreateErrorResponse() public function testResponseShouldBeEmittedAutomaticallyByDefault() { - $this->assertTrue($this->server->autoEmitResponse()); + $this->assertFalse($this->server->getReturnResponse()); } public function testShouldBeAbleToDisableAutomaticResponseEmission() { $this->testResponseShouldBeEmittedAutomaticallyByDefault(); - $this->server->setAutoEmitResponse(false); - $this->assertFalse($this->server->autoEmitResponse()); + $this->server->setReturnResponse(true); + $this->assertTrue($this->server->getReturnResponse()); } public function testShouldBeAbleToRetrieveSmdObject() @@ -257,7 +257,7 @@ public function testHandleValidMethodShouldWork() { $this->server->setClass('ZendTest\\Json\\Foo') ->addFunction('ZendTest\\Json\\FooFunc') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams(array(true, 'foo', 'bar')) @@ -278,7 +278,7 @@ public function testHandleValidMethodWithTooFewParamsShouldPassDefaultsOrNullsFo { $this->markTestSkipped('Problems with Zend_Server conversion'); $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams(array(true)) @@ -297,7 +297,7 @@ public function testHandleValidMethodWithTooManyParamsShouldWork() { $this->markTestSkipped('Problems with Zend_Server conversion'); $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams(array(true, 'foo', 'bar', 'baz')) @@ -315,7 +315,7 @@ public function testHandleValidMethodWithTooManyParamsShouldWork() public function testHandleShouldAllowNamedParamsInAnyOrder1() { $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse( false ); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams( array( @@ -336,7 +336,7 @@ public function testHandleShouldAllowNamedParamsInAnyOrder1() public function testHandleShouldAllowNamedParamsInAnyOrder2() { $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse( false ); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams( array( @@ -357,7 +357,7 @@ public function testHandleShouldAllowNamedParamsInAnyOrder2() public function testHandleValidWithoutRequiredParamShouldReturnError() { $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse( false ); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bar') ->setParams( array( @@ -375,7 +375,7 @@ public function testHandleValidWithoutRequiredParamShouldReturnError() public function testHandleRequestWithErrorsShouldReturnErrorResponse() { $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $response = $this->server->handle(); $this->assertTrue($response instanceof Response); $this->assertTrue($response->isError()); @@ -385,7 +385,7 @@ public function testHandleRequestWithErrorsShouldReturnErrorResponse() public function testHandleRequestWithInvalidMethodShouldReturnErrorResponse() { $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('bogus') ->setId('foo'); @@ -399,7 +399,7 @@ public function testHandleRequestWithExceptionShouldReturnErrorResponse() { $this->markTestSkipped('Problems with Zend_Server conversion'); $this->server->setClass('ZendTest\Json\Foo') - ->setAutoEmitResponse(false); + ->setReturnResponse(true); $request = $this->server->getRequest(); $request->setMethod('baz') ->setId('foo'); From 44ff133d7f39044d142819aa8adf5a5373e4bb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Fri, 13 Jan 2012 14:13:06 +0100 Subject: [PATCH 5/7] Opps.. that was not supposed to stay there. --- test/Server/ClientTest.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/Server/ClientTest.php b/test/Server/ClientTest.php index f18a7bea6..560ee7d09 100644 --- a/test/Server/ClientTest.php +++ b/test/Server/ClientTest.php @@ -266,7 +266,6 @@ public function makeHttpResponseFrom($data, $status=200, $message='OK') return implode("\r\n", $headers) . "\r\n\r\n$data\r\n\r\n"; } - //TODO:BEGIN public function makeHttpResponseFor($nativeVars) { $response = $this->getServerResponseFor($nativeVars); @@ -279,25 +278,3 @@ public function mockHttpClient() $this->jsonClient->setHttpClient($this->mockedHttpClient); } } - -/* - * @throws \Zend\Json\Server\Exception\HttpException When HTTP communication fails. - - * @throws \Zend\Json\Server\Exception\ErrorExceptionn When remote call fails. - public function call($method, $params = array()) - { - $request = $this->createRequest($method, $params); - - $response = $this->doRequest($request); - - if ($response->isError()) { - $error = $response->getError(); - throw new Exception\ErrorException( - $error->getMessage(), - $error->getCode() - ); - } - - return $response->getResult(); - } -*/ From 9b385ff1823b7f1d1244799d9db7973b150ac643 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 16 Jan 2012 11:22:40 -0600 Subject: [PATCH 6/7] CS cleanup of JSON-compliant support - CS cleanup -- imports, docblocks, etc. - Ensured that AMF server also supports new Server interface features --- src/Server/Client.php | 48 +++++++++++++------------ src/Server/Exception/ErrorException.php | 11 +++--- src/Server/Exception/HttpException.php | 7 +--- src/Server/Response.php | 26 +++++++------- src/Server/Server.php | 2 +- 5 files changed, 44 insertions(+), 50 deletions(-) diff --git a/src/Server/Client.php b/src/Server/Client.php index db8bfaf78..b4eb56f35 100644 --- a/src/Server/Client.php +++ b/src/Server/Client.php @@ -14,6 +14,7 @@ * * @category Zend * @package Zend_Json + * @subpackage Server * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -24,15 +25,16 @@ namespace Zend\Json\Server; use Zend\Http\Client as HttpClient, - Zend\Server\Client as ClientInterface; + Zend\Server\Client as ServerClient; /** * @category Zend * @package Zend_Json + * @subpackage Server * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Client implements ClientInterface +class Client implements ServerClient { /** * Full address of the JSON-RPC service. @@ -44,21 +46,21 @@ class Client implements ClientInterface /** * HTTP Client to use for requests. * - * @var \Zend\Http\Client + * @var HttpClient */ protected $httpClient; /** * Request of the last method call. * - * @var \Zend\Json\Server\Request + * @var Request */ protected $lastRequest; /** * Response received from the last method call. * - * @var \Zend\Json\Server\Response + * @var Response */ protected $lastResponse; @@ -73,7 +75,7 @@ class Client implements ClientInterface * Create a new JSON-RPC client to a remote server. * * @param string $server Full address of the JSON-RPC service. - * @param \Zend\Http\Client $httpClient HTTP Client to use for requests. + * @param HttpClient $httpClient HTTP Client to use for requests. */ public function __construct($server, HttpClient $httpClient = null) { @@ -84,20 +86,19 @@ public function __construct($server, HttpClient $httpClient = null) /** * Sets the HTTP client object to use for connecting the JSON-RPC server. * - * @param \Zend\Http\Client $httpClient New HTTP client to use. - * @return \Zend\Json\Server\Client Self instance. + * @param HttpClient $httpClient New HTTP client to use. + * @return Client Self instance. */ public function setHttpClient(HttpClient $httpClient) { $this->httpClient = $httpClient; - return $this; } /** * Gets the HTTP client object. * - * @return \Zend\Http\Client HTTP client. + * @return HttpClient HTTP client. */ public function getHttpClient() { @@ -107,7 +108,7 @@ public function getHttpClient() /** * The request of the last method call. * - * @return \Zend\Json\Server\Request Request instance. + * @return Request Request instance. */ public function getLastRequest() { @@ -117,7 +118,7 @@ public function getLastRequest() /** * The response received from the last method call. * - * @return \Zend\Json\Server\Response Response instance. + * @return Response Response instance. */ public function getLastResponse() { @@ -127,9 +128,9 @@ public function getLastResponse() /** * Perform an JSOC-RPC request and return a response. * - * @param \Zend\Json\Server\Request $request Request. - * @return \Zend\Json\Server\Response Response. - * @throws \Zend\Json\Server\Exception\HttpException When HTTP communication fails. + * @param Request $request Request. + * @return Response Response. + * @throws Exception\HttpException When HTTP communication fails. */ public function doRequest($request) { @@ -143,7 +144,7 @@ public function doRequest($request) $headers = $httpRequest->headers(); $headers->addHeaders(array( 'Content-Type' => 'application/json', - 'Accept' => 'application/json', + 'Accept' => 'application/json', )); if (!$headers->get('User-Agent')) { @@ -151,7 +152,8 @@ public function doRequest($request) } $this->httpClient->setRawBody($request->__toString()); - $httpResponse = $this->httpClient->setMethod('POST')->send(); + $this->httpClient->setMethod('POST'); + $httpResponse = $this->httpClient->send(); if (!$httpResponse->isSuccess()) { throw new Exception\HttpException( @@ -173,10 +175,10 @@ public function doRequest($request) /** * Send an JSON-RPC request to the service (for a specific method). * - * @param string $method Name of the method we want to call. - * @param array $params Array of parameters for the method. + * @param string $method Name of the method we want to call. + * @param array $params Array of parameters for the method. * @return mixed Method call results. - * @throws \Zend\Json\Server\Exception\ErrorExceptionn When remote call fails. + * @throws Exception\ErrorExceptionn When remote call fails. */ public function call($method, $params = array()) { @@ -198,9 +200,9 @@ public function call($method, $params = array()) /** * Create request object. * - * @param string $method Method to call. - * @param array $params List of arguments. - * @return \Zend\Json\Server\Request Created request. + * @param string $method Method to call. + * @param array $params List of arguments. + * @return Request Created request. */ protected function createRequest($method, array $params) { diff --git a/src/Server/Exception/ErrorException.php b/src/Server/Exception/ErrorException.php index e4c5a31aa..b229fb889 100644 --- a/src/Server/Exception/ErrorException.php +++ b/src/Server/Exception/ErrorException.php @@ -19,15 +19,14 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Json\Server\Exception; +use BadMethodCallException, + Zend\Json\Server\Exception; + /** * Thrown by Zend\Json\Server\Client when an JSON-RPC fault response is returned. * - * @uses Zend\Json\Server\Exception * @category Zend * @package Zend_Json * @subpackage Server @@ -35,6 +34,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ class ErrorException - extends \BadMethodCallException - implements \Zend\Json\Server\Exception + extends BadMethodCallException + implements Exception {} diff --git a/src/Server/Exception/HttpException.php b/src/Server/Exception/HttpException.php index 2cddf491e..362588b0e 100644 --- a/src/Server/Exception/HttpException.php +++ b/src/Server/Exception/HttpException.php @@ -19,22 +19,17 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Json\Server\Exception; /** * Thrown by Zend_Json_Server_Client when an HTTP error occurs during an * JSON-RPC method call. * - * @uses Zend\Json\Server\Exception * @category Zend * @package Zend_Json * @subpackage Server * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class HttpException - extends RuntimeException +class HttpException extends RuntimeException {} diff --git a/src/Server/Response.php b/src/Server/Response.php index 3d16bbfc8..577e22b0b 100644 --- a/src/Server/Response.php +++ b/src/Server/Response.php @@ -27,7 +27,6 @@ use Zend\Json\Json; /** - * @uses \Zend\Json\Json * @category Zend * @package Zend_Json * @subpackage Server @@ -38,7 +37,7 @@ class Response { /** * Response error - * @var null|\Zend\Json\Server\Error + * @var null|Error */ protected $_error; @@ -56,7 +55,7 @@ class Response /** * Service map - * @var \Zend\Json\Server\Smd\Smd + * @var Smd\Smd */ protected $_serviceMap; @@ -70,7 +69,7 @@ class Response * Set response state * * @param array $options - * @return \Zend\Json\Server\Response + * @return Response */ public function setOptions(array $options) { @@ -108,7 +107,7 @@ public function loadJson($json) * Set result * * @param mixed $value - * @return \Zend\Json\Server\Response + * @return Response */ public function setResult($value) { @@ -130,8 +129,8 @@ public function getResult() /** * Set result error * - * @param \Zend\Json\Server\Error $error - * @return \Zend\Json\Server\Response + * @param Error $error + * @return Response */ public function setError(Error $error) { @@ -142,7 +141,7 @@ public function setError(Error $error) /** * Get response error * - * @return null|\Zend\Json\Server\Error + * @return null|Error */ public function getError() { @@ -163,7 +162,7 @@ public function isError() * Set request ID * * @param mixed $name - * @return \Zend\Json\Server\Response + * @return Response */ public function setId($name) { @@ -185,7 +184,7 @@ public function getId() * Set JSON-RPC version * * @param string $version - * @return \Zend\Json\Server\Response + * @return Response */ public function setVersion($version) { @@ -260,8 +259,8 @@ public function setArgs($args) /** * Set service map object * - * @param \Zend\Json\Server\Smd\Smd $serviceMap - * @return \Zend\Json\Server\Response + * @param Smd\Smd $serviceMap + * @return Response */ public function setServiceMap($serviceMap) { @@ -272,7 +271,7 @@ public function setServiceMap($serviceMap) /** * Retrieve service map * - * @return \Zend\Json\Server\Smd\Smd|null + * @return Smd\Smd|null */ public function getServiceMap() { @@ -289,4 +288,3 @@ public function __toString() return $this->toJson(); } } - diff --git a/src/Server/Server.php b/src/Server/Server.php index f0217d6f2..03937f883 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -306,7 +306,7 @@ public function autoEmitResponse() * The response is always available via {@link getResponse()}. * * @param boolean $flag - * @return \Zend\Json\Server\Server + * @return Server */ public function setReturnResponse($flag = true) { From 5d5bd485dcdf49a091167cb83feef75637e778c3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 9 Mar 2012 10:49:33 -0600 Subject: [PATCH 7/7] Correct fix is to change class name from SMD to Smd - Updated Zend\Json\Server\SMD to Zend\Json\Server\Smd - Reverted "new SMD" to "new Smd" in Zend\Json\Server\Server --- src/Server/Server.php | 2 +- src/Server/Smd.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Server/Server.php b/src/Server/Server.php index 24e172d8c..03937f883 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -356,7 +356,7 @@ public function __call($method, $args) public function getServiceMap() { if (null === $this->_serviceMap) { - $this->_serviceMap = new SMD(); + $this->_serviceMap = new Smd(); } return $this->_serviceMap; } diff --git a/src/Server/Smd.php b/src/Server/Smd.php index 5be6626ed..9cb2c25c3 100644 --- a/src/Server/Smd.php +++ b/src/Server/Smd.php @@ -37,7 +37,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class SMD +class Smd { const ENV_JSONRPC_1 = 'JSON-RPC-1.0'; const ENV_JSONRPC_2 = 'JSON-RPC-2.0';