Skip to content

Commit

Permalink
Throw an exception on autodiscovery failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes committed Feb 6, 2017
1 parent f0c41e8 commit 5d228f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Changed
- Autodiscovery failure now throws a RuntimeException.

## 1.0.0-beta.3 - 2017-01-21

### Added
Expand Down
5 changes: 0 additions & 5 deletions examples/autodiscover/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@

// Simplest usage, no special options.
$client = Autodiscover::getEWS($email, $password);

// If autodiscovery failed, throw an exception.
if (!$client) {
throw new Exception('Autodiscovery failed.');
}
5 changes: 0 additions & 5 deletions examples/autodiscover/certificate-authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@
$discovery = new Autodiscover($email, $password);
$discovery->setCAInfo($ca_path);
$client = $discovery->newEWS();

// If autodiscovery failed, throw an exception.
if (!$client) {
throw new Exception('Autodiscovery failed.');
}
21 changes: 8 additions & 13 deletions src/Autodiscover.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ public function __construct($email, $password, $username = null)
* Execute the full discovery chain of events in the correct sequence
* until a valid response is received, or all methods have failed.
*
* @return integer|boolean
* One of the AUTODISCOVERED_VIA_* constants or false on failure.
* @return integer
* One of the AUTODISCOVERED_VIA_* constants.
*
* @todo Throw an exception on failure.
* @throws \RuntimeException
* When all autodiscovery methods fail.
*/
public function discover()
{
Expand All @@ -259,6 +260,10 @@ public function discover()
$result = $this->trySRVRecord();
}

if ($result === false) {
throw new \RuntimeException('Autodiscovery failed.');
}

return $result;
}

Expand Down Expand Up @@ -304,8 +309,6 @@ public function skipSSLVerification($skip = true)
*
* @param string $version_hex
* Hexadecimal version string.
*
* @todo Update to include Exchange 2013 versions.
*/
public function parseServerVersion($version_hex)
{
Expand Down Expand Up @@ -413,8 +416,6 @@ public static function getEWS($email, $password, $username = null)
*
* @return integer|boolean
* One of the AUTODISCOVERED_VIA_* constants or false on failure.
*
* @todo Throw an exception on failure.
*/
public function tryTLD()
{
Expand All @@ -428,8 +429,6 @@ public function tryTLD()
*
* @return integer|boolean
* One of the AUTODISCOVERED_VIA_* constants or false on failure.
*
* @todo Throw an exception on failure.
*/
public function trySubdomain()
{
Expand All @@ -445,8 +444,6 @@ public function trySubdomain()
*
* @return integer|boolean
* One of the AUTODISCOVERED_VIA_* constants or false on failure.
*
* @todo Throw an exception on failure.
*/
public function trySubdomainUnauthenticatedGet()
{
Expand Down Expand Up @@ -490,8 +487,6 @@ public function trySubdomainUnauthenticatedGet()
*
* @return integer|boolean
* The value of self::AUTODISCOVERED_VIA_SRV_RECORD or false.
*
* @todo Throw an exception on failure.
*/
public function trySRVRecord()
{
Expand Down

0 comments on commit 5d228f1

Please sign in to comment.