-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from GiampaoloFalqui/psr-4-laravel-4.2
PSR-0 => PSR-4, adds Laravel 4.2 implementation
- Loading branch information
Showing
30 changed files
with
222 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
``` | ||
``` | ||
|
||
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' => '[email protected]', | ||
'from_name' => 'Mandrill API Test' | ||
]); | ||
|
||
$recipient = Mandrill::recipient('[email protected]', 'Recipient Name'); | ||
$recipient->addMergeVar('NAME', $recipient->name); | ||
$message->addRecipient($recipient); | ||
|
||
$response = $api->messages()->send($message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Jlinn\Mandrill\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Mandrill extends Facade | ||
{ | ||
protected static function getFacadeAccessor() { return 'mandrill'; } | ||
} |
4 changes: 2 additions & 2 deletions
4
src/Mandrill/Mandrill.php → src/Jlinn/Mandrill/Mandrill.php
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Jlinn\Mandrill; | ||
|
||
use Jlinn\Mandrill\Mandrill; | ||
|
||
use Jlinn\Mandrill\Struct\Message; | ||
use Jlinn\Mandrill\Struct\Recipient; | ||
use Jlinn\Mandrill\Struct\Attachment; | ||
|
||
class MandrillFactory | ||
{ | ||
private $apiKey; | ||
|
||
public function __construct($apiKey) | ||
{ | ||
$this->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); | ||
} | ||
} |
Oops, something went wrong.