<?php
/**
 * An abstract class for email transports.
 *
 * This class is a thin wrapper over swift transports.
 */
abstract class email_transport_swift implements email_transport
{
    /**
     * @var Swift_Transport The swift transport.
     */
    protected $transport;

    ////////////////////////////////////////////////////////////////////////////
    // Construct and destruct functions.

    ////////////////////////////////////////////////////////////////////////////
    // Overload functions.

    /**
     * Transforms the email transport as a swift object.
     *
     * @return Swift_Transport The object.
     */
    public function __toswift()
    {
        return $this->transport;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    // Interface functions.

    /**
     * Sends an email.
     *
     * @param email $email The email.
     * @param array (optional) $failed The failed recipients.
     * @throws unexpectedvalueexception If the email cannot be sent.
     * @return email_transport A fluent interface.
     */
    public function send(email $email, &$failed = array())
    {
        if (!$this->transport->isStarted())
        {
            $this->transport->start();
        }
        
        $this->transport->send($email->__toswift(), $failed);
        return $this;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    // Internal functions.
}
