From 860092e2dd5ecada3c07a0897eb2ad03852a63a5 Mon Sep 17 00:00:00 2001 From: Giampaolo Date: Mon, 26 Oct 2015 10:59:35 +0100 Subject: [PATCH 1/4] PSR-0 => PSR-4, adds Laravel 4.2 implementation Improves folder structure for PSR-4 compatibility Improves folder structure for PSR-4 compatibility Updates PSR-4 Updates PSR-4 Improves for Laravel 4.2 implementation --- README.md | 44 ++++++++++++-- composer.json | 14 ++++- src/{ => Jlinn}/Mandrill/Api.php | 2 +- src/{ => Jlinn}/Mandrill/Api/Exports.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Inbound.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Ips.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Messages.php | 6 +- src/{ => Jlinn}/Mandrill/Api/Rejects.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Senders.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Subaccounts.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Tags.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Templates.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Urls.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Users.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Webhooks.php | 5 +- src/{ => Jlinn}/Mandrill/Api/Whitelists.php | 5 +- src/{ => Jlinn}/Mandrill/Exception.php | 3 +- .../Mandrill/Exception/APIException.php | 3 +- src/Jlinn/Mandrill/Facades/Mandrill.php | 10 ++++ src/{ => Jlinn}/Mandrill/Mandrill.php | 4 +- src/Jlinn/Mandrill/MandrillFactory.php | 57 +++++++++++++++++++ .../Mandrill/MandrillServiceProvider.php | 29 ++++++++++ src/{ => Jlinn}/Mandrill/Struct.php | 3 +- .../Mandrill/Struct/Attachment.php | 4 +- src/{ => Jlinn}/Mandrill/Struct/Message.php | 4 +- src/{ => Jlinn}/Mandrill/Struct/Recipient.php | 4 +- src/config/config.php | 15 +++++ 27 files changed, 202 insertions(+), 60 deletions(-) rename src/{ => Jlinn}/Mandrill/Api.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Exports.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Inbound.php (97%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Ips.php (99%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Messages.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Rejects.php (97%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Senders.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Subaccounts.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Tags.php (97%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Templates.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Urls.php (95%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Users.php (94%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Webhooks.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Api/Whitelists.php (96%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Exception.php (80%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Exception/APIException.php (95%) mode change 100755 => 100644 create mode 100644 src/Jlinn/Mandrill/Facades/Mandrill.php rename src/{ => Jlinn}/Mandrill/Mandrill.php (99%) mode change 100755 => 100644 create mode 100644 src/Jlinn/Mandrill/MandrillFactory.php create mode 100644 src/Jlinn/Mandrill/MandrillServiceProvider.php rename src/{ => Jlinn}/Mandrill/Struct.php (98%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Struct/Attachment.php (86%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Struct/Message.php (99%) mode change 100755 => 100644 rename src/{ => Jlinn}/Mandrill/Struct/Recipient.php (97%) mode change 100755 => 100644 create mode 100644 src/config/config.php diff --git a/README.md b/README.md index c388cca..4c2c6bd 100755 --- a/README.md +++ b/README.md @@ -17,13 +17,14 @@ php composer.phar require jlinn/mandrill-api-php:~1.0 Usage ===== + Sending a Message ----------------- ```php -use Mandrill\Mandrill; -use Mandrill\Struct\Message; -use Mandrill\Struct\Recipient; +use Jlinn\Mandrill\Mandrill; +use Jlinn\Mandrill\Struct\Message; +use Jlinn\Mandrill\Struct\Recipient; // instantiate a client object $mandrill = new Mandrill('your_api_key'); @@ -48,4 +49,39 @@ $message->addRecipient($recipient); // send the message $response = $mandrill->messages()->send($message); -``` \ No newline at end of file +``` + +Usage with Laravel 4.x +===== + +We have built a factory so that it's easier to use with Laravel 4.x facades. + +Configuration +----------------- + +In order to publish the package configuration you need to perform the following command: + +``` +php artisan config:publish jlinn/mandrill-api-php +``` + +Change then the `secret` variable with your Mandrill secret key. + +Sending a Message +----------------- + +```php +$api = Mandrill::api(); + +$message = Mandrill::message([ + 'text' => 'Hello, *|NAME|*!', + 'subject' => 'Test', + 'from_email' => 'test@example.com', + 'from_name' => 'Mandrill API Test' +]); + +$recipient = Mandrill::recipient('recipient.email@example.com', 'Recipient Name'); +$recipient->addMergeVar('NAME', $recipient->name); +$message->addRecipient($recipient); + +$response = $api->messages()->send($message); \ No newline at end of file diff --git a/composer.json b/composer.json index 74c9b62..b365384 100755 --- a/composer.json +++ b/composer.json @@ -19,8 +19,18 @@ }, "autoload": { "psr-0": { - "Mandrill": "src/", - "Mandrill\\Tests": "tests/" + "Jlinn\\": "src/Jlinn/" + }, + "psr-4": { + "Jlinn\\": "src/Jlinn/" + } + }, + "autoload-dev": { + "psr-0": { + "Jlinn\\": "tests/" + }, + "psr-4": { + "Jlinn\\": "tests/" } } } \ No newline at end of file diff --git a/src/Mandrill/Api.php b/src/Jlinn/Mandrill/Api.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api.php rename to src/Jlinn/Mandrill/Api.php index a622074..692a69a --- a/src/Mandrill/Api.php +++ b/src/Jlinn/Mandrill/Api.php @@ -5,7 +5,7 @@ * Time: 4:46 PM */ -namespace Mandrill; +namespace Jlinn\Mandrill; use Guzzle\Http\Client; use Guzzle\Http\Exception\ServerErrorResponseException; diff --git a/src/Mandrill/Api/Exports.php b/src/Jlinn/Mandrill/Api/Exports.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Exports.php rename to src/Jlinn/Mandrill/Api/Exports.php index f81deea..592a9b7 --- a/src/Mandrill/Api/Exports.php +++ b/src/Jlinn/Mandrill/Api/Exports.php @@ -5,10 +5,9 @@ * Time: 4:56 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Exports diff --git a/src/Mandrill/Api/Inbound.php b/src/Jlinn/Mandrill/Api/Inbound.php old mode 100755 new mode 100644 similarity index 97% rename from src/Mandrill/Api/Inbound.php rename to src/Jlinn/Mandrill/Api/Inbound.php index 9366561..9705084 --- a/src/Mandrill/Api/Inbound.php +++ b/src/Jlinn/Mandrill/Api/Inbound.php @@ -5,10 +5,9 @@ * Time: 4:52 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Inbound diff --git a/src/Mandrill/Api/Ips.php b/src/Jlinn/Mandrill/Api/Ips.php old mode 100755 new mode 100644 similarity index 99% rename from src/Mandrill/Api/Ips.php rename to src/Jlinn/Mandrill/Api/Ips.php index df2a4e8..9d89aad --- a/src/Mandrill/Api/Ips.php +++ b/src/Jlinn/Mandrill/Api/Ips.php @@ -5,10 +5,9 @@ * Time: 5:04 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Ips diff --git a/src/Mandrill/Api/Messages.php b/src/Jlinn/Mandrill/Api/Messages.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Messages.php rename to src/Jlinn/Mandrill/Api/Messages.php index bcfb74d..38c963e --- a/src/Mandrill/Api/Messages.php +++ b/src/Jlinn/Mandrill/Api/Messages.php @@ -5,11 +5,11 @@ * Time: 11:55 AM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; use Guzzle\Http\Client; -use Mandrill\Api; -use Mandrill\Struct\Message; +use Jlinn\Mandrill\Api; +use Jlinn\Mandrill\Struct\Message; /** * Class Messages diff --git a/src/Mandrill/Api/Rejects.php b/src/Jlinn/Mandrill/Api/Rejects.php old mode 100755 new mode 100644 similarity index 97% rename from src/Mandrill/Api/Rejects.php rename to src/Jlinn/Mandrill/Api/Rejects.php index 174dfa6..24b47e7 --- a/src/Mandrill/Api/Rejects.php +++ b/src/Jlinn/Mandrill/Api/Rejects.php @@ -5,10 +5,9 @@ * Time: 3:37 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Rejects diff --git a/src/Mandrill/Api/Senders.php b/src/Jlinn/Mandrill/Api/Senders.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Senders.php rename to src/Jlinn/Mandrill/Api/Senders.php index 8725c62..c7a624f --- a/src/Mandrill/Api/Senders.php +++ b/src/Jlinn/Mandrill/Api/Senders.php @@ -5,10 +5,9 @@ * Time: 3:49 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Senders diff --git a/src/Mandrill/Api/Subaccounts.php b/src/Jlinn/Mandrill/Api/Subaccounts.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Subaccounts.php rename to src/Jlinn/Mandrill/Api/Subaccounts.php index 9663a29..f3e4d00 --- a/src/Mandrill/Api/Subaccounts.php +++ b/src/Jlinn/Mandrill/Api/Subaccounts.php @@ -5,10 +5,9 @@ * Time: 4:41 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Subaccounts diff --git a/src/Mandrill/Api/Tags.php b/src/Jlinn/Mandrill/Api/Tags.php old mode 100755 new mode 100644 similarity index 97% rename from src/Mandrill/Api/Tags.php rename to src/Jlinn/Mandrill/Api/Tags.php index 080826d..80399d3 --- a/src/Mandrill/Api/Tags.php +++ b/src/Jlinn/Mandrill/Api/Tags.php @@ -5,10 +5,9 @@ * Time: 3:25 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Tags diff --git a/src/Mandrill/Api/Templates.php b/src/Jlinn/Mandrill/Api/Templates.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Templates.php rename to src/Jlinn/Mandrill/Api/Templates.php index af47882..7f6ebcc --- a/src/Mandrill/Api/Templates.php +++ b/src/Jlinn/Mandrill/Api/Templates.php @@ -5,10 +5,9 @@ * Time: 4:07 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Templates diff --git a/src/Mandrill/Api/Urls.php b/src/Jlinn/Mandrill/Api/Urls.php old mode 100755 new mode 100644 similarity index 95% rename from src/Mandrill/Api/Urls.php rename to src/Jlinn/Mandrill/Api/Urls.php index a83356a..4c07ec4 --- a/src/Mandrill/Api/Urls.php +++ b/src/Jlinn/Mandrill/Api/Urls.php @@ -5,10 +5,9 @@ * Time: 3:56 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Urls diff --git a/src/Mandrill/Api/Users.php b/src/Jlinn/Mandrill/Api/Users.php old mode 100755 new mode 100644 similarity index 94% rename from src/Mandrill/Api/Users.php rename to src/Jlinn/Mandrill/Api/Users.php index 0be1157..0ecaa0a --- a/src/Mandrill/Api/Users.php +++ b/src/Jlinn/Mandrill/Api/Users.php @@ -5,11 +5,10 @@ * Time: 5:05 PM */ -namespace Mandrill\Api; - +namespace Jlinn\Mandrill\Api; use Guzzle\Http\Client; -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Users diff --git a/src/Mandrill/Api/Webhooks.php b/src/Jlinn/Mandrill/Api/Webhooks.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Api/Webhooks.php rename to src/Jlinn/Mandrill/Api/Webhooks.php index 884ef48..cd60e34 --- a/src/Mandrill/Api/Webhooks.php +++ b/src/Jlinn/Mandrill/Api/Webhooks.php @@ -5,10 +5,9 @@ * Time: 4:31 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Webhooks diff --git a/src/Mandrill/Api/Whitelists.php b/src/Jlinn/Mandrill/Api/Whitelists.php old mode 100755 new mode 100644 similarity index 96% rename from src/Mandrill/Api/Whitelists.php rename to src/Jlinn/Mandrill/Api/Whitelists.php index a13d4f5..50c8474 --- a/src/Mandrill/Api/Whitelists.php +++ b/src/Jlinn/Mandrill/Api/Whitelists.php @@ -5,10 +5,9 @@ * Time: 3:43 PM */ -namespace Mandrill\Api; +namespace Jlinn\Mandrill\Api; - -use Mandrill\Api; +use Jlinn\Mandrill\Api; /** * Class Whitelists diff --git a/src/Mandrill/Exception.php b/src/Jlinn/Mandrill/Exception.php old mode 100755 new mode 100644 similarity index 80% rename from src/Mandrill/Exception.php rename to src/Jlinn/Mandrill/Exception.php index 91cc135..a7721a9 --- a/src/Mandrill/Exception.php +++ b/src/Jlinn/Mandrill/Exception.php @@ -5,8 +5,7 @@ * Time: 12:23 PM */ -namespace Mandrill; - +namespace Jlinn\Mandrill; class Exception extends \Exception{ diff --git a/src/Mandrill/Exception/APIException.php b/src/Jlinn/Mandrill/Exception/APIException.php old mode 100755 new mode 100644 similarity index 95% rename from src/Mandrill/Exception/APIException.php rename to src/Jlinn/Mandrill/Exception/APIException.php index f0ddd54..6c364e5 --- a/src/Mandrill/Exception/APIException.php +++ b/src/Jlinn/Mandrill/Exception/APIException.php @@ -5,8 +5,7 @@ * Time: 12:24 PM */ -namespace Mandrill\Exception; - +namespace Jlinn\Mandrill\Exception; use Mandrill\Exception; diff --git a/src/Jlinn/Mandrill/Facades/Mandrill.php b/src/Jlinn/Mandrill/Facades/Mandrill.php new file mode 100644 index 0000000..b24701f --- /dev/null +++ b/src/Jlinn/Mandrill/Facades/Mandrill.php @@ -0,0 +1,10 @@ +apiKey = $apiKey; + } + + public function api() + { + return new Mandrill($this->apiKey); + } + + public function message(Array $args = []) + { + if (empty($args)) { + return new Message; + } + + $message = new Message; + foreach ($args as $key => $value) { + $message->$key = $value; + } + + return $message; + } + + public function attachment(Array $args = []) + { + if (empty($args)) { + return new Attachment; + } + + $attachment = new Attachment; + foreach ($args as $key => $value) { + $attachment->$key = $value; + } + + return $attachment; + } + + public function recipient($email = NULL, $name = NULL, $type = NULL) + { + return new Recipient($email, $name, $type); + } +} \ No newline at end of file diff --git a/src/Jlinn/Mandrill/MandrillServiceProvider.php b/src/Jlinn/Mandrill/MandrillServiceProvider.php new file mode 100644 index 0000000..de41d95 --- /dev/null +++ b/src/Jlinn/Mandrill/MandrillServiceProvider.php @@ -0,0 +1,29 @@ +package('jlinn/mandrill-api-php'); + } + + public function register() + { + $this->app->bind('mandrill', function () + { + $config = $this->app->config->get('mandrill-api-php::config'); + return new MandrillFactory($config['secret']); + }); + } + + public function provides() + { + return ['mandrill']; + } +} \ No newline at end of file diff --git a/src/Mandrill/Struct.php b/src/Jlinn/Mandrill/Struct.php old mode 100755 new mode 100644 similarity index 98% rename from src/Mandrill/Struct.php rename to src/Jlinn/Mandrill/Struct.php index 1d4c64d..e83f137 --- a/src/Mandrill/Struct.php +++ b/src/Jlinn/Mandrill/Struct.php @@ -5,8 +5,7 @@ * Time: 4:19 PM */ -namespace Mandrill; - +namespace Jlinn\Mandrill; abstract class Struct implements \IteratorAggregate{ /** diff --git a/src/Mandrill/Struct/Attachment.php b/src/Jlinn/Mandrill/Struct/Attachment.php old mode 100755 new mode 100644 similarity index 86% rename from src/Mandrill/Struct/Attachment.php rename to src/Jlinn/Mandrill/Struct/Attachment.php index 188066a..9124872 --- a/src/Mandrill/Struct/Attachment.php +++ b/src/Jlinn/Mandrill/Struct/Attachment.php @@ -5,9 +5,9 @@ * Time: 11:48 AM */ -namespace Mandrill\Struct; +namespace Jlinn\Mandrill\Struct; -use Mandrill\Struct; +use Jlinn\Mandrill\Struct; class Attachment extends Struct{ /** diff --git a/src/Mandrill/Struct/Message.php b/src/Jlinn/Mandrill/Struct/Message.php old mode 100755 new mode 100644 similarity index 99% rename from src/Mandrill/Struct/Message.php rename to src/Jlinn/Mandrill/Struct/Message.php index a90008e..ff30a6e --- a/src/Mandrill/Struct/Message.php +++ b/src/Jlinn/Mandrill/Struct/Message.php @@ -5,9 +5,9 @@ * Time: 10:49 AM */ -namespace Mandrill\Struct; +namespace Jlinn\Mandrill\Struct; -use Mandrill\Struct; +use Jlinn\Mandrill\Struct; class Message extends Struct{ /** diff --git a/src/Mandrill/Struct/Recipient.php b/src/Jlinn/Mandrill/Struct/Recipient.php old mode 100755 new mode 100644 similarity index 97% rename from src/Mandrill/Struct/Recipient.php rename to src/Jlinn/Mandrill/Struct/Recipient.php index 52c09eb..a6da44a --- a/src/Mandrill/Struct/Recipient.php +++ b/src/Jlinn/Mandrill/Struct/Recipient.php @@ -5,9 +5,9 @@ * Time: 11:24 AM */ -namespace Mandrill\Struct; +namespace Jlinn\Mandrill\Struct; -use Mandrill\Struct; +use Jlinn\Mandrill\Struct; class Recipient extends Struct{ /** diff --git a/src/config/config.php b/src/config/config.php new file mode 100644 index 0000000..04ab758 --- /dev/null +++ b/src/config/config.php @@ -0,0 +1,15 @@ + 'changeme' + +); \ No newline at end of file From be604ca675afc9bf0bbac029af7ed29afdf543aa Mon Sep 17 00:00:00 2001 From: Giampaolo Falqui Date: Mon, 26 Oct 2015 14:53:13 +0100 Subject: [PATCH 2/4] Fixes phpunit tests --- tests/Mandrill/Tests/Api/MessagesTest.php | 11 +++++------ tests/Mandrill/Tests/Api/UsersTest.php | 4 ++-- tests/Mandrill/Tests/MandrillTestCase.php | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/Mandrill/Tests/Api/MessagesTest.php b/tests/Mandrill/Tests/Api/MessagesTest.php index 64e551c..3c2f19a 100755 --- a/tests/Mandrill/Tests/Api/MessagesTest.php +++ b/tests/Mandrill/Tests/Api/MessagesTest.php @@ -5,13 +5,12 @@ * Time: 12:07 PM */ -namespace Mandrill\Tests\Api; +namespace Jlinn\Mandrill\Tests\Api; - -use Mandrill\Api\Messages; -use Mandrill\Struct\Message; -use Mandrill\Struct\Recipient; -use Mandrill\Tests\MandrillTestCase; +use Jlinn\Mandrill\Api\Messages; +use Jlinn\Mandrill\Struct\Message; +use Jlinn\Mandrill\Struct\Recipient; +use Jlinn\Mandrill\Tests\MandrillTestCase; class MessagesTest extends MandrillTestCase{ /** diff --git a/tests/Mandrill/Tests/Api/UsersTest.php b/tests/Mandrill/Tests/Api/UsersTest.php index 063471f..25607a8 100755 --- a/tests/Mandrill/Tests/Api/UsersTest.php +++ b/tests/Mandrill/Tests/Api/UsersTest.php @@ -5,9 +5,9 @@ * Time: 5:20 PM */ -namespace Mandrill\Tests\Api; +namespace Jlinn\Mandrill\Tests\Api; -use Mandrill\Tests\MandrillTestCase; +use Jlinn\Mandrill\Tests\MandrillTestCase; class UsersTest extends MandrillTestCase { /** diff --git a/tests/Mandrill/Tests/MandrillTestCase.php b/tests/Mandrill/Tests/MandrillTestCase.php index 98ee4a4..392263d 100755 --- a/tests/Mandrill/Tests/MandrillTestCase.php +++ b/tests/Mandrill/Tests/MandrillTestCase.php @@ -5,12 +5,12 @@ * Time: 5:12 PM */ -namespace Mandrill\Tests; +namespace Jlinn\Mandrill\Tests; use Guzzle\Http\Message\Response; use Guzzle\Plugin\Mock\MockPlugin; use Guzzle\Tests\GuzzleTestCase; -use Mandrill\Mandrill; +use Jlinn\Mandrill\Mandrill; class MandrillTestCase extends GuzzleTestCase{ /** From 3760fc9569501a696f4e34351d926aa5e1071b7a Mon Sep 17 00:00:00 2001 From: Giampaolo Falqui Date: Mon, 26 Oct 2015 16:06:12 +0100 Subject: [PATCH 3/4] Allows override of the MandrillFactory class --- src/Jlinn/Mandrill/MandrillServiceProvider.php | 12 +++++------- src/config/config.php | 12 +++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Jlinn/Mandrill/MandrillServiceProvider.php b/src/Jlinn/Mandrill/MandrillServiceProvider.php index de41d95..47e9182 100644 --- a/src/Jlinn/Mandrill/MandrillServiceProvider.php +++ b/src/Jlinn/Mandrill/MandrillServiceProvider.php @@ -8,17 +8,15 @@ class MandrillServiceProvider extends ServiceProvider { protected $defer = false; - public function boot() + public function register() { $this->package('jlinn/mandrill-api-php'); - } - public function register() - { - $this->app->bind('mandrill', function () + $this->app['mandrill'] = $this->app->share(function ($app) { - $config = $this->app->config->get('mandrill-api-php::config'); - return new MandrillFactory($config['secret']); + $config = $app->config->get('mandrill-api-php::config'); + $factory = "\\{$config['factory']}"; + return new $factory($config['secret']); }); } diff --git a/src/config/config.php b/src/config/config.php index 04ab758..21942b0 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -10,6 +10,16 @@ | Change 'changeme' with your Mandrill Secret Key. | */ - 'secret' => 'changeme' + 'secret' => 'changeme', + + /* + |-------------------------------------------------------------------------- + | Custom Factory Class + |-------------------------------------------------------------------------- + | + | If you wish to have a custom factory class to enhance the functionality of the library, feel free to override it. + | + */ + 'factory' => 'Jlinn\Mandrill\MandrillFactory' ); \ No newline at end of file From 3d117adbae8aaa88a5656d73d807d7bcbd85f5aa Mon Sep 17 00:00:00 2001 From: Giampaolo Falqui Date: Mon, 26 Oct 2015 17:25:27 +0100 Subject: [PATCH 4/4] Fixes namespace --- src/Jlinn/Mandrill/Api.php | 2 +- src/Jlinn/Mandrill/Exception.php | 2 +- src/Jlinn/Mandrill/Exception/APIException.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Jlinn/Mandrill/Api.php b/src/Jlinn/Mandrill/Api.php index 692a69a..7d74d4d 100644 --- a/src/Jlinn/Mandrill/Api.php +++ b/src/Jlinn/Mandrill/Api.php @@ -9,7 +9,7 @@ use Guzzle\Http\Client; use Guzzle\Http\Exception\ServerErrorResponseException; -use Mandrill\Exception\APIException; +use Jlinn\Mandrill\Exception\APIException; abstract class Api{ const BASE_URL = 'https://mandrillapp.com/api/1.0/'; diff --git a/src/Jlinn/Mandrill/Exception.php b/src/Jlinn/Mandrill/Exception.php index a7721a9..c56de5c 100644 --- a/src/Jlinn/Mandrill/Exception.php +++ b/src/Jlinn/Mandrill/Exception.php @@ -7,6 +7,6 @@ namespace Jlinn\Mandrill; -class Exception extends \Exception{ +class Exception extends \Exception { } \ No newline at end of file diff --git a/src/Jlinn/Mandrill/Exception/APIException.php b/src/Jlinn/Mandrill/Exception/APIException.php index 6c364e5..db165a4 100644 --- a/src/Jlinn/Mandrill/Exception/APIException.php +++ b/src/Jlinn/Mandrill/Exception/APIException.php @@ -7,7 +7,7 @@ namespace Jlinn\Mandrill\Exception; -use Mandrill\Exception; +use Jlinn\Mandrill\Exception; class APIException extends Exception{ /**