1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
namespace Catapult;
final class EndpointsToken{
public function __construct() {
$data = Ensure::Input(func_get_args());
return $this->setup($data->get());
}
public function setup($data) {
if (is_object($data[0])) {
$data = Converter::toArray($data[0]);
}
foreach ($data as $k => $d) {
if (!in_array($k,array("token","expires"))) {
throw new CatapultApiException("$k is not a valid key for endpoint token");
}
}
$arr = array('token', 'expires');
foreach ($arr as $a) {
if (isset($data[$a])) {
$this->$a = $data[$a];
}
}
$this->serialize = FALSE;
}
public function __toString() {
return json_encode(array(
"token" => $this->token,
"expires" => $this->expires
));
}
}