From fcd09b773b178181501cdeb857420c70937799fa Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sun, 21 Aug 2016 23:06:27 +0200 Subject: [PATCH] add StanzaException class --- Exception/Protocol/BindingException.php | 5 +-- Exception/Protocol/StanzaException.php | 51 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Exception/Protocol/StanzaException.php diff --git a/Exception/Protocol/BindingException.php b/Exception/Protocol/BindingException.php index dd92bec..4e10c4a 100644 --- a/Exception/Protocol/BindingException.php +++ b/Exception/Protocol/BindingException.php @@ -17,11 +17,10 @@ use Exception; -use Kadet\Xmpp\Exception\ProtocolException; use Kadet\Xmpp\Jid; use Kadet\Xmpp\Stanza\Error; -class BindingException extends ProtocolException +class BindingException extends StanzaException { /** * Construct the exception. Note: The message is NOT binary safe. @@ -34,7 +33,7 @@ class BindingException extends ProtocolException */ public static function fromError(Jid $jid, Error $error, Exception $previous = null) { - return new static(\Kadet\Xmpp\Utils\helper\format("Cannot bind {resource} for {bare}. {condition}", [ + return new static($error, \Kadet\Xmpp\Utils\helper\format("Cannot bind {resource} for {bare}. {condition}", [ 'resource' => $jid->resource ?: "no resource", 'bare' => (string)$jid->bare(), 'condition' => static::_conditionDescription($error) diff --git a/Exception/Protocol/StanzaException.php b/Exception/Protocol/StanzaException.php new file mode 100644 index 0000000..0b80ece --- /dev/null +++ b/Exception/Protocol/StanzaException.php @@ -0,0 +1,51 @@ + + * + * Contact with author: + * Xmpp: me@kadet.net + * E-mail: contact@kadet.net + * + * From Kadet with love. + */ + +namespace Kadet\Xmpp\Exception\Protocol; + + +use Exception; +use Kadet\Xmpp\Exception\PropertyAccessException; +use Kadet\Xmpp\Stanza\Error; + +class StanzaException extends PropertyAccessException +{ + /** @var Error */ + private $_error; + + /** + * Construct the exception. Note: The message is NOT binary safe. + * @link http://php.net/manual/en/exception.construct.php + * @param Error $error Stanza error describing exception + * @param string $message [optional] The Exception message to throw. + * @param int $code [optional] The Exception code. + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 + * @since 5.1.0 + */ + public function __construct(Error $error, $message = '', $code = 0, Exception $previous = null) + { + parent::__construct($message, $code, $previous); + $this->_error = $error; + } + + + /** + * @return Error + */ + public function getError() : Error + { + return $this->_error; + } +}