ZF-8436: Add Zend_App_Resource_Mail

Description

<?php
/**
 * Configuration options (INI):
 
 * application.resources.mail
 * application.resources.mail.protocol = smtp
 * application.resources.mail.host = mail.domain.com
 * application.resources.mail.options.port = 2626
 * application.resources.mail.options.auth = login
 * application.resources.mail.options.username = info+domain.com
 * application.resources.mail.options.password = *secret8
 * application.resources.mail.registry.sender.from = info@domain.com
 * application.resources.mail.registry.sender.name - no-reply
 *
 * NOTE : The resource loader will store in Zend_Registry, the array
 *
 *  array(
 *    'sender' => 'info@domain.com' 
 *    'name'   => 'no-reply'
 *  );
 *
 *  Custom registry key can be specified through the registryKey option
 *
 */
 
/**
 * @author yanick[-dot-]rochon[-at-]gmail[-dot-]com
 */
class Phoo_Application_Resource_Mail
    extends Zend_Application_Resource_ResourceAbstract
{
        
        const DEFAULT_REGISTRY_KEY = 'Zend_Mail_Options';
        
        
        public function init()
    {
        $options = $this->getOptions();
        
        $transportType = ucfirst(strtolower($options['protocol']));
        $transportHost = $options['host'];
                $transportOptions = $options['options'];
                
        $transportClass = "Zend_Mail_Transport_{$transportType}"; 
        
                $transport = new $transportClass($transportHost, $transportOptions);
 
                Zend_Mail::setDefaultTransport($transport);
 
                if (isset($options['registry'])) {
                        if (isset($options['registryKey'])) {
                                $registryKey = $options['registryKey'];
                        } else {
                                $registryKey = self::DEFAULT_REGISTRY_KEY;
                        }
                        
                        Zend_Registry::set($registryKey, $options['registry']);
                }
    }
        
}

Comments

A basic mail resource which could be extended to support more otpions

Attached proposed patch. No unittests available yet.

Done in trunk, to be released in 1.10