| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The Dropbox web API accesses three hosts; this structure holds the |
| 5 |
* names of those three hosts. This is primarily for mocking things out |
| 6 |
* during testing. Most of the time you won't have to deal with this class |
| 7 |
* directly, and even when you do, you'll just use the default |
| 8 |
* value: {@link Host::getDefault()}. |
| 9 |
* |
| 10 |
* @internal |
| 11 |
*/ |
| 12 |
final class Dropbox_Host |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Returns a Host object configured with the three standard Dropbox host: "api.dropbox.com", |
| 16 |
* "api-content.dropbox.com", and "www.dropbox.com" |
| 17 |
* |
| 18 |
* @return Dropbox_Host |
| 19 |
*/ |
| 20 |
public static function getDefault() |
| 21 |
{ |
| 22 |
if (!self::$defaultValue) { |
| 23 |
self::$defaultValue = new self("api.dropbox.com", "api-content.dropbox.com", "www.dropbox.com"); |
| 24 |
} |
| 25 |
|
| 26 |
return self::$defaultValue; |
| 27 |
} |
| 28 |
|
| 29 |
private static $defaultValue; |
| 30 |
|
| 31 |
/** @var string */ |
| 32 |
private $api; |
| 33 |
/** @var string */ |
| 34 |
private $content; |
| 35 |
/** @var string */ |
| 36 |
private $web; |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor. |
| 40 |
* |
| 41 |
* @param string $api |
| 42 |
* See {@link getApi()} |
| 43 |
* @param string $content |
| 44 |
* See {@link getContent()} |
| 45 |
* @param string $web |
| 46 |
* See {@link getWeb()} |
| 47 |
*/ |
| 48 |
public function __construct($api, $content, $web) |
| 49 |
{ |
| 50 |
$this->api = $api; |
| 51 |
$this->content = $content; |
| 52 |
$this->web = $web; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns the host name of the main Dropbox API server. |
| 57 |
* The default is "api.dropbox.com". |
| 58 |
* |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
public function getApi() |
| 62 |
{ |
| 63 |
return $this->api; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Returns the host name of the Dropbox API content server. |
| 68 |
* The default is "api-content.dropbox.com". |
| 69 |
* |
| 70 |
* @return string |
| 71 |
*/ |
| 72 |
public function getContent() |
| 73 |
{ |
| 74 |
return $this->content; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Returns the host name of the Dropbox web server. Used during user authorization. |
| 79 |
* The default is "www.dropbox.com". |
| 80 |
* |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
public function getWeb() |
| 84 |
{ |
| 85 |
return $this->web; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Check that a function argument is of type <code>Host</code>. |
| 90 |
* |
| 91 |
* @internal |
| 92 |
*/ |
| 93 |
public static function checkArg($argName, $argValue) |
| 94 |
{ |
| 95 |
if (!($argValue instanceof self)) { |
| 96 |
Dropbox_Checker::throwError($argName, $argValue, __CLASS__); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Check that a function argument is either <code>null</code> or of type |
| 102 |
* <code>Host</code>. |
| 103 |
* |
| 104 |
* @internal |
| 105 |
*/ |
| 106 |
public static function checkArgOrNull($argName, $argValue) |
| 107 |
{ |
| 108 |
if ($argValue === null) { |
| 109 |
return; |
| 110 |
} |
| 111 |
if (!($argValue instanceof self)) { |
| 112 |
Dropbox_Checker::throwError($argName, $argValue, __CLASS__); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|