Skip to content

Commit

Permalink
Prepare 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Jan 29, 2022
1 parent a4dded5 commit e5ccca4
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 285 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/.php-cs-fixer.php export-ignore
/CHANGELOG.md export-ignore
/README.md export-ignore
/UPGRADE-2.0.md export-ignore
/phpunit.xml.dist export-ignore
19 changes: 4 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,15 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
laravel: ['^6.18', '8.*']
php: ['8.0', '8.1']
laravel: ['9.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
include:
- php: '7.2'
laravel: '^6.18'
- php: '8.0'
laravel: '9.*'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
- php: '8.1'
laravel: '8.*'
composer-flags: '--prefer-stable'
can-fail: false
- php: '8.1'
laravel: '9.*'
composer-flags: ''
can-fail: true
exclude:
- php: '7.2'
laravel: '8.*'

name: "PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

Expand Down
4 changes: 2 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
return (new PhpCsFixer\Config())
->setRules(
[
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'@PSR12' => true,
'@PSR2' => true,
Expand Down
18 changes: 2 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# Changelog

## 1.4.0 (2022-01-29)
## 2.0.0 (2022-??-??)

- Added support for Laravel 9

## 1.3.0 (2020-11-09)

- Drop support for Laravel 6.17 and earlier
- Drop support for Laravel 7
- Allow install on PHP 8

## 1.2.0 (2020-09-07)

- Added support for Laravel 8

## 1.1.0 (2020-03-21)

- Add a notification channel to send SMS messages
- Consult the UPGRADE guide for changes between 1.x and 2.0
8 changes: 8 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Upgrade from 1.x to 2.0

The below guide will assist in upgrading from the 1.x versions to 2.0.

## Package Requirements

- Laravel 9 or later
- PHP 8.0 or later
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"description": "Twilio SDK integration for Laravel",
"keywords": ["laravel", "twilio"],
"require": {
"php": "^7.2 || ^8.0",
"illuminate/support": "^6.18 || ^8.0 || ^9.0",
"twilio/sdk": "^6.0"
"php": "^8.0",
"illuminate/http": "^9.0",
"illuminate/support": "^9.0",
"twilio/sdk": "^6.33"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"laravel/framework": "^6.18 || ^8.0 || ^9.0",
"orchestra/testbench": "^4.0 || ^6.0 || ^7.0",
"phpunit/phpunit": "^8.5 || ^9.3"
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.0",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.5"
},
"suggest": {
"illuminate/notifications": "To use Laravel's notifications component with this package"
Expand Down
5 changes: 2 additions & 3 deletions docs/client-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ TwilioClient::twilio();

This package attempts to create an appropriate `Twilio\Http\Client` for the SDK based on the packages available in your application, using the following preferences:

- If using Laravel 7 and Guzzle is available, a client using [Laravel's HTTP client](https://laravel.com/docs/http-client) is used
- If Guzzle is available, the Twilio SDK's Guzzle client is used
- If neither of the above criteria are met, the Twilio SDK's Curl client is used
- If Guzzle is available, a client using [Laravel's HTTP client](https://laravel.com/docs/http-client) is used
- If Guzzle is not available, the Twilio SDK's Curl client is used

If you need to customize the HTTP client used by default in your application, you can extend the `Twilio\Http\Client` service this package creates to use your own HTTP client.
2 changes: 1 addition & 1 deletion docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AppServiceProvider extends ServiceProvider
{
\TwilioClient::extend(
'custom',
function (Container $container): TwilioClientContract {
static function (Container $container): TwilioClientContract {
/*
* Create a custom client from your application.
*
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- [Introduction](/open-source/packages/laravel-twilio/docs/1.x/intro)
- [Installation & Setup](/open-source/packages/laravel-twilio/docs/1.x/installation)
- [Using The Client](/open-source/packages/laravel-twilio/docs/1.x/client-usage)
- [Connection Management](/open-source/packages/laravel-twilio/docs/1.x/connections)
- [Notifications](/open-source/packages/laravel-twilio/docs/1.x/notifications)
- [Introduction](/open-source/packages/laravel-twilio/docs/2.x/intro)
- [Installation & Setup](/open-source/packages/laravel-twilio/docs/2.x/installation)
- [Using The Client](/open-source/packages/laravel-twilio/docs/2.x/client-usage)
- [Connection Management](/open-source/packages/laravel-twilio/docs/2.x/connections)
- [Notifications](/open-source/packages/laravel-twilio/docs/2.x/notifications)
20 changes: 6 additions & 14 deletions docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ class User extends Authenticatable
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
* @return string[]
*/
public function via($notifiable)
public function via(mixed $notifiable): array
{
// This application's users can receive notifications by mail and Twilio SMS
return ['mail', 'twilio'];
}

/**
* Get the notification routing information for the Twilio driver.
*
* @param Notification $notification
*
* @return string
*/
public function routeNotificationForTwilio($notification)
public function routeNotificationForTwilio(Notification $notification): string
{
return $this->mobile_number;
}
Expand All @@ -45,20 +39,18 @@ For notifications that support being sent as an SMS, you should define a `toTwil
```php
namespace App\Notifications;

use App\Models\User;
use Illuminate\Notifications\Notification;

final class PasswordExpiredNotification extends Notification
{
/**
* Get the Twilio / SMS representation of the notification.
*
* @param mixed $notifiable
*
* @return string
* @param User $notifiable
*/
public function toTwilio($notifiable)
public function toTwilio(mixed $notifiable): string
{
// The $notifiable in this example is your User model
return sprintf('Hello %s, this is a note that the password for your %s account has expired.', $notifiable->name, config('app.name'));
}
}
Expand Down
15 changes: 8 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit backupGlobals="false"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
Expand All @@ -10,16 +12,15 @@
stopOnFailure="false"
verbose="true"
>

<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
78 changes: 23 additions & 55 deletions src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,86 +14,62 @@
class ConnectionManager extends Manager implements TwilioClientContract
{
/**
* Get a connection instance.
*
* @param string|null $name
*
* @return TwilioClientContract
*
* @throws \InvalidArgumentException if the driver cannot be created
*/
public function connection(?string $name = null)
public function connection(?string $name = null): TwilioClientContract
{
return $this->driver($name);
}

/**
* Get the default channel driver name.
*
* @return string
*/
public function getDefaultDriver()
public function getDefaultDriver(): string
{
return $this->config->get('twilio.default', 'twilio');
}

/**
* Create a new driver instance.
*
* @param string $driver
*
* @return TwilioClientContract
*
* @throws \InvalidArgumentException if the driver cannot be created
*/
protected function createDriver($driver)
protected function createDriver($driver): TwilioClientContract
{
try {
return parent::createDriver($driver);
} catch (\InvalidArgumentException $e) {
if ($this->config->has("twilio.connections.$driver")) {
try {
return $this->container->make(
TwilioClient::class,
[
'twilio' => $this->container->make(
RestClient::class,
[
'username' => $this->config->get("twilio.connections.$driver.sid"),
'password' => $this->config->get("twilio.connections.$driver.token"),
'httpClient' => $this->container->make(HttpClient::class),
]
),
'from' => $this->config->get("twilio.connections.$driver.from"),
]
);
} catch (ConfigurationException $e) {
throw new \InvalidArgumentException("Driver [$driver] is not correctly configured.", $e->getCode(), $e);
}
if (!$this->config->has("twilio.connections.$driver")) {
throw $e;
}

throw $e;
try {
return $this->container->make(
TwilioClient::class,
[
'twilio' => $this->container->make(
RestClient::class,
[
'username' => $this->config->get("twilio.connections.$driver.sid"),
'password' => $this->config->get("twilio.connections.$driver.token"),
'httpClient' => $this->container->make(HttpClient::class),
]
),
'from' => $this->config->get("twilio.connections.$driver.from"),
]
);
} catch (ConfigurationException $e) {
throw new \InvalidArgumentException("Driver [$driver] is not correctly configured.", $e->getCode(), $e);
}
}
}

/**
* Provides access to the REST API client from the Twilio SDK.
*
* @return RestClient
*/
public function twilio(): RestClient
{
return $this->connection()->twilio();
}

/**
* Create a call through the Twilio API.
*
* @param string $to The phone number to create a call to.
* @param array $params Optional arguments for the created call.
*
* @return CallInstance
*
* @throws TwilioException on Twilio API failure
*/
public function call(string $to, array $params = []): CallInstance
Expand All @@ -102,14 +78,6 @@ public function call(string $to, array $params = []): CallInstance
}

/**
* Send a SMS through the Twilio API.
*
* @param string $to The phone number to send the SMS to.
* @param string $message The message body to send.
* @param array $params Optional arguments for the SMS.
*
* @return MessageInstance
*
* @throws TwilioException on Twilio API failure
*/
public function message(string $to, string $message, array $params = []): MessageInstance
Expand Down
13 changes: 0 additions & 13 deletions src/Contracts/TwilioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,19 @@ interface TwilioClient
{
/**
* Provides access to the REST API client from the Twilio SDK.
*
* @return Client
*/
public function twilio(): Client;

/**
* Create a call through the Twilio API.
*
* @param string $to The phone number to create a call to.
* @param array $params Optional arguments for the created call.
*
* @return CallInstance
*
* @throws TwilioException on Twilio API failure
*/
public function call(string $to, array $params = []): CallInstance;

/**
* Send a SMS through the Twilio API.
*
* @param string $to The phone number to send the SMS to.
* @param string $message The message body to send.
* @param array $params Optional arguments for the SMS.
*
* @return MessageInstance
*
* @throws TwilioException on Twilio API failure
*/
public function message(string $to, string $message, array $params = []): MessageInstance;
Expand Down
Loading

0 comments on commit e5ccca4

Please sign in to comment.