diff --git a/src/Core/Connection.php b/src/Core/Connection.php index 7e3f390..6b04154 100644 --- a/src/Core/Connection.php +++ b/src/Core/Connection.php @@ -12,42 +12,103 @@ namespace Clivern\Imap\Core; */ class Connection { + /** + * @var string + */ protected $server; + + /** + * @var integer + */ protected $port; + + /** + * @var string + */ protected $email; + + /** + * @var string + */ protected $password; + + /** + * @var string + */ protected $flag; + + /** + * @var string + */ protected $folder; + + /** + * @var mixed + */ protected $stream; - public function __construct($server, $port, $email, $password, $flag = "/novalidate-cert", $folder = "INBOX") + /** + * Class Constructor + * + * @param string $server + * @param string $port + * @param string $email + * @param string $password + * @param string $flag + * @param string $folder + * @return void + */ + public function __construct($server, $port, $email, $password, $flag = "/ssl", $folder = "INBOX") { $this->server = $server; $this->port = $port; $this->email = $email; $this->password = $password; + $this->flag = $flag; + $this->folder = $folder; } + /** + * Connect to IMAP Email + * + * @return Connection + */ public function connect() { - $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); return $this; } + /** + * Get Stream + * + * @return mixed + */ public function getStream() { return $this->stream; } + /** + * Check Connection + * + * @return boolean + */ public function checkConnection() { return (!is_null($this->stream) && imap_ping($this->stream)); } + /** + * Disconnect + * + * @param integer $flag + * @return boolean + */ public function disconnect($flag = 0) { - if( !is_null($this->stream) && !imap_ping($this->stream) ){ + if( !is_null($this->stream) && imap_ping($this->stream) ){ if( imap_close($this->stream, $flag) ){ $this->stream = null; return true; @@ -56,6 +117,7 @@ class Connection } } + var_dump("dd"); return false; } } \ No newline at end of file diff --git a/tests/Core/ConnectionTest.php b/tests/Core/ConnectionTest.php new file mode 100644 index 0000000..afabd07 --- /dev/null +++ b/tests/Core/ConnectionTest.php @@ -0,0 +1,16 @@ +assertTrue($connection->connect()->checkConnection()); + $this->assertTrue($connection->connect()->disconnect()); + } +} \ No newline at end of file