misuzu/src/Twitter/TwitterClientId.php

36 lines
916 B
PHP

<?php
namespace Misuzu\Twitter;
use Stringable;
use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
class TwitterClientId implements Stringable {
public function __construct(
private string $clientId,
private string $clientSecret
) {}
public function hasClientId(): bool {
return $this->clientId !== '' && $this->clientSecret !== '';
}
public function getClientId(): string {
return $this->clientId;
}
public function getClientSecret(): string {
return $this->clientSecret;
}
public function __toString(): string {
return 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
}
public static function load(IConfig $config): self {
return new static(
$config->getValue('clientId', CfgType::T_STR),
$config->getValue('clientSecret', CfgType::T_STR)
);
}
}