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

Commit 398bc5a

Browse files
committed
Revert "Re-implement SmtpPluginManager as an AbstractPluginManager"
This reverts commit 67641e6.
1 parent deeb3e2 commit 398bc5a

8 files changed

+23
-299
lines changed

composer.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
"phpunit/phpunit": "^5.7.25 || ^6.4.4 || ^7.1.4",
2929
"zendframework/zend-coding-standard": "~1.0.0",
3030
"zendframework/zend-config": "^2.6",
31-
"zendframework/zend-crypt": "^2.6 || ^3.0",
32-
"zendframework/zend-servicemanager": "^2.7.10 || ^3.3.1"
31+
"zendframework/zend-crypt": "^2.6 || ^3.0"
3332
},
3433
"suggest": {
35-
"zendframework/zend-crypt": "Crammd5 support in SMTP Auth",
36-
"zendframework/zend-servicemanager": "^2.7.10 || ^3.3.1 when using SMTP to deliver messages"
34+
"zendframework/zend-crypt": "Crammd5 support in SMTP Auth"
3735
},
3836
"autoload": {
3937
"psr-4": {
@@ -52,10 +50,6 @@
5250
"branch-alias": {
5351
"dev-master": "2.10.x-dev",
5452
"dev-develop": "2.11.x-dev"
55-
},
56-
"zf": {
57-
"component": "Zend\\Mail",
58-
"config-provider": "Zend\\Mail\\ConfigProvider"
5953
}
6054
},
6155
"scripts": {

src/ConfigProvider.php

-37
This file was deleted.

src/Module.php

-24
This file was deleted.

src/Protocol/SmtpPluginManager.php

+20-67
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,48 @@
77

88
namespace Zend\Mail\Protocol;
99

10-
use Zend\ServiceManager\AbstractPluginManager;
11-
use Zend\ServiceManager\Exception\InvalidServiceException;
12-
use Zend\ServiceManager\Factory\InvokableFactory;
10+
use Interop\Container\ContainerInterface;
1311

1412
/**
1513
* Plugin manager implementation for SMTP extensions.
1614
*
1715
* Enforces that SMTP extensions retrieved are instances of Smtp. Additionally,
1816
* it registers a number of default extensions available.
1917
*/
20-
class SmtpPluginManager extends AbstractPluginManager
18+
class SmtpPluginManager implements ContainerInterface
2119
{
2220
/**
23-
* Service aliases
24-
*/
25-
protected $aliases = [
26-
'crammd5' => Smtp\Auth\Crammd5::class,
27-
'cramMd5' => Smtp\Auth\Crammd5::class,
28-
'CramMd5' => Smtp\Auth\Crammd5::class,
29-
'cramMD5' => Smtp\Auth\Crammd5::class,
30-
'CramMD5' => Smtp\Auth\Crammd5::class,
31-
'login' => Smtp\Auth\Login::class,
32-
'Login' => Smtp\Auth\Login::class,
33-
'plain' => Smtp\Auth\Plain::class,
34-
'Plain' => Smtp\Auth\Plain::class,
35-
'smtp' => Smtp::class,
36-
'Smtp' => Smtp::class,
37-
'SMTP' => Smtp::class,
38-
];
39-
40-
/**
41-
* Service factories
21+
* Default set of plugins
4222
*
4323
* @var array
4424
*/
45-
protected $factories = [
46-
Smtp\Auth\Crammd5::class => InvokableFactory::class,
47-
Smtp\Auth\Login::class => InvokableFactory::class,
48-
Smtp\Auth\Plain::class => InvokableFactory::class,
49-
Smtp::class => InvokableFactory::class,
50-
51-
// v2 normalized service names
52-
53-
'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class,
54-
'zendmailprotocolsmtpauthlogin' => InvokableFactory::class,
55-
'zendmailprotocolsmtpauthplain' => InvokableFactory::class,
56-
'zendmailprotocolsmtp' => InvokableFactory::class,
25+
protected $plugins = [
26+
'crammd5' => 'Zend\Mail\Protocol\Smtp\Auth\Crammd5',
27+
'login' => 'Zend\Mail\Protocol\Smtp\Auth\Login',
28+
'plain' => 'Zend\Mail\Protocol\Smtp\Auth\Plain',
29+
'smtp' => 'Zend\Mail\Protocol\Smtp',
5730
];
5831

5932
/**
60-
* Plugins must be an instance of the Smtp class
33+
* Do we have the plugin?
6134
*
62-
* @var string
35+
* @param string $id
36+
* @return bool
6337
*/
64-
protected $instanceOf = Smtp::class;
65-
66-
/**
67-
* Validate a retrieved plugin instance (v3).
68-
*
69-
* @param object $plugin
70-
* @throws InvalidServiceException
71-
*/
72-
public function validate($plugin)
38+
public function has($id)
7339
{
74-
if (! $plugin instanceof $this->instanceOf) {
75-
throw new InvalidServiceException(sprintf(
76-
'Plugin of type %s is invalid; must extend %s',
77-
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
78-
Smtp::class
79-
));
80-
}
40+
return array_key_exists($id, $this->plugins);
8141
}
82-
8342
/**
84-
* Validate a retrieved plugin instance (v2).
43+
* Retrieve the smtp plugin
8544
*
86-
* @param object $plugin
87-
* @throws Exception\InvalidArgumentException
45+
* @param string $id
46+
* @param array $options
47+
* @return AbstractProtocol
8848
*/
89-
public function validatePlugin($plugin)
49+
public function get($id, array $options = null)
9050
{
91-
try {
92-
$this->validate($plugin);
93-
} catch (InvalidServiceException $e) {
94-
throw new Exception\InvalidArgumentException(
95-
$e->getMessage(),
96-
$e->getCode(),
97-
$e
98-
);
99-
}
51+
$class = $this->plugins[$id];
52+
return new $class($options);
10053
}
10154
}

src/Protocol/SmtpPluginManagerFactory.php

-53
This file was deleted.

src/Transport/Smtp.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Zend\Mail\Message;
1313
use Zend\Mail\Protocol;
1414
use Zend\Mail\Protocol\Exception as ProtocolException;
15-
use Zend\ServiceManager\ServiceManager;
1615

1716
/**
1817
* SMTP connection object
@@ -129,7 +128,7 @@ public function setPluginManager(Protocol\SmtpPluginManager $plugins)
129128
public function getPluginManager()
130129
{
131130
if (null === $this->plugins) {
132-
$this->setPluginManager(new Protocol\SmtpPluginManager(new ServiceManager()));
131+
$this->setPluginManager(new Protocol\SmtpPluginManager());
133132
}
134133
return $this->plugins;
135134
}

test/Protocol/SmtpPluginManagerCompatibilityTest.php

-35
This file was deleted.

test/Protocol/SmtpPluginManagerFactoryTest.php

-73
This file was deleted.

0 commit comments

Comments
 (0)