22declare(strict_types=1);
24namespace pocketmine\updater;
29use
function is_string;
30use
function json_decode;
33 private const TLS_KEY_UPDATER =
"updater";
35 private string $error =
"Unknown error";
37 public function __construct(
39 private string $endpoint,
40 private string $channel
42 $this->
storeLocal(self::TLS_KEY_UPDATER, $updater);
47 $response =
Internet::getURL($this->endpoint .
"?channel=" . $this->channel, 4, [], $error);
48 $this->error = $error;
50 if($response !==
null){
51 $response = json_decode($response->getBody(),
true);
52 if(is_array($response)){
53 if(isset($response[
"error"]) && is_string($response[
"error"])){
54 $this->error = $response[
"error"];
56 $mapper = new \JsonMapper();
57 $mapper->bExceptionOnMissingData =
true;
58 $mapper->bStrictObjectTypeChecking =
true;
59 $mapper->bEnforceMapType =
false;
62 $responseObj = $mapper->map($response,
new UpdateInfo());
63 $this->setResult($responseObj);
65 $this->error =
"Invalid JSON response data: " . $e->getMessage();
69 $this->error =
"Invalid response data";
76 $updater = $this->fetchLocal(self::TLS_KEY_UPDATER);
77 if($this->hasResult()){
79 $response = $this->getResult();
82 $updater->checkUpdateError($this->error);
storeLocal(string $key, mixed $complexData)
checkUpdateCallback(UpdateInfo $updateInfo)
static getURL(string $page, int $timeout=10, array $extraHeaders=[], &$err=null)