Skip to content

Commit 96135eb

Browse files
Added documentation on the LoggingDecorator and Dummy class
1 parent 5dcc9a5 commit 96135eb

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,31 @@ $twilio->call('+18085551212', function ($message) {
8383
});
8484
```
8585

86-
Generating TwiML:
86+
#### Dummy class
8787

88-
```php
89-
$twiml = $twilio->twiml(function($message) {
90-
$message->say('Hello');
91-
$message->play('https://api.twilio.com/cowbell.mp3', array('loop' => 5));
92-
});
88+
There is a dummy implementation of the `TwilioInterface` available: `Aloha\Twilio\Dummy`. This class
89+
allows you to inject this instead of a working implementation in case you need to run quick integration tests.
90+
91+
#### Logging decorator
9392

94-
print $twiml;
93+
There is one more class available for you: the `Aloha\Twilio\LoggingDecorator`. This class wraps any
94+
`TwilioInterface` object and logs whatever Twilio will do for you. It also takes a `Psr\Log\LoggerInterface` object
95+
(like Monolog) for logging, you know.
96+
97+
By default the service providers don't wrap objects with the `LoggingDecorator`,
98+
but it is at your disposal in case you want it. A possible use case is to construct a
99+
`TwilioInterface` object that logs what will happen, but doesn't actually call Twilio (using the Dummy class):
100+
101+
```php
102+
if (getenv('APP_ENV') === 'production') {
103+
$twilio = $container->make(\Aloha\Twilio\Manager::class);
104+
} else {
105+
$psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
106+
$twilio = new LoggingDecorator($psrLogger, new \Aloha\Twilio\Dummy());
107+
}
108+
109+
// Inject it wherever you want.
110+
$notifier = new Notifier($twilio);
95111
```
96112

97113
### License

0 commit comments

Comments
 (0)