connection error exception class added

This commit is contained in:
Clivern 2017-08-10 11:45:56 +02:00
parent 26f6ff8840
commit 948d61cc3f
4 changed files with 28 additions and 3 deletions

View file

@ -5,6 +5,8 @@
namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Exception\ConnectionError;
/**
* Connection Class
*
@ -72,10 +74,15 @@ class Connection
* Connect to IMAP Email
*
* @return Connection
* @throws ConnectionError
*/
public function connect()
{
$this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password);
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.");
}
return $this;
}

View file

@ -0,0 +1,13 @@
<?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

@ -4,6 +4,7 @@
*/
namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Connection;
/**
@ -22,12 +23,16 @@ class Stats
public function getQuota($folder = 'INBOX')
{
return imap_get_quotaroot($this->connection->getStream(), $folder);
$data = imap_get_quotaroot($this->connection->getStream(), $folder);
return $data;
}
public function getStatus($folder = 'INBOX', $flag = SA_ALL)
{
return imap_status($this->connection->getStream(), "{" . $this->connection->getServer() . "}" . $folder, $flag);
$data = imap_status($this->connection->getStream(), "{" . $this->connection->getServer() . "}" . $folder, $flag);
return $data;
}
}