protected function createTransport(ContainerInterface $container)
{
$adapter = $this->mailOptions->getMailAdapter();
// A transport instance can be returned as is
if ($adapter instanceof TransportInterface) {
return $this->setupTransportConfig($adapter);
}
// Check if the adapter is a service
if (is_string($adapter) && $container->has($adapter)) {
/** @var TransportInterface $transport */
$transport = $container->get($adapter);
if ($transport instanceof TransportInterface) {
return $this->setupTransportConfig($transport);
} else {
throw new InvalidArgumentException('Provided mail_adapter service does not return a "Zend\\Mail\\Transport\\TransportInterface" instance');
}
}
// Check if the adapter is one of Zend's default adapters
if (is_string($adapter) && is_subclass_of($adapter, 'Zend\\Mail\\Transport\\TransportInterface')) {
return $this->setupTransportConfig(new $adapter());
}
// The adapter is not valid. Throw an exception
throw new InvalidArgumentException(sprintf('mail_adapter must be an instance of "Zend\\Mail\\Transport\\TransportInterface" or string, "%s" provided', is_object($adapter) ? get_class($adapter) : gettype($adapter)));
}