From 5e0a4f51473b5a543b346b0398a77707eb269432 Mon Sep 17 00:00:00 2001 From: Brian Cash Date: Sun, 11 Feb 2024 03:30:34 -0800 Subject: [PATCH] fixed complaints in php8 (manual testing in 8.2.15) --- opensrs/Base.php | 61 +++++++++++++------- opensrs/domains/lookup/AllInOneDomain.php | 2 +- opensrs/domains/lookup/GetOrdersByDomain.php | 2 +- opensrs/domains/lookup/NameSuggest.php | 2 +- opensrs/domains/lookup/PremiumDomain.php | 2 +- opensrs/domains/provisioning/SWRegister.php | 2 +- 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/opensrs/Base.php b/opensrs/Base.php index 4d3a2168..3fa3d4ff 100644 --- a/opensrs/Base.php +++ b/opensrs/Base.php @@ -2,6 +2,8 @@ namespace opensrs; +use stdClass; + defined('OPENSRSURI') or die; /** @@ -19,6 +21,21 @@ class Base private $_socketTimeout = 120; // seconds private $_socketReadTimeout = 120; // seconds + private $osrs_debug = false; + + private stdClass $dataObject; + + public $action; + public $object; + + public $_formatHolder; + public $resultFullRaw; + public $resultRaw; + public $resultFullFormatted; + public $resultFormatted; + + protected $dataFormat; + protected $_opsHandler; public $defaultTlds = array('.com', '.net', '.org'); @@ -66,7 +83,7 @@ public function __destruct() private function _verifySystemProperties() { if (!function_exists('version_compare') || version_compare('4.3', phpversion(), '>=')) { - $error_message = 'PHP version must be v4.3+ (current version is '.phpversion().') to use "SSL" encryption'; + $error_message = 'PHP version must be v4.3+ (current version is ' . phpversion() . ') to use "SSL" encryption'; throw new Exception($error_message); } elseif (!function_exists('openssl_open')) { $error_message = 'PHP must be compiled using --with-openssl to use "SSL" encryption'; @@ -87,7 +104,7 @@ public function send_cmd($request) { // make or get the socket filehandle if (!$this->init_socket()) { - throw new Exception('oSRS Error - Unable to establish socket: ('.$this->_socketErrorNum.') '.$this->_socketErrorMsg); + throw new Exception('oSRS Error - Unable to establish socket: (' . $this->_socketErrorNum . ') ' . $this->_socketErrorMsg); } $this->send_data($request); @@ -114,7 +131,7 @@ private function init_socket() if ($this->is_connected()) { return true; } - $this->_socket = fsockopen(CRYPT_TYPE.'://'.OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout); + $this->_socket = fsockopen(CRYPT_TYPE . '://' . OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout); if (!$this->_socket) { return false; } else { @@ -162,8 +179,8 @@ private function read_data() } else { $data = $buf; } - if (!empty($this->osrs_debug)) { - print_r('
'.htmlentities($data).'
'); + if ($this->osrs_debug) { + print_r('
' . htmlentities($data) . '
'); } return $data; @@ -180,8 +197,8 @@ private function read_data() */ private function send_data($message) { - if (!empty($this->osrs_debug)) { - print_r('
'.htmlentities($message).'
'); + if ($this->osrs_debug) { + print_r('
' . htmlentities($message) . '
'); } return $this->writeData($this->_socket, $message); @@ -198,12 +215,12 @@ private function writeData(&$fh, $msg) $header = ''; $len = strlen($msg); - $signature = md5(md5($msg.OSRS_KEY).OSRS_KEY); - $header .= 'POST / HTTP/1.0'.CRLF; - $header .= 'Content-Type: text/xml'.CRLF; - $header .= 'X-Username: '.OSRS_USERNAME.CRLF; - $header .= 'X-Signature: '.$signature.CRLF; - $header .= 'Content-Length: '.$len.CRLF.CRLF; + $signature = md5(md5($msg . OSRS_KEY) . OSRS_KEY); + $header .= 'POST / HTTP/1.0' . CRLF; + $header .= 'Content-Type: text/xml' . CRLF; + $header .= 'X-Username: ' . OSRS_USERNAME . CRLF; + $header .= 'X-Signature: ' . $signature . CRLF; + $header .= 'Content-Length: ' . $len . CRLF . CRLF; fputs($fh, $header); fputs($fh, $msg, $len); @@ -264,11 +281,11 @@ private function readData(&$fh, $timeout = 5) /* PHP doesn't have timeout for fread ... we just set the timeout for the socket */ socket_set_timeout($fh, $timeout); $header = $this->readHeader($fh, $timeout); - if (!$header || !isset($header{'content-length'}) || (empty($header{'content-length'}))) { + if (!$header || !isset($header['content-length']) || (empty($header['content-length']))) { throw new Exception('oSRS Error - UNEXPECTED ERROR: No Content-Length header provided! Please make sure IP is whitelisted in RWI.'); } - $len = (int) $header{'content-length'}; + $len = (int) $header['content-length']; $line = ''; while (strlen($line) < $len) { $line .= fread($fh, $len); @@ -295,7 +312,7 @@ public function convertArray2Formatted($type = '', $data = '') $resultString = json_encode($data); } if ($type == 'yaml') { - $resultString = Spyc::YAMLDump($data); + $resultString = \Spyc::YAMLDump($data); } return $resultString; @@ -337,7 +354,7 @@ public function getConfiguredTlds() return $this->defaultTlds; } - public function setDataObject($format, $dataObject) + public function setDataObject($format, stdClass $dataObject) { $this->dataObject = $dataObject; $this->dataFormat = $format; @@ -417,9 +434,7 @@ public function send($dataObject, $returnFullResponse = true) ); } - if (method_exists($this, 'customResponseHandling')) { - $arrayResult = $this->customResponseHandling($arrayResult, $returnFullResponse); - } + $arrayResult = $this->customResponseHandling($arrayResult, $returnFullResponse); // Results $this->resultFullRaw = $arrayResult; @@ -440,6 +455,12 @@ public function send($dataObject, $returnFullResponse = true) $this->resultFormatted = $this->convertArray2Formatted($this->_formatHolder, $this->resultRaw); } + // method which may be implemented by child classes + protected function customResponseHandling(array $arrayResult, bool $returnFullResponse = true): array + { + return $arrayResult; + } + /** * Method for any shared validation that is applicable to all * API calls. Checks API call class for requiredFields array diff --git a/opensrs/domains/lookup/AllInOneDomain.php b/opensrs/domains/lookup/AllInOneDomain.php index a40ca8e4..d6569837 100644 --- a/opensrs/domains/lookup/AllInOneDomain.php +++ b/opensrs/domains/lookup/AllInOneDomain.php @@ -37,7 +37,7 @@ public function __destruct() parent::__destruct(); } - public function customResponseHandling($arrayResult, $returnFullResponse = true) + public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array { if ($returnFullResponse) { if (isset($arrayResult['attributes']['premium']['items'])) { diff --git a/opensrs/domains/lookup/GetOrdersByDomain.php b/opensrs/domains/lookup/GetOrdersByDomain.php index a2548d86..be55af99 100644 --- a/opensrs/domains/lookup/GetOrdersByDomain.php +++ b/opensrs/domains/lookup/GetOrdersByDomain.php @@ -37,7 +37,7 @@ public function __destruct() parent::__destruct(); } - public function customResponseHandling($arrayResult, $returnFullResponse = true) + public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array { if (!$returnFullResponse) { if (isset($arrayResult['attributes']['lookup']['items'])) { diff --git a/opensrs/domains/lookup/NameSuggest.php b/opensrs/domains/lookup/NameSuggest.php index a17f01da..1c6ce66b 100644 --- a/opensrs/domains/lookup/NameSuggest.php +++ b/opensrs/domains/lookup/NameSuggest.php @@ -37,7 +37,7 @@ public function __destruct() parent::__destruct(); } - public function customResponseHandling($arrayResult, $returnFullResponse = true) + public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array { if (!$returnFullResponse) { if (isset($arrayResult['attributes'])) { diff --git a/opensrs/domains/lookup/PremiumDomain.php b/opensrs/domains/lookup/PremiumDomain.php index 2506a231..a2409cd2 100644 --- a/opensrs/domains/lookup/PremiumDomain.php +++ b/opensrs/domains/lookup/PremiumDomain.php @@ -37,7 +37,7 @@ public function __destruct() parent::__destruct(); } - public function customResponseHandling($arrayResult, $returnFullResponse = true) + public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array { if (!$returnFullResponse) { if (isset($arrayResult['attributes'])) { diff --git a/opensrs/domains/provisioning/SWRegister.php b/opensrs/domains/provisioning/SWRegister.php index c3d891f2..36b336e9 100644 --- a/opensrs/domains/provisioning/SWRegister.php +++ b/opensrs/domains/provisioning/SWRegister.php @@ -43,7 +43,7 @@ public function __destruct() parent::__destruct(); } - public function customResponseHandling($arrayResult, $returnFullResponse = true) + public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array { /* Added by BC : NG : 16-7-2014 : To set error message for Insufficient Funds */ if (isset($arrayResult['attributes']['forced_pending']) and $arrayResult['attributes']['forced_pending'] != '' and $arrayResult['is_success'] == 1) {