mirror of
https://github.com/fleetbase/fleetbase.git
synced 2026-01-06 06:15:51 +00:00
takeover and minor fix, allow nullable values for twilio constructor instead of having a system breaking exception when running the system provider
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Contributions are **welcome** and will be fully **credited**.
|
Contributions are **welcome** and will be fully **credited**.
|
||||||
|
|
||||||
We accept contributions via Pull Requests on [Github](https://github.com/aloha/laravel-twilio).
|
We accept contributions via Pull Requests on [Github](https://github.com/fleetbase/laravel-twilio).
|
||||||
|
|
||||||
## Pull Requests
|
## Pull Requests
|
||||||
|
|
||||||
|
|||||||
32
README.md
32
README.md
@@ -2,17 +2,17 @@ laravel-twilio
|
|||||||
===============
|
===============
|
||||||
Laravel Twilio API Integration
|
Laravel Twilio API Integration
|
||||||
|
|
||||||
[](https://travis-ci.org/aloha/laravel-twilio)
|
[](https://travis-ci.org/fleetbase/laravel-twilio)
|
||||||
[](https://packagist.org/packages/aloha/twilio)
|
[](https://packagist.org/packages/fleetbase/twilio)
|
||||||
[](https://packagist.org/packages/aloha/twilio)
|
[](https://packagist.org/packages/fleetbase/twilio)
|
||||||
[](#license)
|
[](#license)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Begin by installing this package through Composer. Run this command from the Terminal:
|
Begin by installing this package through Composer. Run this command from the Terminal:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require aloha/twilio
|
composer require fleetbase/twilio
|
||||||
```
|
```
|
||||||
|
|
||||||
This will register two new artisan commands for you:
|
This will register two new artisan commands for you:
|
||||||
@@ -22,25 +22,25 @@ This will register two new artisan commands for you:
|
|||||||
|
|
||||||
And make these objects resolvable from the IoC container:
|
And make these objects resolvable from the IoC container:
|
||||||
|
|
||||||
- `Aloha\Twilio\Manager` (aliased as `twilio`)
|
- `Fleetbase\Twilio\Manager` (aliased as `twilio`)
|
||||||
- `Aloha\Twilio\TwilioInterface` (resolves a `Twilio` object, the default connection object created by the `Manager`).
|
- `Fleetbase\Twilio\TwilioInterface` (resolves a `Twilio` object, the default connection object created by the `Manager`).
|
||||||
|
|
||||||
There's a Facade class available for you, if you like. In your `app.php` config file add the following
|
There's a Facade class available for you, if you like. In your `app.php` config file add the following
|
||||||
line to the `aliases` array if you want to use a short class name:
|
line to the `aliases` array if you want to use a short class name:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'Twilio' => 'Aloha\Twilio\Support\Laravel\Facade',
|
'Twilio' => 'Fleetbase\Twilio\Support\Laravel\Facade',
|
||||||
```
|
```
|
||||||
|
|
||||||
You can publish the default config file to `config/twilio.php` with the terminal command
|
You can publish the default config file to `config/twilio.php` with the terminal command
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
php artisan vendor:publish --provider="Aloha\Twilio\Support\Laravel\ServiceProvider"
|
php artisan vendor:publish --provider="Fleetbase\Twilio\Support\Laravel\ServiceProvider"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Facade
|
#### Facade
|
||||||
|
|
||||||
The facade has the exact same methods as the `Aloha\Twilio\TwilioInterface`. First, include the `Facade` class at the top of your file:
|
The facade has the exact same methods as the `Fleetbase\Twilio\TwilioInterface`. First, include the `Facade` class at the top of your file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Twilio;
|
use Twilio;
|
||||||
@@ -63,10 +63,10 @@ Define multiple entries in your `twilio` [config file](src/config/config.php) to
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Creating a Twilio object. This object implements the `Aloha\Twilio\TwilioInterface`.
|
Creating a Twilio object. This object implements the `Fleetbase\Twilio\TwilioInterface`.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$twilio = new Aloha\Twilio\Twilio($accountId, $token, $fromNumber);
|
$twilio = new Fleetbase\Twilio\Twilio($accountId, $token, $fromNumber);
|
||||||
```
|
```
|
||||||
|
|
||||||
Sending a text message:
|
Sending a text message:
|
||||||
@@ -131,12 +131,12 @@ $twilio->call($to, $message, $params);
|
|||||||
|
|
||||||
#### Dummy class
|
#### Dummy class
|
||||||
|
|
||||||
There is a dummy implementation of the `TwilioInterface` available: `Aloha\Twilio\Dummy`. This class
|
There is a dummy implementation of the `TwilioInterface` available: `Fleetbase\Twilio\Dummy`. This class
|
||||||
allows you to inject this instead of a working implementation in case you need to run quick integration tests.
|
allows you to inject this instead of a working implementation in case you need to run quick integration tests.
|
||||||
|
|
||||||
#### Logging decorator
|
#### Logging decorator
|
||||||
|
|
||||||
There is one more class available for you: the `Aloha\Twilio\LoggingDecorator`. This class wraps any
|
There is one more class available for you: the `Fleetbase\Twilio\LoggingDecorator`. This class wraps any
|
||||||
`TwilioInterface` object and logs whatever Twilio will do for you. It also takes a `Psr\Log\LoggerInterface` object
|
`TwilioInterface` object and logs whatever Twilio will do for you. It also takes a `Psr\Log\LoggerInterface` object
|
||||||
(like Monolog) for logging, you know.
|
(like Monolog) for logging, you know.
|
||||||
|
|
||||||
@@ -146,10 +146,10 @@ but it is at your disposal in case you want it. A possible use case is to constr
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
if (getenv('APP_ENV') === 'production') {
|
if (getenv('APP_ENV') === 'production') {
|
||||||
$twilio = $container->make(\Aloha\Twilio\Manager::class);
|
$twilio = $container->make(\Fleetbase\Twilio\Manager::class);
|
||||||
} else {
|
} else {
|
||||||
$psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
|
$psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
|
||||||
$twilio = new LoggingDecorator($psrLogger, new \Aloha\Twilio\Dummy());
|
$twilio = new LoggingDecorator($psrLogger, new \Fleetbase\Twilio\Dummy());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject it wherever you want.
|
// Inject it wherever you want.
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "aloha/twilio",
|
"name": "fleetbase/twilio",
|
||||||
"description": "Twilio API for Laravel",
|
"description": "Twilio API for Laravel",
|
||||||
|
"version": "5.0.1",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": ["sms", "ivr", "laravel", "twilio"],
|
"keywords": ["sms", "ivr", "laravel", "twilio"],
|
||||||
"authors": [
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Ronald A Richardson",
|
||||||
|
"email": "ron@fleetbase.io"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Travis J Ryan",
|
"name": "Travis J Ryan",
|
||||||
"email": "travisjryan@gmail.com"
|
"email": "travisjryan@gmail.com"
|
||||||
@@ -13,7 +18,7 @@
|
|||||||
"email": "vandevreken.hannes@gmail.com"
|
"email": "vandevreken.hannes@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"homepage":"https://github.com/aloha/laravel-twilio",
|
"homepage":"https://github.com/fleetbase/laravel-twilio",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.0",
|
"php": ">=7.2.0",
|
||||||
@@ -27,12 +32,12 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Aloha\\Twilio\\": "src/"
|
"Fleetbase\\Twilio\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Aloha\\Twilio\\Tests\\": "tests/"
|
"Fleetbase\\Twilio\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -51,10 +56,10 @@
|
|||||||
"extra": {
|
"extra": {
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
"Aloha\\Twilio\\Support\\Laravel\\ServiceProvider"
|
"Fleetbase\\Twilio\\Support\\Laravel\\ServiceProvider"
|
||||||
],
|
],
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"Twilio": "Aloha\\Twilio\\Support\\Laravel\\Facade"
|
"Twilio": "Fleetbase\\Twilio\\Support\\Laravel\\Facade"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Commands;
|
namespace Fleetbase\Twilio\Commands;
|
||||||
|
|
||||||
use Aloha\Twilio\TwilioInterface;
|
use Fleetbase\Twilio\TwilioInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Commands;
|
namespace Fleetbase\Twilio\Commands;
|
||||||
|
|
||||||
use Aloha\Twilio\TwilioInterface;
|
use Fleetbase\Twilio\TwilioInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
@@ -24,14 +24,14 @@ class TwilioSmsCommand extends Command
|
|||||||
protected $description = 'Twilio command to test Twilio SMS API Integration.';
|
protected $description = 'Twilio command to test Twilio SMS API Integration.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Aloha\Twilio\TwilioInterface
|
* @var \Fleetbase\Twilio\TwilioInterface
|
||||||
*/
|
*/
|
||||||
protected $twilio;
|
protected $twilio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
* @param \Aloha\Twilio\TwilioInterface $twilio
|
* @param \Fleetbase\Twilio\TwilioInterface $twilio
|
||||||
*/
|
*/
|
||||||
public function __construct(TwilioInterface $twilio)
|
public function __construct(TwilioInterface $twilio)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio;
|
namespace Fleetbase\Twilio;
|
||||||
|
|
||||||
use Twilio\Exceptions\ConfigurationException;
|
use Twilio\Exceptions\ConfigurationException;
|
||||||
use Twilio\Rest\Api;
|
use Twilio\Rest\Api;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio;
|
namespace Fleetbase\Twilio;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio;
|
namespace Fleetbase\Twilio;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
||||||
@@ -51,7 +51,7 @@ class Manager implements TwilioInterface
|
|||||||
throw new InvalidArgumentException("Connection \"{$connection}\" is not configured.");
|
throw new InvalidArgumentException("Connection \"{$connection}\" is not configured.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = $this->settings[$connection];
|
$settings = $this->settings[$connection] ?? ['sid' => '', 'token' => '', 'from' => ''];
|
||||||
|
|
||||||
return new Twilio($settings['sid'], $settings['token'], $settings['from']);
|
return new Twilio($settings['sid'], $settings['token'], $settings['from']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Support\Laravel;
|
namespace Fleetbase\Twilio\Support\Laravel;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade as BaseFacade;
|
use Illuminate\Support\Facades\Facade as BaseFacade;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Support\Laravel;
|
namespace Fleetbase\Twilio\Support\Laravel;
|
||||||
|
|
||||||
use Aloha\Twilio\Commands\TwilioCallCommand;
|
use Fleetbase\Twilio\Commands\TwilioCallCommand;
|
||||||
use Aloha\Twilio\Commands\TwilioSmsCommand;
|
use Fleetbase\Twilio\Commands\TwilioSmsCommand;
|
||||||
use Aloha\Twilio\Manager;
|
use Fleetbase\Twilio\Manager;
|
||||||
use Aloha\Twilio\TwilioInterface;
|
use Fleetbase\Twilio\TwilioInterface;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio;
|
namespace Fleetbase\Twilio;
|
||||||
|
|
||||||
use Twilio\Exceptions\ConfigurationException;
|
use Twilio\Exceptions\ConfigurationException;
|
||||||
use Twilio\Exceptions\TwilioException;
|
use Twilio\Exceptions\TwilioException;
|
||||||
@@ -38,12 +38,12 @@ class Twilio implements TwilioInterface
|
|||||||
protected $twilio;
|
protected $twilio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $token
|
* @param string|null $token
|
||||||
* @param string $from
|
* @param string|null $from
|
||||||
* @param string $sid
|
* @param string|null $sid
|
||||||
* @param bool $sslVerify
|
* @param bool $sslVerify
|
||||||
*/
|
*/
|
||||||
public function __construct(string $sid, string $token, string $from, bool $sslVerify = true)
|
public function __construct(?string $sid = null, ?string $token = null, ?string $from = null, bool $sslVerify = true)
|
||||||
{
|
{
|
||||||
$this->sid = $sid;
|
$this->sid = $sid;
|
||||||
$this->token = $token;
|
$this->token = $token;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio;
|
namespace Fleetbase\Twilio;
|
||||||
|
|
||||||
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
use Twilio\Rest\Api\V2010\Account\CallInstance;
|
||||||
use Twilio\Rest\Api\V2010\Account\MessageInstance;
|
use Twilio\Rest\Api\V2010\Account\MessageInstance;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Tests;
|
namespace Fleetbase\Twilio\Tests;
|
||||||
|
|
||||||
use Aloha\Twilio\Commands\TwilioCallCommand;
|
use Fleetbase\Twilio\Commands\TwilioCallCommand;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class TwilioCallCommandTest extends TestCase
|
class TwilioCallCommandTest extends TestCase
|
||||||
@@ -13,7 +13,7 @@ class TwilioCallCommandTest extends TestCase
|
|||||||
public function testName()
|
public function testName()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
$stub = $this->createMock('Aloha\Twilio\TwilioInterface');
|
$stub = $this->createMock('Fleetbase\Twilio\TwilioInterface');
|
||||||
$command = new TwilioCallCommand($stub);
|
$command = new TwilioCallCommand($stub);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aloha\Twilio\Tests;
|
namespace Fleetbase\Twilio\Tests;
|
||||||
|
|
||||||
use Aloha\Twilio\Commands\TwilioSmsCommand;
|
use Fleetbase\Twilio\Commands\TwilioSmsCommand;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class TwilioSmsCommandTest extends TestCase
|
class TwilioSmsCommandTest extends TestCase
|
||||||
@@ -13,7 +13,7 @@ class TwilioSmsCommandTest extends TestCase
|
|||||||
public function testName()
|
public function testName()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
$stub = $this->createMock('Aloha\Twilio\TwilioInterface');
|
$stub = $this->createMock('Fleetbase\Twilio\TwilioInterface');
|
||||||
$command = new TwilioSmsCommand($stub);
|
$command = new TwilioSmsCommand($stub);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
Reference in New Issue
Block a user