-
-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Adding types & logging in
catch
blocks
- Loading branch information
Showing
4 changed files
with
28 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<?php | ||
/** | ||
* @author Pierre-Henry Soria <[email protected]> | ||
* @copyright (c) 2019, Pierre-Henry Soria. All Rights Reserved. | ||
* @copyright (c) 2019-2023, Pierre-Henry Soria. All Rights Reserved. | ||
* @license MIT License; See LICENSE.md and COPYRIGHT.md in the root directory. | ||
* @package PH7 / App / System / Module / SMS Verification / Inc / Class | ||
*/ | ||
|
||
namespace PH7; | ||
|
||
use PH7\Framework\Error\Logger; | ||
use Twilio\Rest\Client; | ||
use Twilio\Exceptions\TwilioException; | ||
|
||
class TwilioProvider extends SmsProvider implements SmsProvidable | ||
{ | ||
|
@@ -19,14 +21,20 @@ public function send($sPhoneNumber, $sTextMessage) | |
{ | ||
$oClient = new Client($this->sApiId, $this->sApiToken); | ||
|
||
$oMessage = $oClient->messages->create( | ||
$sPhoneNumber, | ||
[ | ||
'from' => $this->sSenderNumber, | ||
'body' => $sTextMessage | ||
] | ||
); | ||
try { | ||
$oMessage = $oClient->messages->create( | ||
$sPhoneNumber, | ||
[ | ||
'from' => $this->sSenderNumber, | ||
'body' => $sTextMessage | ||
] | ||
); | ||
|
||
return strlen($oMessage->sid) > 1; | ||
return strlen($oMessage->sid) > 1; | ||
} catch (TwilioException $oExcept) { | ||
(new Logger())->msg('Twilio error while sending SMS: ' . $oExcept->getMessage()); | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters