diff --git a/lib/Api.php b/lib/Api.php index d187a68..962c979 100644 --- a/lib/Api.php +++ b/lib/Api.php @@ -277,9 +277,15 @@ public function getPbxRedirection($pbxNumber) * @return Statistics * @throws ApiException */ - public function getStatistics($start = null, $end = null, $sip = null, $costOnly = null, $type = null, $skip = null, - $limit = null) - { + public function getStatistics( + $start = null, + $end = null, + $sip = null, + $costOnly = null, + $type = null, + $skip = null, + $limit = null + ) { $params = [ 'start' => $start, 'end' => $end, @@ -306,9 +312,14 @@ public function getStatistics($start = null, $end = null, $sip = null, $costOnly * @return PbxStatistics * @throws ApiException */ - public function getPbxStatistics($start = null, $end = null, $newFormat = true, $callType = null, - $skip = null, $limit = null) - { + public function getPbxStatistics( + $start = null, + $end = null, + $newFormat = true, + $callType = null, + $skip = null, + $limit = null + ) { $params = [ 'start' => $start, 'end' => $end, @@ -463,20 +474,20 @@ public function setPbxRecording($sipId, $status, $email = null, $speechRecogniti /** * Sending the SMS messages. * - * @param string number Phone number, where to send the SMS message (several numbers can be specified, - * separated by comma); - * @param string message Message (standard text limit applies; the text will be separated into several SMS messages, + * @param string|array $to Phone number(s), where to send the SMS message (array of numbers can be specified); + * @param string $message Message (standard text limit applies; the text will be separated into several SMS messages, * if the limit is exceeded); - * @param string caller_id Phone number, from which the SMS messages is sent (can be sent only from list of user's + * @param string $callerId Phone number, from which the SMS messages is sent (can be sent only from list of user's * confirmed phone numbers). * @return Sms * @throws ApiException */ public function sendSms($to, $message, $callerId = null) { + $to = array_map([self::class, 'filterNumber'], is_array($to) ? $to : [$to]); $params = [ - 'number' => self::filterNumber($to), - 'message' => $message + 'number' => implode(',', $to), + 'message' => $message, ]; if ($callerId) { $params['caller_id'] = $callerId; @@ -564,9 +575,12 @@ public function setPbxVoicemailRedirection($pbxNumber, $destination, $always, $g if (!filter_var($destination, FILTER_VALIDATE_EMAIL)) { throw new \BadFunctionCallException('Wrong email parameter'); } - if (!in_array($greeting, [self::PBX_REDIRECTION_NO_GREETING, self::PBX_REDIRECTION_OWN_GREETING, - self::PBX_REDIRECTION_STANDART_GREETING]) - ) { + $allowedRedirections = [ + self::PBX_REDIRECTION_NO_GREETING, + self::PBX_REDIRECTION_OWN_GREETING, + self::PBX_REDIRECTION_STANDART_GREETING + ]; + if (!in_array($greeting, $allowedRedirections)) { throw new \BadFunctionCallException('Wrong voicemailGreeting parameter'); } $params = [ @@ -577,9 +591,11 @@ public function setPbxVoicemailRedirection($pbxNumber, $destination, $always, $g 'voicemail_greeting' => $greeting, ]; if ($greeting == self::PBX_REDIRECTION_OWN_GREETING) { - if( !$greetingFile || !file_exists($greetingFile) || - !in_array(pathinfo($greetingFile, PATHINFO_EXTENSION), ['wav', 'mp3']) - ){ + if ( + !$greetingFile + || !file_exists($greetingFile) + || !in_array(pathinfo($greetingFile, PATHINFO_EXTENSION), ['wav', 'mp3']) + ) { throw new \BadFunctionCallException('Greeting file does not exist or has wrong extension.'); } $params['greeting_file'] = curl_file_create($greetingFile); @@ -806,4 +822,4 @@ protected static function arrayToResultObj($array, $resultClassName) } return $array; } -} \ No newline at end of file +} diff --git a/lib/Client.php b/lib/Client.php index 6e6a694..dcf9038 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -1,6 +1,7 @@ $this->url . $method, - CURLOPT_CUSTOMREQUEST => $type, + $options = [ + CURLOPT_URL => $this->url . $method, + CURLOPT_CUSTOMREQUEST => $type, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_HEADERFUNCTION => array($this, 'parseHeaders'), - CURLOPT_HTTPHEADER => $this->getAuthHeader($method, $params), - ); + CURLOPT_HEADERFUNCTION => [$this, 'parseHeaders'], + CURLOPT_HTTPHEADER => $this->getAuthHeader($method, $params), + ]; $ch = curl_init(); @@ -65,9 +66,9 @@ public function call($method, $params = array(), $requestType = 'get', $format = $options[CURLOPT_URL] = $this->url . $method . '?' . $this->httpBuildQuery($params); } else { $options[CURLOPT_POST] = true; - if(array_filter($params, 'is_object')){ + if (array_filter($params, 'is_object')) { $options[CURLOPT_POSTFIELDS] = $params; - }else{ + } else { $options[CURLOPT_POSTFIELDS] = $this->httpBuildQuery($params); } } @@ -121,12 +122,14 @@ public function encodeSignature($signatureString) */ private function getAuthHeader($method, $params) { - $params = array_filter($params, function($a){return !is_object($a);}); + $params = array_filter($params, function ($a) { + return !is_object($a); + }); ksort($params); $paramsString = $this->httpBuildQuery($params); $signature = $this->encodeSignature($method . $paramsString . md5($paramsString)); - return array('Authorization: ' . $this->key . ':' . $signature); + return ['Authorization: ' . $this->key . ':' . $signature]; } /** @@ -138,7 +141,7 @@ private function getAuthHeader($method, $params) private function parseHeaders($curl, $line) { if (preg_match('/^X-RateLimit-([a-z]+):\s([0-9]+)/i', $line, $match)) { - $this->limits[$match[1]] = (int) $match[2]; + $this->limits[$match[1]] = (int)$match[2]; } return strlen($line); @@ -151,8 +154,8 @@ private function parseHeaders($curl, $line) * * @return string */ - private function httpBuildQuery($params = array()) + private function httpBuildQuery($params = []) { - return http_build_query($params, null, '&', PHP_QUERY_RFC1738); + return http_build_query($params, '', '&', PHP_QUERY_RFC1738); } }