misuzu/src/Twitter/TwitterClientId.php

36 lines
889 B
PHP

<?php
namespace Misuzu\Twitter;
use Stringable;
use Misuzu\Config\IConfig;
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', IConfig::T_STR),
$config->getValue('clientSecret', IConfig::T_STR)
);
}
}