|
7 | 7 |
|
8 | 8 | namespace Zend\Mail\Protocol; |
9 | 9 |
|
10 | | -use Zend\ServiceManager\AbstractPluginManager; |
11 | | -use Zend\ServiceManager\Exception\InvalidServiceException; |
12 | | -use Zend\ServiceManager\Factory\InvokableFactory; |
| 10 | +use Interop\Container\ContainerInterface; |
13 | 11 |
|
14 | 12 | /** |
15 | 13 | * Plugin manager implementation for SMTP extensions. |
16 | 14 | * |
17 | 15 | * Enforces that SMTP extensions retrieved are instances of Smtp. Additionally, |
18 | 16 | * it registers a number of default extensions available. |
19 | 17 | */ |
20 | | -class SmtpPluginManager extends AbstractPluginManager |
| 18 | +class SmtpPluginManager implements ContainerInterface |
21 | 19 | { |
22 | 20 | /** |
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 |
42 | 22 | * |
43 | 23 | * @var array |
44 | 24 | */ |
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', |
57 | 30 | ]; |
58 | 31 |
|
59 | 32 | /** |
60 | | - * Plugins must be an instance of the Smtp class |
| 33 | + * Do we have the plugin? |
61 | 34 | * |
62 | | - * @var string |
| 35 | + * @param string $id |
| 36 | + * @return bool |
63 | 37 | */ |
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) |
73 | 39 | { |
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); |
81 | 41 | } |
82 | | - |
83 | 42 | /** |
84 | | - * Validate a retrieved plugin instance (v2). |
| 43 | + * Retrieve the smtp plugin |
85 | 44 | * |
86 | | - * @param object $plugin |
87 | | - * @throws Exception\InvalidArgumentException |
| 45 | + * @param string $id |
| 46 | + * @param array $options |
| 47 | + * @return AbstractProtocol |
88 | 48 | */ |
89 | | - public function validatePlugin($plugin) |
| 49 | + public function get($id, array $options = null) |
90 | 50 | { |
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); |
100 | 53 | } |
101 | 54 | } |
0 commit comments