This is designed to play nicely with other autoloaders.
public static registerAutoload ( mixed $callable = null ) | ||
$callable | mixed | A valid PHP callable that will be called when autoloading the first Swift class |
public function register(Application $app) { $app['swiftmailer.options'] = array_replace(array('host' => 'localhost', 'port' => 25, 'username' => '', 'password' => '', 'encryption' => null, 'auth_mode' => null), isset($app['swiftmailer.options']) ? $app['swiftmailer.options'] : array()); $app['mailer'] = $app->share(function () use($app) { $r = new \ReflectionClass('Swift_Mailer'); require_once dirname($r->getFilename()) . '/../../swift_init.php'; return new \Swift_Mailer($app['swiftmailer.transport']); }); $app['swiftmailer.transport'] = $app->share(function () use($app) { $transport = new \Swift_Transport_EsmtpTransport($app['swiftmailer.transport.buffer'], array($app['swiftmailer.transport.authhandler']), $app['swiftmailer.transport.eventdispatcher']); $transport->setHost($app['swiftmailer.options']['host']); $transport->setPort($app['swiftmailer.options']['port']); $transport->setEncryption($app['swiftmailer.options']['encryption']); $transport->setUsername($app['swiftmailer.options']['username']); $transport->setPassword($app['swiftmailer.options']['password']); $transport->setAuthMode($app['swiftmailer.options']['auth_mode']); return $transport; }); $app['swiftmailer.transport.buffer'] = $app->share(function () { return new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory()); }); $app['swiftmailer.transport.authhandler'] = $app->share(function () { return new \Swift_Transport_Esmtp_AuthHandler(array(new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(), new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(), new \Swift_Transport_Esmtp_Auth_PlainAuthenticator())); }); $app['swiftmailer.transport.eventdispatcher'] = $app->share(function () { return new \Swift_Events_SimpleEventDispatcher(); }); if (isset($app['swiftmailer.class_path'])) { require_once $app['swiftmailer.class_path'] . '/Swift.php'; \Swift::registerAutoload($app['swiftmailer.class_path'] . '/../swift_init.php'); } }
/** * Creates RAD app kernel, which you can use to manage your app. * * Loads intl, swift and then requires/initializes/returns custom * app kernel. * * @param ClassLoader $loader Composer class loader * @param string $environment Environment name * @param Boolean $debug Debug mode? * * @return RadAppKernel */ public static function createAppKernel(ClassLoader $loader, $environment, $debug) { require_once __DIR__ . '/RadAppKernel.php'; if (null === self::$projectRootDir) { self::$projectRootDir = realpath(__DIR__ . '/../../../../../../..'); } $autoloadIntl = function ($rootDir) use($loader) { if (!function_exists('intl_get_error_code')) { require_once $rootDir . '/vendor/symfony/symfony/src/' . 'Symfony/Component/Locale/Resources/stubs/functions.php'; $loader->add(null, $rootDir . '/vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs'); } }; $autoloadSwift = function ($rootDir) use($loader) { require_once $rootDir . '/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php'; \Swift::registerAutoload($rootDir . '/vendor/swiftmailer/swiftmailer/lib/swift_init.php'); }; $loader->add(null, self::$projectRootDir . '/src'); if (file_exists($custom = self::$projectRootDir . '/config/autoload.php')) { require $custom; } else { $autoloadIntl(self::$projectRootDir); $autoloadSwift(self::$projectRootDir); } return new \RadAppKernel($environment, $debug); }
/** * Loads the Swift mailer */ public static function enableMailer() { if (!class_exists('Swift_Message')) { Swift::registerAutoload(); sfMailer::initialize(); } }
function __construct() { // include swift mailer require ENGINE_PATH . 'swiftmailer/classes/Swift.php'; Swift::init(); Swift::registerAutoload(); //Yii::import('system.vendors.swiftMailer.classes.Swift', true); //Yii::registerAutoloader(array('Swift','autoload')); require_once ENGINE_PATH . 'swiftmailer/swift_init.php'; //Yii::import('system.vendors.swiftMailer.swift_init', true); switch ($this->params['transportType']) { case 'smtp': $transport = Swift_SmtpTransport::newInstance($this->params['smtpServer'], $this->params['smtpPort'], $this->params['smtpSequre'])->setUsername($this->params['smtpUsername'])->setPassword($this->params['smtpPassword']); break; case 'sendmail': $transport = Swift_SendmailTransport::newInstance($this->params['sendmailCommand']); break; default: case 'mail': $transport = Swift_MailTransport::newInstance(); break; } $this->toEmail = 'noreplay@' . $_SERVER['HTTP_HOST']; $this->fromEmail = 'noreplay@' . $_SERVER['HTTP_HOST']; $this->path = "http://" . $_SERVER['HTTP_HOST'] . "/submit/mailtpl/"; $this->mailer = Swift_Mailer::newInstance($transport); $this->mes = Swift_Message::newInstance(); }
/** * @param $vendorDir */ public function __construct($vendorDir) { require_once sprintf('%s/lib/classes/Swift.php', $vendorDir); if (!\Swift::$initialized) { \Swift::registerAutoload(sprintf('%s/lib/swift_init.php', $vendorDir)); } }
protected function initializeMailer() { require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/classes/Swift.php'; Swift::registerAutoload(); sfMailer::initialize(); $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); return new $config['mailer']['class']($this->dispatcher, $config['mailer']['param']); }
/** * Creates a SwiftMailer instance. * * @param string Config array mirroring format as described in config file * @return object Swift object */ public static function connect($config = NULL) { if (!class_exists('Swift', FALSE)) { // Load SwiftMailer require Kohana::find_file('vendor', 'swift4/lib/swift_required'); // Register the Swift ClassLoader as an autoload Swift::registerAutoload(); } // Load default configuration $config === NULL and $config = Kohana::config('email'); switch ($config['driver']) { case 'smtp': // Set port $port = empty($config['options']['port']) ? NULL : (int) $config['options']['port']; //Set host $transport = Swift_SmtpTransport::newInstance()->setHost($config['options']['hostname']); //Set port if defined if ($port) { $transport->setPort($port); } //Set encryption if defined if (!empty($config['options']['encryption'])) { $enc = strtolower($config['options']['encryption']); $transport->setEncryption($enc); } empty($config['options']['username']) or $transport->setUsername($config['options']['username']); empty($config['options']['password']) or $transport->setPassword($config['options']['password']); // Set the timeout to 5 seconds $mailer = Swift_Mailer::newInstance($transport); break; //Sendmail //Sendmail case 'sendmail': $op = empty($config['options']) ? null : $config['options']; $transport = Swift_SendmailTransport::newInstance($op); break; //PHP mail :( //PHP mail :( default: $transport = Swift_MailTransport::newInstance(); break; } // Create the SwiftMailer instance return email::$mail = $mailer; }
<?php /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /* * Autoloader and dependency injection initialization for Swift Mailer. */ if (class_exists('Swift', false)) { return; } // Load Swift utility class require dirname(__FILE__) . '/Swift.php'; if (!function_exists('_swiftmailer_init')) { function _swiftmailer_init() { require dirname(__FILE__) . '/swift_init.php'; } } // Start the autoloader and lazy-load the init script to set up dependency injection Swift::registerAutoload('_swiftmailer_init');
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'), 'Sensio' => __DIR__.'/../vendor/bundles', 'JMS' => __DIR__.'/../vendor/bundles', 'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib', 'Doctrine\\DBAL\\Migrations' => __DIR__.'/../vendor/doctrine-migrations/lib', 'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib', 'Doctrine' => __DIR__.'/../vendor/doctrine/lib', 'Monolog' => __DIR__.'/../vendor/monolog/src', 'Assetic' => __DIR__.'/../vendor/assetic/src', 'Metadata' => __DIR__.'/../vendor/metadata/src', 'TaskBoxx' => __DIR__.'/../src', 'Bundle' => __DIR__.'/../src', 'Knplabs' => __DIR__.'/../src/Bundle', )); $loader->registerPrefixes(array( 'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib', 'Twig_' => __DIR__.'/../vendor/twig/lib', )); $loader->registerPrefixFallbacks(array( __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs', )); $loader->registerNamespaceFallbacks(array( __DIR__.'/../src', )); $loader->register(); // Swiftmailer needs a special autoloader to allow // the lazy loading of the init file (which is expensive) require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php'; Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
} $class = sfConfig::get('sf_factory_controller', 'sfFrontWebController'); $this->factories['controller'] = new $class($this); $class = sfConfig::get('sf_factory_request', 'sfWebRequest'); $this->factories['request'] = new $class($this->dispatcher, array(), array(), sfConfig::get('sf_factory_request_parameters', array('logging' => '1', 'path_info_array' => 'SERVER', 'path_info_key' => 'PATH_INFO', 'relative_url_root' => NULL, 'formats' => array('txt' => 'text/plain', 'js' => array(0 => 'application/javascript', 1 => 'application/x-javascript', 2 => 'text/javascript'), 'css' => 'text/css', 'json' => array(0 => 'application/json', 1 => 'application/x-json'), 'xml' => array(0 => 'text/xml', 1 => 'application/xml', 2 => 'application/x-xml'), 'rdf' => 'application/rdf+xml', 'atom' => 'application/atom+xml'), 'no_script_name' => false)), sfConfig::get('sf_factory_request_attributes', array())); $class = sfConfig::get('sf_factory_response', 'sfWebResponse'); $this->factories['response'] = new $class($this->dispatcher, sfConfig::get('sf_factory_response_parameters', array_merge(array('http_protocol' => isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null), array('logging' => '1', 'charset' => 'utf-8', 'send_http_headers' => false)))); if ($this->factories['request'] instanceof sfWebRequest && $this->factories['response'] instanceof sfWebResponse && 'HEAD' == $this->factories['request']->getMethod()) { $this->factories['response']->setHeaderOnly(true); } $class = sfConfig::get('sf_factory_routing', 'sfPatternRouting'); $cache = null; $this->factories['routing'] = new $class($this->dispatcher, $cache, array_merge(array('auto_shutdown' => false, 'context' => $this->factories['request']->getRequestContext()), sfConfig::get('sf_factory_routing_parameters', array('load_configuration' => true, 'suffix' => '', 'default_module' => 'default', 'default_action' => 'index', 'debug' => '1', 'logging' => '1', 'generate_shortest_url' => false, 'extra_parameters_as_query_string' => false, 'cache' => NULL)))); if ($parameters = $this->factories['routing']->parse($this->factories['request']->getPathInfo())) { $this->factories['request']->addRequestParameters($parameters); } $class = sfConfig::get('sf_factory_storage', 'sfSessionTestStorage'); $this->factories['storage'] = new $class(array_merge(array('auto_shutdown' => false, 'session_id' => $this->getRequest()->getParameter('symfony')), sfConfig::get('sf_factory_storage_parameters', array('session_name' => 'symfony', 'session_path' => '/var/www/production/sfweb/www/cache/symfony-for-release/1.3.4/test/functional/fixtures/cache/frontend/test/test/sessions')))); $class = sfConfig::get('sf_factory_user', 'myUser'); $this->factories['user'] = new $class($this->dispatcher, $this->factories['storage'], array_merge(array('auto_shutdown' => false, 'culture' => $this->factories['request']->getParameter('sf_culture')), sfConfig::get('sf_factory_user_parameters', array('timeout' => 1800, 'logging' => '1', 'use_flash' => true, 'default_culture' => 'en')))); if (sfConfig::get('sf_cache')) { $class = sfConfig::get('sf_factory_view_cache', 'sfFileCache'); $cache = new $class(sfConfig::get('sf_factory_view_cache_parameters', array('automatic_cleaning_factor' => 0, 'cache_dir' => '/var/www/production/sfweb/www/cache/symfony-for-release/1.3.4/test/functional/fixtures/cache/frontend/test/template', 'lifetime' => 86400, 'prefix' => '/var/www/production/sfweb/www/cache/symfony-for-release/1.3.4/test/functional/fixtures/apps/frontend/template'))); $this->factories['viewCacheManager'] = new sfViewCacheManager($this, $cache, array('cache_key_use_vary_headers' => true, 'cache_key_use_host_name' => true)); } else { $this->factories['viewCacheManager'] = null; } require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/classes/Swift.php'; Swift::registerAutoload(); sfMailer::initialize(); $this->setMailerConfiguration(array_merge(array('class' => sfConfig::get('sf_factory_mailer', 'sfMailer')), sfConfig::get('sf_factory_mailer_parameters', array('logging' => '1', 'charset' => 'utf-8', 'delivery_strategy' => 'realtime', 'transport' => array('class' => 'Swift_SmtpTransport', 'param' => array('host' => 'localhost', 'port' => 25, 'encryption' => NULL, 'username' => NULL, 'password' => NULL))))));
<?php /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /* * Autoloader and dependency injection initialization for Swift Mailer. */ if (defined('SWIFT_REQUIRED_LOADED')) { return; } define('SWIFT_REQUIRED_LOADED', true); //Load Swift utility class require dirname(__FILE__) . '/classes/Swift.php'; //Start the autoloader and lazy-load the init script to set up dependency injection Swift::registerAutoload(dirname(__FILE__) . '/swift_init.php');
*/ @session_start(); /** * Register the class and template loader */ require TL_ROOT . '/system/library/Contao/ClassLoader.php'; class_alias('Contao\\ClassLoader', 'ClassLoader'); require TL_ROOT . '/system/library/Contao/TemplateLoader.php'; class_alias('Contao\\TemplateLoader', 'TemplateLoader'); ClassLoader::scanAndRegister(); // config/autoload.php /** * Register the SwiftMailer autoloader */ require_once TL_ROOT . '/system/library/Swiftmailer/classes/Swift.php'; Swift::registerAutoload(TL_ROOT . '/system/library/Swiftmailer/swift_init.php'); /** * Get the Config instance */ $objConfig = Config::getInstance(); /** * Initialize the Input and RequestToken class */ Input::initialize(); RequestToken::initialize(); /** * Set error_reporting */ @ini_set('display_errors', $GLOBALS['TL_CONFIG']['displayErrors'] ? 1 : 0); error_reporting($GLOBALS['TL_CONFIG']['displayErrors'] || $GLOBALS['TL_CONFIG']['logErrors'] ? E_ALL | E_STRICT : 0); /**
/** * Retrieves the mailer. * * @return sfMailer The current sfMailer implementation instance. */ public function getMailer() { if (!isset($this->factories['mailer'])) { Swift::registerAutoload(); sfMailer::initialize(); $this->factories['mailer'] = new $this->mailerConfiguration['class']($this->dispatcher, $this->mailerConfiguration); } return $this->factories['mailer']; }
private function submit() { Swift::registerAutoload(); $l_oTransport = \Swift_SmtpTransport::newInstance('flanders01.flanders.local', '25')->setUsername('')->setPassword(''); $l_oSwift = \Swift_Mailer::newInstance($l_oTransport); $l_oMessage = \Swift_Message::newInstance($this->m_sSubject)->setFrom([$this->m_sEmail => $this->m_sName])->setTo(['*****@*****.**' => 'Annick Boghemans'])->setBody($this->m_sMailBody, 'text/html')->addPart(strip_tags($this->m_sMailBody), 'text/plain'); try { $l_oSwift->send($l_oMessage); return 0; } catch (Exception $ex) { return 1; } // if ($l_oSwift->send($l_oMessage)){ // return 0; // } else { // return 1; // } }
/** * Initialize mailer * * @return sfMailer A sfMailer instance */ protected function initializeMailer() { if (!class_exists('Swift')) { $swift_dir = sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/lib'; require_once $swift_dir . '/classes/Swift.php'; Swift::registerAutoload($swift_dir . '/swift_init.php'); } $config = $this->getFactoryConfiguration(); return new $config['mailer']['class']($this->dispatcher, $config['mailer']['param']); }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/lib/classes/Swift.php'; Swift::registerAutoload(sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/lib/swift_init.php'); require_once dirname(__FILE__) . '/fixtures/TestMailerTransport.class.php'; require_once dirname(__FILE__) . '/fixtures/TestSpool.class.php'; require_once dirname(__FILE__) . '/fixtures/TestMailMessage.class.php'; $t = new lime_test(34); $dispatcher = new sfEventDispatcher(); // __construct() $t->diag('__construct()'); try { new sfMailer($dispatcher, array('delivery_strategy' => 'foo')); $t->fail('__construct() throws an InvalidArgumentException exception if the strategy is not valid'); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws an InvalidArgumentException exception if the strategy is not valid'); } // main transport $mailer = new sfMailer($dispatcher, array('logging' => true, 'delivery_strategy' => 'realtime', 'transport' => array('class' => 'TestMailerTransport', 'param' => array('foo' => 'bar', 'bar' => 'foo')))); $t->is($mailer->getTransport()->getFoo(), 'bar', '__construct() passes the parameters to the main transport'); // spool $mailer = new sfMailer($dispatcher, array('logging' => true, 'delivery_strategy' => 'spool', 'spool_class' => 'TestSpool', 'spool_arguments' => array('TestMailMessage'), 'transport' => array('class' => 'Swift_SmtpTransport', 'param' => array('username' => 'foo')))); $t->is($mailer->getRealTimeTransport()->getUsername(), 'foo', '__construct() passes the parameters to the main transport');
<?php /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/classes/Swift.php'; Swift::registerAutoload(function () { // Load in dependency maps require __DIR__ . '/dependency_maps/cache_deps.php'; require __DIR__ . '/dependency_maps/mime_deps.php'; require __DIR__ . '/dependency_maps/message_deps.php'; require __DIR__ . '/dependency_maps/transport_deps.php'; // Load in global library preferences require __DIR__ . '/preferences.php'; });
@session_start(); /** * Register the class and template loader */ require TL_ROOT . '/system/modules/core/library/Contao/ClassLoader.php'; class_alias('Contao\\ClassLoader', 'ClassLoader'); require TL_ROOT . '/system/modules/core/library/Contao/TemplateLoader.php'; class_alias('Contao\\TemplateLoader', 'TemplateLoader'); ClassLoader::scanAndRegister(); // config/autoload.php /** * Register the SwiftMailer and SimplePie autoloaders */ require_once TL_ROOT . '/system/vendor/swiftmailer/classes/Swift.php'; Swift::registerAutoload(function () { require TL_ROOT . '/system/vendor/swiftmailer/swift_init.php'; }); require_once TL_ROOT . '/system/vendor/simplepie/autoloader.php'; /** * Get the Config instance */ $objConfig = Config::getInstance(); /** * Initialize the Input and RequestToken class */ Input::initialize(); RequestToken::initialize(); /** * Set error_reporting */ @ini_set('display_errors', $GLOBALS['TL_CONFIG']['displayErrors'] ? 1 : 0);