@@ -267,7 +267,7 @@ |
||
| 267 | 267 | |
| 268 | 268 | $name = \ucfirst(\str_replace(['-', '_', ''], '', $name)); |
| 269 | 269 | |
| 270 | - return __NAMESPACE__."\\Gateways\\{$name}Gateway"; |
|
| 270 | + return __NAMESPACE__."\\Gateways\\{$name}gateway"; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @throws NoGatewayAvailableException |
| 54 | 54 | * @throws InvalidArgumentException |
| 55 | 55 | */ |
| 56 | - public function send(array|string $to, MessageInterface|array $message, array $gateways = []): array |
|
| 56 | + public function send(array | string $to, MessageInterface | array $message, array $gateways = []): array |
|
| 57 | 57 | { |
| 58 | 58 | $to = $this->formatPhoneNumber($to); |
| 59 | 59 | $message = $this->formatMessage($message); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function gateway(?string $name): GatewayInterface |
| 75 | 75 | { |
| 76 | - if (! isset($this->gateways[$name])) { |
|
| 76 | + if (!isset($this->gateways[$name])) { |
|
| 77 | 77 | $this->gateways[$name] = $this->createGateway($name); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -91,15 +91,15 @@ discard block |
||
| 91 | 91 | $strategy = $this->config->get('default.strategy', OrderStrategy::class); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if (! \class_exists($strategy)) { |
|
| 94 | + if (!\class_exists($strategy)) { |
|
| 95 | 95 | $strategy = __NAMESPACE__.'\Strategies\\'.\ucfirst($strategy); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if (! \class_exists($strategy)) { |
|
| 98 | + if (!\class_exists($strategy)) { |
|
| 99 | 99 | throw new InvalidArgumentException("Unsupported strategy \"{$strategy}\""); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if (empty($this->strategies[$strategy]) || ! ($this->strategies[$strategy] instanceof StrategyInterface)) { |
|
| 102 | + if (empty($this->strategies[$strategy]) || !($this->strategies[$strategy] instanceof StrategyInterface)) { |
|
| 103 | 103 | $this->strategies[$strategy] = new $strategy($this); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | $config = $this->config->get("gateways.{$name}", []); |
| 140 | 140 | |
| 141 | - if (! isset($config['timeout'])) { |
|
| 141 | + if (!isset($config['timeout'])) { |
|
| 142 | 142 | $config['timeout'] = $this->config->get('timeout', Gateway::DEFAULT_TIMEOUT); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $gateway = $this->makeGateway($className, $config); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if (! ($gateway instanceof GatewayInterface)) { |
|
| 154 | + if (!($gateway instanceof GatewayInterface)) { |
|
| 155 | 155 | throw new InvalidArgumentException(\sprintf('Gateway "%s" must implement interface %s.', $name, GatewayInterface::class)); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | protected function makeGateway(string $gateway, array $config): GatewayInterface |
| 167 | 167 | { |
| 168 | - if (! \class_exists($gateway) || ! \in_array(GatewayInterface::class, \class_implements($gateway))) { |
|
| 168 | + if (!\class_exists($gateway) || !\in_array(GatewayInterface::class, \class_implements($gateway))) { |
|
| 169 | 169 | throw new InvalidArgumentException(\sprintf('Class "%s" is a invalid easy-sms gateway.', $gateway)); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | return \call_user_func($this->customCreators[$gateway], $config); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - protected function formatPhoneNumber(PhoneNumberInterface|string $number): PhoneNumberInterface |
|
| 197 | + protected function formatPhoneNumber(PhoneNumberInterface | string $number): PhoneNumberInterface |
|
| 198 | 198 | { |
| 199 | 199 | if ($number instanceof PhoneNumberInterface) { |
| 200 | 200 | return $number; |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | return new PhoneNumber(\trim($number)); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - protected function formatMessage(MessageInterface|array|string $message): MessageInterface |
|
| 206 | + protected function formatMessage(MessageInterface | array | string $message): MessageInterface |
|
| 207 | 207 | { |
| 208 | - if (! ($message instanceof MessageInterface)) { |
|
| 209 | - if (! \is_array($message)) { |
|
| 208 | + if (!($message instanceof MessageInterface)) { |
|
| 209 | + if (!\is_array($message)) { |
|
| 210 | 210 | $message = [ |
| 211 | 211 | 'content' => $message, |
| 212 | 212 | 'template' => $message, |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $formatted[$gateway] = $setting; |
| 236 | 236 | $globalSettings = $this->config->get("gateways.{$gateway}", []); |
| 237 | 237 | |
| 238 | - if (\is_string($gateway) && ! empty($globalSettings) && \is_array($setting)) { |
|
| 238 | + if (\is_string($gateway) && !empty($globalSettings) && \is_array($setting)) { |
|
| 239 | 239 | $formatted[$gateway] = new Config(\array_merge($globalSettings, $setting)); |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -14,4 +14,6 @@ |
||
| 14 | 14 | /** |
| 15 | 15 | * Class InvalidArgumentException. |
| 16 | 16 | */ |
| 17 | -class InvalidArgumentException extends Exception {} |
|
| 17 | +class InvalidArgumentException extends Exception |
|
| 18 | +{ |
|
| 19 | +} |
|
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | $params = [ |
| 54 | 54 | 'appid' => $config->get('app_id'), |
| 55 | 55 | 'signature' => $config->get('app_key'), |
| 56 | - 'project' => ! empty($template_code) ? $template_code : (! empty($data['project']) ? $data['project'] : $config->get('project')), |
|
| 56 | + 'project' => !empty($template_code) ? $template_code : (!empty($data['project']) ? $data['project'] : $config->get('project')), |
|
| 57 | 57 | 'to' => $to->getUniversalNumber(), |
| 58 | 58 | 'vars' => json_encode($data, JSON_FORCE_OBJECT), |
| 59 | 59 | ]; |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | |
| 54 | 54 | $result = $this->post(sprintf(self::ENDPOINT_TEMPLATE, 'send'), $params); |
| 55 | 55 | |
| 56 | - if (! $result['result']) { |
|
| 56 | + if (!$result['result']) { |
|
| 57 | 57 | throw new GatewayErrorException($result['message'], $result['statusCode'], $result); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) |
| 61 | 61 | { |
| 62 | 62 | $data = $message->getData($this); |
| 63 | - $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 64 | - $smsAccount = ! empty($data['sms_account']) ? $data['sms_account'] : $config->get('sms_account'); |
|
| 63 | + $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 64 | + $smsAccount = !empty($data['sms_account']) ? $data['sms_account'] : $config->get('sms_account'); |
|
| 65 | 65 | $templateId = $message->getTemplate($this); |
| 66 | - $phoneNumbers = ! empty($data['phone_numbers']) ? $data['phone_numbers'] : $to->getNumber(); |
|
| 67 | - $templateParam = ! empty($data['template_param']) ? $data['template_param'] : $message->getData($this); |
|
| 66 | + $phoneNumbers = !empty($data['phone_numbers']) ? $data['phone_numbers'] : $to->getNumber(); |
|
| 67 | + $templateParam = !empty($data['template_param']) ? $data['template_param'] : $message->getData($this); |
|
| 68 | 68 | |
| 69 | - $tag = ! empty($data['tag']) ? $data['tag'] : ''; |
|
| 69 | + $tag = !empty($data['tag']) ? $data['tag'] : ''; |
|
| 70 | 70 | |
| 71 | 71 | $payload = [ |
| 72 | 72 | 'SmsAccount' => $smsAccount, // 消息组帐号,火山短信页面右上角,短信应用括号中的字符串 |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | public function getEndpoint() |
| 200 | 200 | { |
| 201 | 201 | $regionId = $this->getRegionId(); |
| 202 | - if (! in_array($regionId, array_keys(self::$endpoints))) { |
|
| 202 | + if (!in_array($regionId, array_keys(self::$endpoints))) { |
|
| 203 | 203 | $regionId = self::ENDPOINT_DEFAULT_REGION_ID; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $data = $message->getData($this); |
| 53 | 53 | |
| 54 | - $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 54 | + $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 55 | 55 | |
| 56 | 56 | unset($data['sign_name']); |
| 57 | 57 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), |
| 66 | 66 | 'Action' => self::ENDPOINT_METHOD, |
| 67 | 67 | 'Version' => self::ENDPOINT_VERSION, |
| 68 | - 'PhoneNumbers' => ! \is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), |
|
| 68 | + 'PhoneNumbers' => !\is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), |
|
| 69 | 69 | 'SignName' => $signName, |
| 70 | 70 | 'TemplateCode' => $message->getTemplate($this), |
| 71 | 71 | 'TemplateParam' => json_encode($data, JSON_FORCE_OBJECT), |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $result = $this->get(self::ENDPOINT_URL, $params); |
| 77 | 77 | |
| 78 | - if (! empty($result['Code']) && $result['Code'] != 'OK') { |
|
| 78 | + if (!empty($result['Code']) && $result['Code'] != 'OK') { |
|
| 79 | 79 | throw new GatewayErrorException($result['Message'], $result['Code'], $result); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | 'exceptions' => false, |
| 50 | 50 | ]; |
| 51 | 51 | |
| 52 | - if (! is_null($template)) { |
|
| 52 | + if (!is_null($template)) { |
|
| 53 | 53 | $function = 'tpl_single_send'; |
| 54 | 54 | $data = []; |
| 55 | 55 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | 'mobile' => $to->getNumber(), |
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | - if (! empty($data)) { |
|
| 49 | + if (!empty($data)) { |
|
| 50 | 50 | $params['parameters'] = $data; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -103,21 +103,21 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | // write request uri |
| 105 | 105 | $toSignStr = $method.' '.$path; |
| 106 | - if (! empty($query)) { |
|
| 106 | + if (!empty($query)) { |
|
| 107 | 107 | $toSignStr .= '?'.$query; |
| 108 | 108 | } |
| 109 | 109 | // write host and port |
| 110 | 110 | $toSignStr .= "\nHost: ".$host; |
| 111 | - if (! empty($port)) { |
|
| 111 | + if (!empty($port)) { |
|
| 112 | 112 | $toSignStr .= ':'.$port; |
| 113 | 113 | } |
| 114 | 114 | // write content type |
| 115 | - if (! empty($contentType)) { |
|
| 115 | + if (!empty($contentType)) { |
|
| 116 | 116 | $toSignStr .= "\nContent-Type: ".$contentType; |
| 117 | 117 | } |
| 118 | 118 | $toSignStr .= "\n\n"; |
| 119 | 119 | // write body |
| 120 | - if (! empty($body)) { |
|
| 120 | + if (!empty($body)) { |
|
| 121 | 121 | $toSignStr .= $body; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $data = $message->getData($this); |
| 42 | 42 | |
| 43 | - $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 43 | + $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); |
|
| 44 | 44 | |
| 45 | 45 | unset($data['sign_name']); |
| 46 | 46 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | 'SignatureNonce' => uniqid('', true), |
| 54 | 54 | 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), |
| 55 | 55 | 'Version' => self::ENDPOINT_VERSION, |
| 56 | - 'To' => ! \is_null($to->getIDDCode()) ? (int) $to->getZeroPrefixedNumber() : $to->getNumber(), |
|
| 56 | + 'To' => !\is_null($to->getIDDCode()) ? (int) $to->getZeroPrefixedNumber() : $to->getNumber(), |
|
| 57 | 57 | 'Action' => self::ENDPOINT_ACTION, |
| 58 | 58 | 'From' => $signName, |
| 59 | 59 | 'TemplateCode' => $message->getTemplate($this), |