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

Commit 292a06a

Browse files
committed
Merge branch 'feature/config-provider' into develop
Close #80
2 parents 3bf97c8 + cd2c323 commit 292a06a

File tree

7 files changed

+198
-1
lines changed

7 files changed

+198
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file, in reverse
88

99
- [#41](https://github.com/zendframework/zend-mail/pull/41) adds support for
1010
IMAP delimiters in the IMAP storage adapter.
11+
- [#80](https://github.com/zendframework/zend-mail/pull/80) adds:
12+
- `Zend\Mail\Protocol\SmtpPluginManagerFactory`, for creating and returning an
13+
`SmtpPluginManagerFactory` instance.
14+
- `Zend\Mail\ConfigProvider`, which maps the `SmtpPluginManager` to the above
15+
factory.
16+
- `Zend\Mail\Module`, which does the same, for zend-mvc contexts.
1117

1218
### Deprecated
1319

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"branch-alias": {
3737
"dev-master": "2.6-dev",
3838
"dev-develop": "2.7-dev"
39+
},
40+
"zf": {
41+
"component": "Zend\\Mail",
42+
"config-provider": "Zend\\Mail\\ConfigProvider"
3943
}
4044
},
4145
"autoload-dev": {

src/ConfigProvider.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-mail for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Mail;
9+
10+
class ConfigProvider
11+
{
12+
/**
13+
* Retrieve configuration for zend-mail package.
14+
*
15+
* @return array
16+
*/
17+
public function __invoke()
18+
{
19+
return [
20+
'dependencies' => $this->getDependencyConfig(),
21+
];
22+
}
23+
24+
/**
25+
* Retrieve dependency settings for zend-mail package.
26+
*
27+
* @return array
28+
*/
29+
public function getDependencyConfig()
30+
{
31+
return [
32+
'factories' => [
33+
Protocol\SmtpPluginManager::class => Protocol\SmtpPluginManagerFactory::class,
34+
],
35+
];
36+
}
37+
}

src/Module.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-mail for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Mail;
9+
10+
class Module
11+
{
12+
/**
13+
* Retrieve zend-mail package configuration for zend-mvc context.
14+
*
15+
* @return array
16+
*/
17+
public function getConfig()
18+
{
19+
$provider = new ConfigProvider();
20+
return [
21+
'service_manager' => $provider->getDependencyConfig(),
22+
];
23+
}
24+
}

src/Protocol/SmtpPluginManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SmtpPluginManager extends AbstractPluginManager
5555
'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class,
5656
'zendmailprotocolsmtpauthlogin' => InvokableFactory::class,
5757
'zendmailprotocolsmtpauthplain' => InvokableFactory::class,
58-
'zendmailprotocolsmtp' => InvokableFactory::class,
58+
'zendmailprotocolsmtp' => InvokableFactory::class,
5959
];
6060

6161
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-mail for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Mail\Protocol;
9+
10+
use Interop\Container\ContainerInterface;
11+
use Zend\ServiceManager\FactoryInterface;
12+
use Zend\ServiceManager\ServiceLocatorInterface;
13+
14+
class SmtpPluginManagerFactory implements FactoryInterface
15+
{
16+
/**
17+
* zend-servicemanager v2 support for invocation options.
18+
*
19+
* @param array
20+
*/
21+
protected $creationOptions;
22+
23+
/**
24+
* {@inheritDoc}
25+
*
26+
* @return SmtpPluginManager
27+
*/
28+
public function __invoke(ContainerInterface $container, $name, array $options = null)
29+
{
30+
return new SmtpPluginManager($container, $options ?: []);
31+
}
32+
33+
/**
34+
* {@inheritDoc}
35+
*
36+
* @return SmtpPluginManager
37+
*/
38+
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
39+
{
40+
return $this($container, $requestedName ?: SmtpPluginManager::class, $this->creationOptions);
41+
}
42+
43+
/**
44+
* zend-servicemanager v2 support for invocation options.
45+
*
46+
* @param array $options
47+
* @return void
48+
*/
49+
public function setCreationOptions(array $options)
50+
{
51+
$this->creationOptions = $options;
52+
}
53+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-mail for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace ZendTest\Mail\Protocol;
9+
10+
use Interop\Container\ContainerInterface;
11+
use PHPUnit_Framework_TestCase as TestCase;
12+
use Zend\Mail\Protocol\Smtp;
13+
use Zend\Mail\Protocol\SmtpPluginManager;
14+
use Zend\Mail\Protocol\SmtpPluginManagerFactory;
15+
use Zend\ServiceManager\ServiceLocatorInterface;
16+
17+
class SmtpPluginManagerFactoryTest extends TestCase
18+
{
19+
public function testFactoryReturnsPluginManager()
20+
{
21+
$container = $this->prophesize(ContainerInterface::class)->reveal();
22+
$factory = new SmtpPluginManagerFactory();
23+
24+
$plugins = $factory($container, SmtpPluginManager::class);
25+
$this->assertInstanceOf(SmtpPluginManager::class, $plugins);
26+
27+
if (method_exists($plugins, 'configure')) {
28+
// zend-servicemanager v3
29+
$this->assertAttributeSame($container, 'creationContext', $plugins);
30+
} else {
31+
// zend-servicemanager v2
32+
$this->assertSame($container, $plugins->getServiceLocator());
33+
}
34+
}
35+
36+
/**
37+
* @depends testFactoryReturnsPluginManager
38+
*/
39+
public function testFactoryConfiguresPluginManagerUnderContainerInterop()
40+
{
41+
$container = $this->prophesize(ContainerInterface::class)->reveal();
42+
$smtp = $this->prophesize(Smtp::class)->reveal();
43+
44+
$factory = new SmtpPluginManagerFactory();
45+
$plugins = $factory($container, SmtpPluginManager::class, [
46+
'services' => [
47+
'test' => $smtp,
48+
],
49+
]);
50+
$this->assertSame($smtp, $plugins->get('test'));
51+
}
52+
53+
/**
54+
* @depends testFactoryReturnsPluginManager
55+
*/
56+
public function testFactoryConfiguresPluginManagerUnderServiceManagerV2()
57+
{
58+
$container = $this->prophesize(ServiceLocatorInterface::class);
59+
$container->willImplement(ContainerInterface::class);
60+
61+
$smtp = $this->prophesize(Smtp::class)->reveal();
62+
63+
$factory = new SmtpPluginManagerFactory();
64+
$factory->setCreationOptions([
65+
'services' => [
66+
'test' => $smtp,
67+
],
68+
]);
69+
70+
$plugins = $factory->createService($container->reveal());
71+
$this->assertSame($smtp, $plugins->get('test'));
72+
}
73+
}

0 commit comments

Comments
 (0)