new custom exceptions added
This commit is contained in:
parent
f7faa6541d
commit
a2dc59b84a
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
namespace Clivern\Imap\Core;
|
namespace Clivern\Imap\Core;
|
||||||
|
|
||||||
use Clivern\Imap\Core\Exception\ConnectionError;
|
use Clivern\Imap\Core\Exception\AuthenticationFailedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection Class
|
* Connection Class
|
||||||
|
@ -85,14 +85,14 @@ class Connection
|
||||||
* Connect to IMAP Email
|
* Connect to IMAP Email
|
||||||
*
|
*
|
||||||
* @return Connection
|
* @return Connection
|
||||||
* @throws ConnectionError
|
* @throws AuthenticationFailedException
|
||||||
*/
|
*/
|
||||||
public function connect()
|
public function connect()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password);
|
$this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new ConnectionError("Error! Connecting to Imap Email.");
|
throw new AuthenticationFailedException("Error! Connecting to Imap Email.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -103,7 +103,7 @@ class Connection
|
||||||
try {
|
try {
|
||||||
imap_reopen($this->stream, "{" . $this->server . ":" . $this->port . $this->flag . "}" . $folder);
|
imap_reopen($this->stream, "{" . $this->server . ":" . $this->port . $this->flag . "}" . $folder);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new ConnectionError("Error! Connecting to Imap Email.");
|
throw new AuthenticationFailedException("Error! Connecting to Imap Email.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
src/Core/Exception/AuthenticationFailedException.php
Normal file
28
src/Core/Exception/AuthenticationFailedException.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author clivern <hello@clivern.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Clivern\Imap\Core\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection Error Class
|
||||||
|
*
|
||||||
|
* @package Clivern\Imap\Core\Exception
|
||||||
|
*/
|
||||||
|
class AuthenticationFailedException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct($error = null)
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
sprintf(
|
||||||
|
"Authentication failed with error: %s",
|
||||||
|
$server,
|
||||||
|
$port,
|
||||||
|
$email,
|
||||||
|
$error
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @author clivern <hello@clivern.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Clivern\Imap\Core\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connection Error Class
|
|
||||||
*
|
|
||||||
* @package Clivern\Imap\Core\Exception
|
|
||||||
*/
|
|
||||||
class ConnectionError extends \Exception{}
|
|
25
src/Core/Exception/MessageDeleteException.php
Normal file
25
src/Core/Exception/MessageDeleteException.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author clivern <hello@clivern.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Clivern\Imap\Core\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection Error Class
|
||||||
|
*
|
||||||
|
* @package Clivern\Imap\Core\Exception
|
||||||
|
*/
|
||||||
|
class MessageDeleteException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor
|
||||||
|
*
|
||||||
|
* @param integer $message_number
|
||||||
|
*/
|
||||||
|
public function __construct($message_number)
|
||||||
|
{
|
||||||
|
parent::__construct(sprintf('Message %s cannot be deleted', $message_number));
|
||||||
|
}
|
||||||
|
}
|
25
src/Core/Exception/MessageDoesNotExistException.php
Normal file
25
src/Core/Exception/MessageDoesNotExistException.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author clivern <hello@clivern.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Clivern\Imap\Core\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection Error Class
|
||||||
|
*
|
||||||
|
* @package Clivern\Imap\Core\Exception
|
||||||
|
*/
|
||||||
|
class MessageDoesNotExistException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Class Constructor
|
||||||
|
*
|
||||||
|
* @param integer $number
|
||||||
|
* @param string $error
|
||||||
|
*/
|
||||||
|
public function __construct($number, $error)
|
||||||
|
{
|
||||||
|
parent::__construct(sprintf('Message %s does not exist: %s', $number, $error));
|
||||||
|
}
|
||||||
|
}
|
26
src/Core/Exception/MessageMoveException.php
Normal file
26
src/Core/Exception/MessageMoveException.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author clivern <hello@clivern.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Clivern\Imap\Core\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection Error Class
|
||||||
|
*
|
||||||
|
* @package Clivern\Imap\Core\Exception
|
||||||
|
*/
|
||||||
|
class MessageMoveException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor
|
||||||
|
*
|
||||||
|
* @param integer $message_number
|
||||||
|
* @param string $mailbox
|
||||||
|
*/
|
||||||
|
public function __construct($message_number, $mailbox)
|
||||||
|
{
|
||||||
|
parent::__construct(sprintf('Message %s cannot be moved to %s', $message_number, $mailbox));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue