From 4f78fb95109b8f3a8209bbef1874e8201cbb6637 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 17:15:49 +0300 Subject: [PATCH 01/12] Update HttpClientFactory.php Update to manage HttpClient Options --- src/SlmMail/Factory/HttpClientFactory.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/SlmMail/Factory/HttpClientFactory.php b/src/SlmMail/Factory/HttpClientFactory.php index 60e9a84..0b45d54 100644 --- a/src/SlmMail/Factory/HttpClientFactory.php +++ b/src/SlmMail/Factory/HttpClientFactory.php @@ -53,15 +53,11 @@ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); - if (!isset($config['slm_mail']['http_adapter']) - || !isset($config['slm_mail']['http_options']) - ) { - return new HttpClient(); - } - $client = new HttpClient(); $client->setAdapter($config['slm_mail']['http_adapter']); - $client->getAdapter()->setOptions($config['slm_mail']['http_options']); + if (isset($config['slm_mail']['http_options']) { + $client->getAdapter()->setOptions($config['slm_mail']['http_options']); + } return $client; } From e1245a2913f1ece6ff4951eb7564a0a01c87ea00 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 17:18:30 +0300 Subject: [PATCH 02/12] Update module.config.php --- config/module.config.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/module.config.php b/config/module.config.php index b5a1104..10b846f 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -71,4 +71,7 @@ 'SlmMail\Http\Client' => 'SlmMail\Factory\HttpClientFactory', ), ), + 'slm_mail' => array( + 'http_adapter' => 'Zend\Http\Client\Adapter\Socket', + ), ); From 02383f21d2c304f443870542ef8c69371de4c7d9 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 17:20:20 +0300 Subject: [PATCH 03/12] Update HttpClientFactory.php --- src/SlmMail/Factory/HttpClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SlmMail/Factory/HttpClientFactory.php b/src/SlmMail/Factory/HttpClientFactory.php index 0b45d54..9ef395a 100644 --- a/src/SlmMail/Factory/HttpClientFactory.php +++ b/src/SlmMail/Factory/HttpClientFactory.php @@ -55,7 +55,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $client = new HttpClient(); $client->setAdapter($config['slm_mail']['http_adapter']); - if (isset($config['slm_mail']['http_options']) { + if (isset($config['slm_mail']['http_options'])) { $client->getAdapter()->setOptions($config['slm_mail']['http_options']); } From ec9330b085c8d5de7e0c6f19ad231a8bc57bb836 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 16:33:48 +0200 Subject: [PATCH 04/12] Update module.config.php --- config/module.config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/module.config.php b/config/module.config.php index 10b846f..2e06b4a 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -71,6 +71,7 @@ 'SlmMail\Http\Client' => 'SlmMail\Factory\HttpClientFactory', ), ), + 'slm_mail' => array( 'http_adapter' => 'Zend\Http\Client\Adapter\Socket', ), From 2a46859c51f6935a64a56b99b8d643a27923ec54 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 17:36:10 +0300 Subject: [PATCH 05/12] Update HttpClientFactory.php --- src/SlmMail/Factory/HttpClientFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SlmMail/Factory/HttpClientFactory.php b/src/SlmMail/Factory/HttpClientFactory.php index 9ef395a..b982fdc 100644 --- a/src/SlmMail/Factory/HttpClientFactory.php +++ b/src/SlmMail/Factory/HttpClientFactory.php @@ -55,6 +55,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $client = new HttpClient(); $client->setAdapter($config['slm_mail']['http_adapter']); + if (isset($config['slm_mail']['http_options'])) { $client->getAdapter()->setOptions($config['slm_mail']['http_options']); } From 384d42f369cef615f6e5804bbcbddd76a433dbac Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 18:04:55 +0300 Subject: [PATCH 06/12] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index f681f24..0d01013 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,40 @@ $message->setBody($body); > For accessibility purposes, you should *always* provide both a text and HTML version of your mails. +### How to configure HttpClient with http_options and http_adapter + +By defaut the adapter is Zend\Http\Client\Adapter\Socket but you can override it with other adapter like this in your slm_mail.*.local.php + +```php +'slm_mail' => array( + 'mandrill' => array( + /** + * Set your Mandrill API key + */ + 'key' => 'yourkey' + ), + 'http_adapter' => 'Zend\Http\Client\Adapter\Proxy' // for example + ) +``` + +If you want to change some options of your adapter please refer to you adapter class in var $config [here](https://github.com/zendframework/zf2/tree/master/library/Zend/Http/Client/Adapter) and override these in your slm_mail.*.local.php like this : + +```php +'slm_mail' => array( + 'mandrill' => array( + /** + * Set your Mandrill API key + */ + 'key' => 'yourkey' + ), + // example for Socket adapter + 'http_options' => array( + 'sslverifypeer' => false, + 'persistent' => true, + ), + ) +``` + ### Pricing comparison Here is a table of prices for each service providers (if they are outdated please create an issue). Of course, you From 6e33ea6a24b91f9bd3a273b8dedbdf963f812423 Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Mon, 13 May 2013 17:52:01 +0200 Subject: [PATCH 07/12] Update README.md --- README.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0d01013..fac35c0 100644 --- a/README.md +++ b/README.md @@ -100,12 +100,8 @@ By defaut the adapter is Zend\Http\Client\Adapter\Socket but you can override it ```php 'slm_mail' => array( - 'mandrill' => array( - /** - * Set your Mandrill API key - */ - 'key' => 'yourkey' - ), + // Here your email service provider options + 'http_adapter' => 'Zend\Http\Client\Adapter\Proxy' // for example ) ``` @@ -114,12 +110,8 @@ If you want to change some options of your adapter please refer to you adapter c ```php 'slm_mail' => array( - 'mandrill' => array( - /** - * Set your Mandrill API key - */ - 'key' => 'yourkey' - ), + // Here your email service provider options + // example for Socket adapter 'http_options' => array( 'sslverifypeer' => false, From 49f64127c246634ef8df7f32e1d03f7a0102a757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 18 May 2013 12:44:16 +0200 Subject: [PATCH 08/12] Add metadata option --- src/SlmMail/Mail/Message/Mandrill.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/SlmMail/Mail/Message/Mandrill.php b/src/SlmMail/Mail/Message/Mandrill.php index 77d1432..7113e98 100644 --- a/src/SlmMail/Mail/Message/Mandrill.php +++ b/src/SlmMail/Mail/Message/Mandrill.php @@ -59,19 +59,20 @@ class Mandrill extends Message * @var array */ protected $validOptions = array( - 'important', - 'track_opens', - 'track_clicks', - 'auto_text', 'auto_html', + 'auto_text', + 'google_analytics_campaign', + 'google_analytics_domains', + 'important', 'inline_css', - 'url_strip_qs', + 'merge', + 'metadata', 'preserve_recipients', - 'tracking_domain', 'signing_domain', - 'merge', - 'google_analytics_domains', - 'google_analytics_campaign' + 'track_clicks', + 'track_opens', + 'tracking_domain', + 'url_strip_qs' ); /** From 3e2221382c8055dc128afcdbc97dfe73d9c7e42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 18 May 2013 13:31:54 +0200 Subject: [PATCH 09/12] Add tests for Http --- CHANGELOG.md | 5 ++ src/SlmMail/Factory/HttpClientFactory.php | 2 +- tests/SlmMailTest/Http/ClientTest.php | 87 +++++++++++++++++++++++ tests/TestConfiguration.php.dist | 2 +- 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 tests/SlmMailTest/Http/ClientTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 30b080e..3a1b0fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 1.0.0 RC3 + +- Now allow the new "metadata" option in Mandrill message +- Http adapter can now be configured more easily + ## 1.0.0 RC2 - Licensing of `composer.json` and all files inside SlmMail - Addition of a CHANGELOG document diff --git a/src/SlmMail/Factory/HttpClientFactory.php b/src/SlmMail/Factory/HttpClientFactory.php index b982fdc..c410766 100644 --- a/src/SlmMail/Factory/HttpClientFactory.php +++ b/src/SlmMail/Factory/HttpClientFactory.php @@ -55,7 +55,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $client = new HttpClient(); $client->setAdapter($config['slm_mail']['http_adapter']); - + if (isset($config['slm_mail']['http_options'])) { $client->getAdapter()->setOptions($config['slm_mail']['http_options']); } diff --git a/tests/SlmMailTest/Http/ClientTest.php b/tests/SlmMailTest/Http/ClientTest.php new file mode 100644 index 0000000..1ed2cb4 --- /dev/null +++ b/tests/SlmMailTest/Http/ClientTest.php @@ -0,0 +1,87 @@ + + * @copyright 2012-2013 Jurian Sluiman. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @link http://juriansluiman.nl + */ + +namespace SlmMailTest\Http; + +use PHPUnit_Framework_TestCase; +use SlmMailTest\Util\ServiceManagerFactory; + +class ClientTest extends PHPUnit_Framework_TestCase +{ + public function testAssertSocketAdapterIsUsedByDefault() + { + /** @var \Zend\Http\Client $client */ + $client = ServiceManagerFactory::getServiceManager()->get('SlmMail\Http\Client'); + $this->assertInstanceOf('Zend\Http\Client\Adapter\Socket', $client->getAdapter()); + } + + public function testAssertCanChangeAdapter() + { + $serviceManager = ServiceManagerFactory::getServiceManager(); + $serviceManager->setAllowOverride(true); + + $config = $serviceManager->get('Config'); + $config['slm_mail']['http_adapter'] = 'Zend\Http\Client\Adapter\Test'; + + $serviceManager->setService('Config', $config); + + /** @var \Zend\Http\Client $client */ + $client = $serviceManager->get('SlmMail\Http\Client'); + $this->assertInstanceOf('Zend\Http\Client\Adapter\Test', $client->getAdapter()); + } + + public function testCanSetOptionsForHttpAdapter() + { + $serviceManager = ServiceManagerFactory::getServiceManager(); + $serviceManager->setAllowOverride(true); + + $config = $serviceManager->get('Config'); + $config['slm_mail']['http_options'] = array( + 'sslverifypeer' => false + ); + + $serviceManager->setService('Config', $config); + + /** @var \Zend\Http\Client $client */ + $client = $serviceManager->get('SlmMail\Http\Client'); + $config = $client->getAdapter()->getConfig(); + $this->assertFalse($config['sslverifypeer']); + } +} diff --git a/tests/TestConfiguration.php.dist b/tests/TestConfiguration.php.dist index 2b5b43f..70ee1a8 100644 --- a/tests/TestConfiguration.php.dist +++ b/tests/TestConfiguration.php.dist @@ -18,7 +18,7 @@ */ return array( 'modules' => array( - 'Aws', + //'Aws', 'SlmMail', ), 'module_listener_options' => array( From 187184ab9ecc34abbd6ba46678597d8a7837f039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 18 May 2013 13:34:35 +0200 Subject: [PATCH 10/12] Reactivate Aws --- tests/TestConfiguration.php.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestConfiguration.php.dist b/tests/TestConfiguration.php.dist index 70ee1a8..2b5b43f 100644 --- a/tests/TestConfiguration.php.dist +++ b/tests/TestConfiguration.php.dist @@ -18,7 +18,7 @@ */ return array( 'modules' => array( - //'Aws', + 'Aws', 'SlmMail', ), 'module_listener_options' => array( From 6720710b800ad6c8602ff5310d424f473fa31d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 18 May 2013 13:47:37 +0200 Subject: [PATCH 11/12] Add note about RC --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fac35c0..98a001f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SlmMail ======= -Version 1.0.0 Created by Jurian Sluiman and Michaël Gallego +Version 1.0.0-rc3 Created by Jurian Sluiman and Michaël Gallego Introduction ------------ @@ -38,12 +38,15 @@ file called `composer.json` and save it in the root of your project: ``` { + "minimum-stability": "rc", "require": { "slm/mail": ">=1.*" } } ``` +> minimum-stability attribute is required as we have not reached final version yet. + Then execute the following commands in a CLI: ``` @@ -101,7 +104,7 @@ By defaut the adapter is Zend\Http\Client\Adapter\Socket but you can override it ```php 'slm_mail' => array( // Here your email service provider options - + 'http_adapter' => 'Zend\Http\Client\Adapter\Proxy' // for example ) ``` @@ -111,7 +114,7 @@ If you want to change some options of your adapter please refer to you adapter c ```php 'slm_mail' => array( // Here your email service provider options - + // example for Socket adapter 'http_options' => array( 'sslverifypeer' => false, From 3e69d55c8b93005b6f8ab41102f31c9410b54e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Mon, 20 May 2013 15:07:04 +0300 Subject: [PATCH 12/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98a001f..b11f7e7 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ file called `composer.json` and save it in the root of your project: { "minimum-stability": "rc", "require": { - "slm/mail": ">=1.*" + "slm/mail": "1.*" } } ```