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

Commit

Permalink
Resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 134 deletions.
58 changes: 0 additions & 58 deletions src/Protocol/SmtpBroker.php

This file was deleted.

46 changes: 0 additions & 46 deletions src/Protocol/SmtpLoader.php

This file was deleted.

74 changes: 74 additions & 0 deletions src/Protocol/SmtpPluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mail\Protocol;

use Zend\ServiceManager\AbstractPluginManager;

/**
* Plugin manager implementation for SMTP extensions.
*
* Enforces that SMTP extensions retrieved are instances of Smtp. Additionally,
* it registers a number of default extensions available.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class SmtpPluginManager extends AbstractPluginManager
{
/**
* Default set of extensions
*
* @var array
*/
protected $invokableClasses = array(
'crammd5' => 'Zend\Mail\Protocol\Smtp\Auth\Crammd5',
'login' => 'Zend\Mail\Protocol\Smtp\Auth\Login',
'plain' => 'Zend\Mail\Protocol\Smtp\Auth\Plain',
'smtp' => 'Zend\Mail\Protocol\Smtp',
);

/**
* Validate the plugin
*
* Checks that the extension loaded is an instance of Smtp.
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
public function validatePlugin($plugin)
{
if ($plugin instanceof Smtp) {
// we're okay
return;
}

throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must extend %s\Smtp',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}
51 changes: 24 additions & 27 deletions src/Transport/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@

namespace Zend\Mail\Transport;

use Zend\Loader\Pluggable,
Zend\Mail\Address,
Zend\Mail\Headers,
Zend\Mail\Message,
Zend\Mail\Protocol,
Zend\Mail\Protocol\Exception as ProtocolException;
use Zend\Mail\Address;
use Zend\Mail\Headers;
use Zend\Mail\Message;
use Zend\Mail\Protocol;
use Zend\Mail\Protocol\Exception as ProtocolException;

/**
* SMTP connection object
Expand All @@ -39,7 +38,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Smtp implements TransportInterface, Pluggable
class Smtp implements TransportInterface
{
/**
* @var SmtpOptions
Expand All @@ -57,9 +56,9 @@ class Smtp implements TransportInterface, Pluggable
protected $autoDisconnect = true;

/**
* @var Protocol\SmtpBroker
* @var Protocol\SmtpPluginManager
*/
protected $broker;
protected $plugins;

/**
* Constructor.
Expand Down Expand Up @@ -97,37 +96,31 @@ public function getOptions()
}

/**
* Set broker for obtaining SMTP protocol connection
* Set plugin manager for obtaining SMTP protocol connection
*
* @param Protocol\SmtpBroker $broker
* @param Protocol\SmtpPluginManager $plugins
* @throws Exception\InvalidArgumentException
* @return Smtp
*/
public function setBroker($broker)
public function setPluginManager(Protocol\SmtpPluginManager $plugins)
{
if (!$broker instanceof Protocol\SmtpBroker) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an SmtpBroker argument; received "%s"',
__METHOD__,
(is_object($broker) ? get_class($broker) : gettype($broker))
));
}
$this->broker = $broker;
$this->plugins = $plugins;
return $this;
}

/**
* Get broker for loading SMTP protocol connection
* Get plugin manager for loading SMTP protocol connection
*
* @return Protocol\SmtpBroker
* @return Protocol\SmtpPluginManager
*/
public function getBroker()
public function getPluginManager()
{
if (null === $this->broker) {
$this->setBroker(new Protocol\SmtpBroker());
if (null === $this->plugins) {
$this->setPluginManager(new Protocol\SmtpPluginManager());
}
return $this->broker;
return $this->plugins;
}

/**
* Set the automatic disconnection when destruct
*
Expand All @@ -139,6 +132,7 @@ public function setAutoDisconnect($flag)
$this->autoDisconnect = (bool) $flag;
return $this;
}

/**
* Get the automatic disconnection value
*
Expand All @@ -148,6 +142,7 @@ public function getAutoDisconnect()
{
return $this->autoDisconnect;
}

/**
* Return an SMTP connection
*
Expand All @@ -157,7 +152,7 @@ public function getAutoDisconnect()
*/
public function plugin($name, array $options = null)
{
return $this->getBroker()->load($name, $options);
return $this->getPluginManager()->get($name, $options);
}

/**
Expand Down Expand Up @@ -197,6 +192,7 @@ public function getConnection()
{
return $this->connection;
}

/**
* Disconnect the connection protocol instance
*
Expand All @@ -208,6 +204,7 @@ public function disconnect()
$this->connection->disconnect();
}
}

/**
* Send an email via the SMTP connection protocol
*
Expand Down
6 changes: 3 additions & 3 deletions test/Transport/SmtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ public function testReceivesMailArtifacts()
$this->assertContains("\r\n\r\nThis is only a test.", $data, $data);
}

public function testCanUseAuthenticationExtensionsViaPluginBroker()
public function testCanUseAuthenticationExtensionsViaPluginManager()
{
$options = new SmtpOptions(array(
'connection_class' => 'login',
));
$transport = new Smtp($options);
$connection = $transport->plugin($options->getConnectionClass(), array(array(
$connection = $transport->plugin($options->getConnectionClass(), array(
'username' => 'matthew',
'password' => 'password',
'host' => 'localhost',
)));
));
$this->assertInstanceOf('Zend\Mail\Protocol\Smtp\Auth\Login', $connection);
$this->assertEquals('matthew', $connection->getUsername());
$this->assertEquals('password', $connection->getPassword());
Expand Down

0 comments on commit 2c9f881

Please # to comment.