Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 3311e16

Browse files
committed
Merge branch 'hotfix/abstract-plugin-manager'
Close #72
2 parents 89a5a6c + f6064e0 commit 3311e16

File tree

6 files changed

+133
-23
lines changed

6 files changed

+133
-23
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,33 @@ cache:
1111
directories:
1212
- $HOME/.composer/cache
1313

14+
env:
15+
global:
16+
- SERVICE_MANAGER_VERSION="^3.0.3"
17+
1418
matrix:
1519
fast_finish: true
1620
include:
1721
- php: 5.5
1822
env:
1923
- EXECUTE_CS_CHECK=true
24+
- php: 5.5
25+
env:
26+
- SERVICE_MANAGER_VERSION="^2.7.5"
2027
- php: 5.6
2128
env:
2229
- EXECUTE_TEST_COVERALLS=true
30+
- php: 5.6
31+
env:
32+
- SERVICE_MANAGER_VERSION="^2.7.5"
2333
- php: 7
34+
- php: 7
35+
env:
36+
- SERVICE_MANAGER_VERSION="^2.7.5"
2437
- php: hhvm
38+
- php: hhvm
39+
env:
40+
- SERVICE_MANAGER_VERSION="^2.7.5"
2541
allow_failures:
2642
- php: hhvm
2743

@@ -33,6 +49,7 @@ before_install:
3349
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
3450
- composer self-update
3551
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
52+
- composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION"
3653

3754
install:
3855
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.6.1 - TBD
5+
## 2.6.1 - 2016-02-24
66

77
### Added
88

@@ -18,7 +18,11 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#72](https://github.com/zendframework/zend-mail/pull/72) re-implements
22+
`SmtpPluginManager` as a zend-servicemanager `AbstractPluginManager`, after
23+
reports that making it standalone broke important extensibility use cases
24+
(specifically, replacing existing plugins and/or providing additional plugins
25+
could only be managed with significant code changes).
2226

2327
## 2.6.0 - 2016-02-18
2428

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
},
2323
"require-dev": {
2424
"zendframework/zend-config": "^2.6",
25+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
2526
"fabpot/php-cs-fixer": "1.7.*",
2627
"phpunit/PHPUnit": "~4.0"
2728
},
29+
"suggest": {
30+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3 when using SMTP to deliver messages"
31+
},
2832
"minimum-stability": "dev",
2933
"prefer-stable": true,
3034
"extra": {

src/Protocol/SmtpPluginManager.php

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,95 @@
99

1010
namespace Zend\Mail\Protocol;
1111

12-
use Interop\Container\ContainerInterface;
12+
use Zend\ServiceManager\AbstractPluginManager;
13+
use Zend\ServiceManager\Factory\InvokableFactory;
14+
use Zend\ServiceManager\Exception\InvalidServiceException;
1315

1416
/**
1517
* Plugin manager implementation for SMTP extensions.
1618
*
1719
* Enforces that SMTP extensions retrieved are instances of Smtp. Additionally,
1820
* it registers a number of default extensions available.
1921
*/
20-
class SmtpPluginManager implements ContainerInterface
22+
class SmtpPluginManager extends AbstractPluginManager
2123
{
2224
/**
23-
* Default set of plugins
25+
* Service aliases
26+
*/
27+
protected $aliases = [
28+
'crammd5' => Smtp\Auth\Crammd5::class,
29+
'cramMd5' => Smtp\Auth\Crammd5::class,
30+
'CramMd5' => Smtp\Auth\Crammd5::class,
31+
'cramMD5' => Smtp\Auth\Crammd5::class,
32+
'CramMD5' => Smtp\Auth\Crammd5::class,
33+
'login' => Smtp\Auth\Login::class,
34+
'Login' => Smtp\Auth\Login::class,
35+
'plain' => Smtp\Auth\Plain::class,
36+
'Plain' => Smtp\Auth\Plain::class,
37+
'smtp' => Smtp::class,
38+
'Smtp' => Smtp::class,
39+
'SMTP' => Smtp::class,
40+
];
41+
42+
/**
43+
* Service factories
2444
*
2545
* @var array
2646
*/
27-
protected $plugins = [
28-
'crammd5' => 'Zend\Mail\Protocol\Smtp\Auth\Crammd5',
29-
'login' => 'Zend\Mail\Protocol\Smtp\Auth\Login',
30-
'plain' => 'Zend\Mail\Protocol\Smtp\Auth\Plain',
31-
'smtp' => 'Zend\Mail\Protocol\Smtp',
47+
protected $factories = [
48+
Smtp\Auth\Crammd5::class => InvokableFactory::class,
49+
Smtp\Auth\Login::class => InvokableFactory::class,
50+
Smtp\Auth\Plain::class => InvokableFactory::class,
51+
Smtp::class => InvokableFactory::class,
52+
53+
// v2 normalized service names
54+
55+
'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class,
56+
'zendmailprotocolsmtpauthlogin' => InvokableFactory::class,
57+
'zendmailprotocolsmtpauthplain' => InvokableFactory::class,
58+
'zendmailprotocolsmtp' => InvokableFactory::class,
3259
];
3360

3461
/**
35-
* Do we have the plugin?
62+
* Plugins must be an instance of the Smtp class
3663
*
37-
* @param string $id
38-
* @return bool
64+
* @var string
3965
*/
40-
public function has($id)
66+
protected $instanceOf = Smtp::class;
67+
68+
/**
69+
* Validate a retrieved plugin instance (v3).
70+
*
71+
* @param object $plugin
72+
* @throws InvalidServiceException
73+
*/
74+
public function validate($plugin)
4175
{
42-
return array_key_exists($id, $this->plugins);
76+
if (! $plugin instanceof $this->instanceOf) {
77+
throw new InvalidServiceException(sprintf(
78+
'Plugin of type %s is invalid; must extend %s',
79+
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
80+
Smtp::class
81+
));
82+
}
4383
}
84+
4485
/**
45-
* Retrieve the smtp plugin
86+
* Validate a retrieved plugin instance (v2).
4687
*
47-
* @param string $id
48-
* @param array $options
49-
* @return AbstractProtocol
88+
* @param object $plugin
89+
* @throws Exception\InvalidArgumentException
5090
*/
51-
public function get($id, array $options = null)
91+
public function validatePlugin($plugin)
5292
{
53-
$class = $this->plugins[$id];
54-
return new $class($options);
93+
try {
94+
$this->validate($plugin);
95+
} catch (InvalidServiceException $e) {
96+
throw new Exception\InvalidArgumentException(
97+
$e->getMessage(),
98+
$e->getCode(),
99+
$e
100+
);
101+
}
55102
}
56103
}

src/Transport/Smtp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Zend\Mail\Message;
1515
use Zend\Mail\Protocol;
1616
use Zend\Mail\Protocol\Exception as ProtocolException;
17+
use Zend\ServiceManager\ServiceManager;
1718

1819
/**
1920
* SMTP connection object
@@ -123,7 +124,7 @@ public function setPluginManager(Protocol\SmtpPluginManager $plugins)
123124
public function getPluginManager()
124125
{
125126
if (null === $this->plugins) {
126-
$this->setPluginManager(new Protocol\SmtpPluginManager());
127+
$this->setPluginManager(new Protocol\SmtpPluginManager(new ServiceManager()));
127128
}
128129
return $this->plugins;
129130
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zend-mail for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Mail\Protocol;
11+
12+
use PHPUnit_Framework_TestCase as TestCase;
13+
use Zend\Mail\Protocol\Smtp;
14+
use Zend\Mail\Protocol\SmtpPluginManager;
15+
use Zend\Mail\Protocol\Exception\InvalidArgumentException;
16+
use Zend\ServiceManager\ServiceManager;
17+
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
18+
19+
class SmtpPluginManagerCompatibilityTest extends TestCase
20+
{
21+
use CommonPluginManagerTrait;
22+
23+
protected function getPluginManager()
24+
{
25+
return new SmtpPluginManager(new ServiceManager());
26+
}
27+
28+
protected function getV2InvalidPluginException()
29+
{
30+
return InvalidArgumentException::class;
31+
}
32+
33+
protected function getInstanceOf()
34+
{
35+
return Smtp::class;
36+
}
37+
}

0 commit comments

Comments
 (0)