Skip to content

Commit

Permalink
add StanzaException class
Browse files Browse the repository at this point in the history
  • Loading branch information
kadet1090 committed Aug 21, 2016
1 parent 91853ba commit fcd09b7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Exception/Protocol/BindingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
51 changes: 51 additions & 0 deletions Exception/Protocol/StanzaException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Nucleus - XMPP Library for PHP
*
* Copyright (C) 2016, Some rights reserved.
*
* @author Kacper "Kadet" Donat <[email protected]>
*
* Contact with author:
* Xmpp: [email protected]
* E-mail: [email protected]
*
* 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;
}
}

0 comments on commit fcd09b7

Please sign in to comment.