forked from miroslav-valerian/google-distance-matrix
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exceptions, response mapping objects
- Loading branch information
1 parent
11a48a3
commit 7b10146
Showing
6 changed files
with
228 additions
and
17 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Valerian\GoogleDistanceMatrix\Response; | ||
|
||
|
||
class Address | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $address; | ||
|
||
/** | ||
* Address constructor. | ||
* @param $address string | ||
*/ | ||
public function __construct($address) | ||
{ | ||
$this->address = $address; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->address; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Valerian\GoogleDistanceMatrix\Response; | ||
|
||
|
||
class Distance | ||
{ | ||
|
||
private $text; | ||
|
||
private $value; | ||
|
||
/** | ||
* Distance constructor. | ||
* @param $text | ||
* @param $value | ||
*/ | ||
public function __construct($text, $value) | ||
{ | ||
$this->text = $text; | ||
$this->value = $value; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getText() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Valerian\GoogleDistanceMatrix\Response; | ||
|
||
|
||
class Duration | ||
{ | ||
|
||
private $text; | ||
|
||
private $value; | ||
|
||
/** | ||
* Distance constructor. | ||
* @param $text | ||
* @param $value | ||
*/ | ||
public function __construct($text, $value) | ||
{ | ||
$this->text = $text; | ||
$this->value = $value; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getText() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Valerian\GoogleDistanceMatrix\Response; | ||
|
||
use Valerian\GoogleDistanceMatrix\Exception\Exception; | ||
|
||
|
||
class Element | ||
{ | ||
const STATUS_OK = 'OK'; | ||
const STATUS_NOT_FOUND = 'NOT_FOUND' ; | ||
const STATUS_ZERO_RESULTS = 'ZERO_RESULTS'; | ||
|
||
const STATUS = [ | ||
self::STATUS_OK, | ||
self::STATUS_NOT_FOUND, | ||
self::STATUS_ZERO_RESULTS | ||
]; | ||
|
||
private $status; | ||
|
||
private $duration; | ||
|
||
private $distance; | ||
|
||
/** | ||
* Element constructor. | ||
* @param $status | ||
* @param Duration $duration | ||
* @param Distance $distance | ||
*/ | ||
public function __construct($status, Duration $duration, Distance $distance) | ||
{ | ||
if(!in_array($status,self::STATUS)) { | ||
throw new Exception('Unknown status code'); | ||
} | ||
|
||
|
||
$this->status = $status; | ||
$this->duration = $duration; | ||
$this->distance = $distance; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getStatus() | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* @return Duration | ||
*/ | ||
public function getDuration() | ||
{ | ||
return $this->duration; | ||
} | ||
|
||
/** | ||
* @return Distance | ||
*/ | ||
public function getDistance() | ||
{ | ||
return $this->distance; | ||
} | ||
} |