servermgrv2/app/Libraries/Adapter/API/Adapter.php
2023-07-20 13:56:55 +09:00

59 lines
1.7 KiB
PHP

<?php
namespace App\Libraries\Adapter\API;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
{
protected $_client = null;
protected $_serverInfo = array();
protected $_accountInfo = array();
protected $_debug = false;
protected function __construct($debug = false)
{
$this->_debug = $debug;
}
abstract protected function getClient();
abstract protected function requestURL(string $url, string $method, array $datas = []): object;
final public function setServerInfo(string $ip, int $port)
{
$this->_serverInfo['ip'] = $ip;
$this->_serverInfo['port'] = $port;
}
final protected function getServerInfo($scheme = "https://", $delimeter = ":"): string
{
return $scheme . $this->_serverInfo['ip'] . $delimeter . $this->_serverInfo['port'];
}
final public function setAccountInfo(string $id, int $password)
{
$this->_serverInfo['id'] = $id;
$this->_serverInfo['password'] = $password;
}
final protected function getAccountInfo($authType = 'basic'): array
{
//type: basic , digest
return array($this->_serverInfo['id'], $this->_serverInfo['password'], $authType);
}
protected function isSSLVerifiy(): bool
{
return getenv('api.ssl') == 'true' ? true : false;
}
protected function getCookieFile()
{
return PATHS['API'] . getenv('api.cookie.file') ?: "api-cookie_" . date("Ymd") . ".log";
}
protected function getDebugFile()
{
return PATHS['API'] . getenv('api.debug.file') ?: "api-debug_" . date("Ymd") . ".log";
}
final public function get(string $url): object
{
return $this->requestURL($url, 'GET');
}
final public function post(string $url, array $datas): object
{
return $this->requestURL($url, 'POST', $datas);
}
}