new custom exceptions added

This commit is contained in:
Clivern 2017-08-11 23:19:19 +02:00
parent f7faa6541d
commit a2dc59b84a
6 changed files with 108 additions and 17 deletions

View file

@ -5,7 +5,7 @@
namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Exception\ConnectionError;
use Clivern\Imap\Core\Exception\AuthenticationFailedException;
/**
* Connection Class
@ -85,14 +85,14 @@ class Connection
* Connect to IMAP Email
*
* @return Connection
* @throws ConnectionError
* @throws AuthenticationFailedException
*/
public function connect()
{
try {
$this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password);
} catch (\Exception $e) {
throw new ConnectionError("Error! Connecting to Imap Email.");
throw new AuthenticationFailedException("Error! Connecting to Imap Email.");
}
return $this;
@ -103,7 +103,7 @@ class Connection
try {
imap_reopen($this->stream, "{" . $this->server . ":" . $this->port . $this->flag . "}" . $folder);
} catch (\Exception $e) {
throw new ConnectionError("Error! Connecting to Imap Email.");
throw new AuthenticationFailedException("Error! Connecting to Imap Email.");
}
}

View 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
)
);
}
}

View file

@ -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{}

View 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));
}
}

View 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));
}
}

View 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));
}
}