<commit_before>laravel-twilio
===============
Laravel Twillio API Integration

[![Build Status](https://travis-ci.org/aloha/laravel-twilio.svg)](https://travis-ci.org/aloha/laravel-twilio)
[![Total Downloads](https://poser.pugx.org/aloha/twilio/downloads.svg)](https://packagist.org/packages/aloha/twilio)
[![Latest Stable Version](https://poser.pugx.org/aloha/twilio/v/stable.svg)](https://packagist.org/packages/aloha/twilio)
[![Latest Unstable Version](https://poser.pugx.org/aloha/twilio/v/unstable.svg)](https://packagist.org/packages/aloha/twilio)
[![License](https://poser.pugx.org/aloha/twilio/license.svg)](https://packagist.org/packages/aloha/twilio)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/aloha/laravel-twilio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

## Installation

Begin by installing this package through Composer. In Laravel 4, run this command from the Terminal:
```bash
composer require aloha/twilio
```
In Laravel 5, use 2.0.0 pre-release version:
```bash
composer require 'aloha/twilio:2.0.0-RC2'
```
## Laravel integration

To wire this up in your Laravel project, wether it's built in Laravel 4 or 5, you need to add the service provider. Open `app.php`, and add a new item to the providers array.

```php
'Aloha\Twilio\Support\Laravel\ServiceProvider',
```

This will register two new artisan commands for you:

- `twilio:sms`
- `twilio:call`

Then, add a Facade for more convenient usage. In your `app.php` config file add the following line to the `aliases` array:

```php
'Twilio' => 'Aloha\Twilio\Support\Laravel\Facade',
```

In Laravel 4 you need to publish the default config file to `app/config/packages/aloha/twilio/config.php` with the artisan command `config:publish aloha/twilio`.

In Laravel 5 you need to publish the default config file to `config/twilio.php` with the artisan command `vendor:publish`.

#### Facade

The facade now has the exact same methods as the `Aloha\Twilio\TwilioInterface`.
One extra feature is that you can define which settings (and which sender phone number) to use:

```php
Twilio::from('callcenter')->message($user->phone, $message);
Twilio::from('board_room')->message($boss->phone, 'Hi there boss!');
```

Define multiple entries in your `twilio` config to make use of this feature.

### Usage

Creating a Twilio object. This object implements the `Aloha\Twilio\TwilioInterface`.

```php
$twilio = new Aloha\Twilio\Twilio($accountId, $token, $fromNumber);
```

Sending a text message:

```php
$twilio->message('+18085551212', 'Pink Elephants and Happy Rainbows');
```

Creating a call:

```php
$twilio->call('+18085551212', 'http://foo.com/call.xml');
```

Generating a call and building the message in one go:

```php
$twilio->call('+18085551212', function ($message) {
    $message->say('Hello');
    $message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);
});
```

Generating TwiML:

```php
$twiml = $twilio->twiml(function($message) {
    $message->say('Hello');
    $message->play('https://api.twilio.com/cowbell.mp3', array('loop' => 5));
});

print $twiml;
```

### License

laravel-twilio is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)<commit_msg>Added documentation on the LoggingDecorator and Dummy class<commit_after>laravel-twilio
===============
Laravel Twillio API Integration

[![Build Status](https://travis-ci.org/aloha/laravel-twilio.svg)](https://travis-ci.org/aloha/laravel-twilio)
[![Total Downloads](https://poser.pugx.org/aloha/twilio/downloads.svg)](https://packagist.org/packages/aloha/twilio)
[![Latest Stable Version](https://poser.pugx.org/aloha/twilio/v/stable.svg)](https://packagist.org/packages/aloha/twilio)
[![Latest Unstable Version](https://poser.pugx.org/aloha/twilio/v/unstable.svg)](https://packagist.org/packages/aloha/twilio)
[![License](https://poser.pugx.org/aloha/twilio/license.svg)](https://packagist.org/packages/aloha/twilio)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/aloha/laravel-twilio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

## Installation

Begin by installing this package through Composer. In Laravel 4, run this command from the Terminal:
```bash
composer require aloha/twilio
```
In Laravel 5, use 2.0.0 pre-release version:
```bash
composer require 'aloha/twilio:2.0.0-RC2'
```
## Laravel integration

To wire this up in your Laravel project, wether it's built in Laravel 4 or 5, you need to add the service provider. Open `app.php`, and add a new item to the providers array.

```php
'Aloha\Twilio\Support\Laravel\ServiceProvider',
```

This will register two new artisan commands for you:

- `twilio:sms`
- `twilio:call`

Then, add a Facade for more convenient usage. In your `app.php` config file add the following line to the `aliases` array:

```php
'Twilio' => 'Aloha\Twilio\Support\Laravel\Facade',
```

In Laravel 4 you need to publish the default config file to `app/config/packages/aloha/twilio/config.php` with the artisan command `config:publish aloha/twilio`.

In Laravel 5 you need to publish the default config file to `config/twilio.php` with the artisan command `vendor:publish`.

#### Facade

The facade now has the exact same methods as the `Aloha\Twilio\TwilioInterface`.
One extra feature is that you can define which settings (and which sender phone number) to use:

```php
Twilio::from('callcenter')->message($user->phone, $message);
Twilio::from('board_room')->message($boss->phone, 'Hi there boss!');
```

Define multiple entries in your `twilio` config to make use of this feature.

### Usage

Creating a Twilio object. This object implements the `Aloha\Twilio\TwilioInterface`.

```php
$twilio = new Aloha\Twilio\Twilio($accountId, $token, $fromNumber);
```

Sending a text message:

```php
$twilio->message('+18085551212', 'Pink Elephants and Happy Rainbows');
```

Creating a call:

```php
$twilio->call('+18085551212', 'http://foo.com/call.xml');
```

Generating a call and building the message in one go:

```php
$twilio->call('+18085551212', function ($message) {
    $message->say('Hello');
    $message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);
});
```

#### Dummy class

There is a dummy implementation of the `TwilioInterface` available: `Aloha\Twilio\Dummy`. This class
allows you to inject this instead of a working implementation in case you need to run quick integration tests.

#### Logging decorator

There is one more class available for you: the `Aloha\Twilio\LoggingDecorator`. This class wraps any
`TwilioInterface` object and logs whatever Twilio will do for you. It also takes a `Psr\Log\LoggerInterface` object
(like Monolog) for logging, you know.

By default the service providers don't wrap objects with the `LoggingDecorator`,
but it is at your disposal in case you want it. A possible use case is to construct a
`TwilioInterface` object that logs what will happen, but doesn't actually call Twilio (using the Dummy class):

```php
if (getenv('APP_ENV') === 'production') {
    $twilio = $container->make(\Aloha\Twilio\Manager::class);
} else {
    $psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
    $twilio = new LoggingDecorator($psrLogger, new \Aloha\Twilio\Dummy());
}

// Inject it wherever you want.
$notifier = new Notifier($twilio);
```

### License

laravel-twilio is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
{'fraction_non_alphanumeric': 0.15136443070305147, 'fraction_numerical': 0.013711520365640543, 'mean_word_length': 5.164043082021541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 27, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6755163', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2431, 'n_words': 694}