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

Commit

Permalink
CS cleanup of JSON-compliant support
Browse files Browse the repository at this point in the history
- CS cleanup -- imports, docblocks, etc.
- Ensured that AMF server also supports new Server interface features
  • Loading branch information
weierophinney committed Jan 16, 2012
1 parent 1674a18 commit 9b385ff
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 50 deletions.
48 changes: 25 additions & 23 deletions src/Server/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -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)
{
Expand All @@ -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()
{
Expand All @@ -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()
{
Expand All @@ -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()
{
Expand All @@ -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)
{
Expand All @@ -143,15 +144,16 @@ 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')) {
$headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client');
}

$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(
Expand All @@ -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())
{
Expand All @@ -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)
{
Expand Down
11 changes: 5 additions & 6 deletions src/Server/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
* @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
* @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 ErrorException
extends \BadMethodCallException
implements \Zend\Json\Server\Exception
extends BadMethodCallException
implements Exception
{}
7 changes: 1 addition & 6 deletions src/Server/Exception/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{}
26 changes: 12 additions & 14 deletions src/Server/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Zend\Json\Json;

/**
* @uses \Zend\Json\Json
* @category Zend
* @package Zend_Json
* @subpackage Server
Expand All @@ -38,7 +37,7 @@ class Response
{
/**
* Response error
* @var null|\Zend\Json\Server\Error
* @var null|Error
*/
protected $_error;

Expand All @@ -56,7 +55,7 @@ class Response

/**
* Service map
* @var \Zend\Json\Server\Smd\Smd
* @var Smd\Smd
*/
protected $_serviceMap;

Expand All @@ -70,7 +69,7 @@ class Response
* Set response state
*
* @param array $options
* @return \Zend\Json\Server\Response
* @return Response
*/
public function setOptions(array $options)
{
Expand Down Expand Up @@ -108,7 +107,7 @@ public function loadJson($json)
* Set result
*
* @param mixed $value
* @return \Zend\Json\Server\Response
* @return Response
*/
public function setResult($value)
{
Expand All @@ -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)
{
Expand All @@ -142,7 +141,7 @@ public function setError(Error $error)
/**
* Get response error
*
* @return null|\Zend\Json\Server\Error
* @return null|Error
*/
public function getError()
{
Expand All @@ -163,7 +162,7 @@ public function isError()
* Set request ID
*
* @param mixed $name
* @return \Zend\Json\Server\Response
* @return Response
*/
public function setId($name)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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()
{
Expand All @@ -289,4 +288,3 @@ public function __toString()
return $this->toJson();
}
}

2 changes: 1 addition & 1 deletion src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 9b385ff

Please sign in to comment.