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

Commit

Permalink
Merge branch 'milestones/exceptions/xmlrpc' into local/milestones/exc…
Browse files Browse the repository at this point in the history
…eptions
  • Loading branch information
Ralph Schindler committed Oct 18, 2010
3 parents 906c7b6 + 0da7bb6 + dfab537 commit 8154ba6
Show file tree
Hide file tree
Showing 31 changed files with 257 additions and 283 deletions.
8 changes: 5 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function doRequest($request, $response = null)
/**
* Exception thrown when an HTTP error occurs
*/
throw new Client\HttpException(
throw new Client\Exception\HttpException(
$httpResponse->getMessage(),
$httpResponse->getStatus()
);
Expand Down Expand Up @@ -335,8 +335,10 @@ public function call($method, $params=array())
/**
* Exception thrown when an XML-RPC fault is returned
*/
throw new Client\FaultException($fault->getMessage(),
$fault->getCode());
throw new Client\Exception\FaultException(
$fault->getMessage(),
$fault->getCode()
);
}

return $this->_lastResponse->getReturnValue();
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\XmlRpc\Exception
interface Exception extends \Zend\XmlRpc\Exception
{}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\XmlRpc\Client;
namespace Zend\XmlRpc\Client\Exception;

/**
* Thrown by Zend_XmlRpc_Client when an XML-RPC fault response is returned.
Expand All @@ -35,5 +35,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class FaultException extends Exception
class FaultException
extends \BadMethodCallException
implements \Zend\XmlRpc\Client\Exception
{}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\XmlRpc\Client;
namespace Zend\XmlRpc\Client\Exception;

/**
* Thrown by Zend_XmlRpc_Client when an HTTP error occurs during an
Expand All @@ -36,5 +36,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class HttpException extends Exception
class HttpException
extends RuntimeException
implements \Zend\XmlRpc\Client\Exception
{}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\XmlRpc\Client;
namespace Zend\XmlRpc\Client\Exception;

/**
* Thrown by Zend_XmlRpc_Client_Introspection when any error occurs.
Expand All @@ -35,5 +35,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class IntrospectException extends Exception
class IntrospectException
extends \InvalidArgumentException
implements \Zend\XmlRpc\Client\Exception
{}
9 changes: 9 additions & 0 deletions src/Client/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\XmlRpc\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\XmlRpc\Exception
{}

9 changes: 9 additions & 0 deletions src/Client/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\XmlRpc\Client\Exception;

class RuntimeException
extends \RuntimeException
implements \Zend\XmlRpc\Client\Exception
{}

6 changes: 3 additions & 3 deletions src/Client/ServerIntrospection.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public function getSignatureForEachMethodByMulticall($methods = null)
if (! is_array($serverSignatures)) {
$type = gettype($serverSignatures);
$error = "Multicall return is malformed. Expected array, got $type";
throw new IntrospectException($error);
throw new Exception\IntrospectException($error);
}

if (count($serverSignatures) != count($methods)) {
$error = 'Bad number of signatures received from multicall';
throw new IntrospectException($error);
throw new Exception\IntrospectException($error);
}

// Create a new signatures array with the methods name as keys and the signature as value
Expand Down Expand Up @@ -152,7 +152,7 @@ public function getMethodSignature($method)
$signature = $this->_system->methodSignature($method);
if (!is_array($signature)) {
$error = 'Invalid signature for method "' . $method . '"';
throw new IntrospectException($error);
throw new Exception\IntrospectException($error);
}
return $signature;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Exception
interface Exception
{}

9 changes: 9 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\XmlRpc\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\XmlRpc\Exception
{}

9 changes: 9 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Zend\XmlRpc\Exception;

class RuntimeException
extends \RuntimeException
implements \Zend\XmlRpc\Exception
{}

6 changes: 4 additions & 2 deletions src/Value/Exception.php → src/Exception/ValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\XmlRpc\Value;
namespace Zend\XmlRpc\Exception;

/**
* @uses \Zend\XmlRpc\Exception
Expand All @@ -33,6 +33,8 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\XmlRpc\Exception
class ValueException
extends \LogicException
implements \Zend\XmlRpc\Exception
{}

8 changes: 4 additions & 4 deletions src/Fault.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ public function getEncoding()
public function loadXml($fault)
{
if (!is_string($fault)) {
throw new Exception('Invalid XML provided to fault');
throw new Exception\InvalidArgumentException('Invalid XML provided to fault');
}

try {
$xml = new \SimpleXMLElement($fault);
} catch (\Exception $e) {
// Not valid XML
throw new Exception('Failed to parse XML fault: ' . $e->getMessage(), 500, $e);
throw new Exception\InvalidArgumentException('Failed to parse XML fault: ' . $e->getMessage(), 500, $e);
}

// Check for fault
Expand All @@ -215,7 +215,7 @@ public function loadXml($fault)

if (!$xml->fault->value->struct) {
// not a proper fault
throw new Exception('Invalid fault structure', 500);
throw new Exception\InvalidArgumentException('Invalid fault structure', 500);
}

$structXml = $xml->fault->value->asXML();
Expand All @@ -230,7 +230,7 @@ public function loadXml($fault)
}

if (empty($code) && empty($message)) {
throw new Exception('Fault code and string required');
throw new Exception\InvalidArgumentException('Fault code and string required');
}

if (empty($code)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function loadXml($response)

try {
if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) {
throw new Value\Exception('Missing XML-RPC value in XML');
throw new Exception\ValueException('Missing XML-RPC value in XML');
}
$valueXml = $xml->params->param->value->asXML();
$value = Value::getXmlRpcValue($valueXml, Value::XML_STRING);
Expand Down
26 changes: 13 additions & 13 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function __call($method, $params)
{
$system = $this->getSystem();
if (!method_exists($system, $method)) {
throw new Server\Exception('Unknown instance method called on server: ' . $method);
throw new Server\Exception\BadMethodCallException('Unknown instance method called on server: ' . $method);
}
return call_user_func_array(array($system, $method), $params);
}
Expand All @@ -197,7 +197,7 @@ public function __call($method, $params)
public function addFunction($function, $namespace = '')
{
if (!is_string($function) && !is_array($function)) {
throw new Server\Exception('Unable to attach function; invalid', 611);
throw new Server\Exception\InvalidArgumentException('Unable to attach function; invalid', 611);
}

$argv = null;
Expand All @@ -209,9 +209,9 @@ public function addFunction($function, $namespace = '')
$function = (array) $function;
foreach ($function as $func) {
if (!is_string($func) || !function_exists($func)) {
throw new Server\Exception('Unable to attach function; invalid', 611);
throw new Server\Exception\InvalidArgumentException('Unable to attach function; invalid', 611);
}
$reflection = Reflection::reflectFunction($func, $argv, $namespace);
$reflection = Reflection\Reflection::reflectFunction($func, $argv, $namespace);
$this->_buildSignature($reflection);
}
}
Expand All @@ -236,7 +236,7 @@ public function addFunction($function, $namespace = '')
public function setClass($class, $namespace = '', $argv = null)
{
if (is_string($class) && !class_exists($class)) {
throw new Server\Exception('Invalid method class', 610);
throw new Server\Exception\InvalidArgumentException('Invalid method class', 610);
}

$argv = null;
Expand All @@ -245,7 +245,7 @@ public function setClass($class, $namespace = '', $argv = null)
$argv = array_slice($argv, 2);
}

$dispatchable = Reflection::reflectClass($class, $argv, $namespace);
$dispatchable = Reflection\Reflection::reflectClass($class, $argv, $namespace);
foreach ($dispatchable->getMethods() as $reflection) {
$this->_buildSignature($reflection, $class);
}
Expand All @@ -265,7 +265,7 @@ public function fault($fault = null, $code = 404)
if (empty($fault)) {
$fault = 'Unknown Error';
}
$fault = new Server\Exception($fault, $code);
$fault = new Server\Exception\RuntimeException($fault, $code);
}

return Server\Fault::getInstance($fault);
Expand Down Expand Up @@ -323,7 +323,7 @@ public function loadFunctions($definition)
} else {
$type = gettype($definition);
}
throw new Server\Exception('Unable to load server definition; must be an array or Zend_Server_Definition, received ' . $type, 612);
throw new Server\Exception\InvalidArgumentException('Unable to load server definition; must be an array or Zend_Server_Definition, received ' . $type, 612);
}

$this->_table->clearMethods();
Expand Down Expand Up @@ -386,11 +386,11 @@ public function setRequest($request)
if (is_string($request) && class_exists($request)) {
$request = new $request();
if (!$request instanceof Request) {
throw new Server\Exception('Invalid request class');
throw new Server\Exception\InvalidArgumentException('Invalid request class');
}
$request->setEncoding($this->getEncoding());
} elseif (!$request instanceof Request) {
throw new Server\Exception('Invalid request object');
throw new Server\Exception\InvalidArgumentException('Invalid request object');
}

$this->_request = $request;
Expand Down Expand Up @@ -418,7 +418,7 @@ public function setResponseClass($class)
if (!class_exists($class) or
($c = new \ReflectionClass($class) and !$c->isSubclassOf('Zend\\XmlRpc\\Response'))) {

throw new Server\Exception('Invalid response class');
throw new Server\Exception\InvalidArgumentException('Invalid response class');
}
$this->_responseClass = $class;
return true;
Expand Down Expand Up @@ -514,7 +514,7 @@ protected function _handle(Request $request)

// Check for valid method
if (!$this->_table->hasMethod($method)) {
throw new Server\Exception('Method "' . $method . '" does not exist', 620);
throw new Server\Exception\RuntimeException('Method "' . $method . '" does not exist', 620);
}

$info = $this->_table->getMethod($method);
Expand Down Expand Up @@ -546,7 +546,7 @@ protected function _handle(Request $request)
}
}
if (!$matched) {
throw new Server\Exception('Calling parameters do not match signature', 623);
throw new Server\Exception\RuntimeException('Calling parameters do not match signature', 623);
}

$return = $this->_dispatch($info, $params);
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\XmlRpc\Exception
interface Exception extends \Zend\XmlRpc\Exception
{
}

8 changes: 8 additions & 0 deletions src/Server/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\XmlRpc\Server\Exception;

class BadMethodCallException
extends \BadMethodCallException
implements \Zend\XmlRpc\Server\Exception
{}
8 changes: 8 additions & 0 deletions src/Server/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\XmlRpc\Server\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\XmlRpc\Server\Exception
{}
8 changes: 8 additions & 0 deletions src/Server/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\XmlRpc\Server\Exception;

class RuntimeException
extends \RuntimeException
implements \Zend\XmlRpc\Server\Exception
{}
4 changes: 2 additions & 2 deletions src/Server/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function methodHelp($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
throw new Exception('Method "' . $method . '" does not exist', 640);
throw new Exception\InvalidArgumentException('Method "' . $method . '" does not exist', 640);
}

return $table->getMethod($method)->getMethodHelp();
Expand All @@ -93,7 +93,7 @@ public function methodSignature($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
throw new Exception('Method "' . $method . '" does not exist', 640);
throw new Exception\InvalidArgumentException('Method "' . $method . '" does not exist', 640);
}
$method = $table->getMethod($method)->toArray();
return $method['prototypes'];
Expand Down
Loading

0 comments on commit 8154ba6

Please sign in to comment.