From 111a023466a233fbb9bcc2f008bef0cbb51719cd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2010 15:57:07 +0100 Subject: [PATCH] [DependencyInjection] added some extensions --- .../Loader/Extension/DoctrineExtension.php | 73 +++++++++++ .../Loader/Extension/SwiftMailerExtension.php | 116 ++++++++++++++++++ .../Extension/xml/doctrine/dbal-1.0.xml | 35 ++++++ .../xml/swiftmailer/swiftmailer-1.0.xml | 91 ++++++++++++++ .../Loader/schema/doctrine/doctrine-1.0.xsd | 16 +++ .../schema/swiftmailer/swiftmailer-1.0.xsd | 53 ++++++++ 6 files changed, 384 insertions(+) create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/xml/doctrine/dbal-1.0.xml create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/xml/swiftmailer/swiftmailer-1.0.xml create mode 100644 src/Symfony/Components/DependencyInjection/Loader/schema/doctrine/doctrine-1.0.xsd create mode 100644 src/Symfony/Components/DependencyInjection/Loader/schema/swiftmailer/swiftmailer-1.0.xsd diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php b/src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php new file mode 100644 index 0000000000..0ea2d1b8c7 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php @@ -0,0 +1,73 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * DoctrineExtension is an extension for the Doctrine DBAL and ORM library. + * + * @package symfony + * @subpackage dependency_injection + * @author Fabien Potencier + */ +class DoctrineExtension extends LoaderExtension +{ + /** + * Loads the DBAL configuration. + * + * @param array $config A configuration array + * + * @return BuilderConfiguration A BuilderConfiguration instance + */ + public function dbalLoad($config) + { + $configuration = new BuilderConfiguration(); + + $loader = new XmlFileLoader(__DIR__.'/xml/doctrine'); + $configuration->merge($loader->load('dbal-1.0.xml')); + + foreach (array('dbname', 'driverClass', 'host', 'username', 'password') as $key) + { + if (isset($config[$key])) + { + $configuration->setParameter('doctrine.dbal.'.$key, $config[$key]); + } + } + + return $configuration; + } + + /** + * Returns the namespace to be used for this extension (XML namespace). + * + * @return string The XML namespace + */ + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/doctrine'; + } + + /** + * Returns the recommanded alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ + public function getAlias() + { + return 'doctrine'; + } +} diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php b/src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php new file mode 100644 index 0000000000..054731bcd8 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php @@ -0,0 +1,116 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * SwiftMailerExtension is an extension for the Swift Mailer library. + * + * @package symfony + * @subpackage dependency_injection + * @author Fabien Potencier + */ +class SwiftMailerExtension extends LoaderExtension +{ + /** + * Loads the Swift Mailer configuration. + * + * @param array $config A configuration array + * + * @return BuilderConfiguration A BuilderConfiguration instance + */ + public function mailerLoad($config) + { + $configuration = new BuilderConfiguration(); + + $loader = new XmlFileLoader(__DIR__.'/xml/swiftmailer'); + $configuration->merge($loader->load('swiftmailer-1.0.xml')); + + if (null === $config['transport']) + { + $config['transport'] = 'null'; + } + elseif (!isset($config['transport'])) + { + $config['transport'] = 'smtp'; + } + elseif ('gmail' === $config['transport']) + { + $config['encryption'] = 'ssl'; + $config['auth_mode'] = 'login'; + $config['host'] = 'smtp.gmail.com'; + $config['transport'] = 'smtp'; + } + + $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$config['transport']); + + if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) + { + $config['port'] = 465; + } + + foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) + { + if (isset($config[$key])) + { + $configuration->setParameter('swiftmailer.transport.'.$config['transport'].'.'.$key, $config[$key]); + } + } + + // spool? + if (isset($config['spool'])) + { + $type = isset($config['type']) ? $config['type'] : 'file'; + + $configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$config['transport']); + $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool'); + $configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type); + + foreach (array('path') as $key) + { + if (isset($config['spool'][$key])) + { + $configuration->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]); + } + } + } + + $configuration->setAlias(isset($config['alias']) ? $config['alias'] : 'mailer', 'swiftmailer.mailer'); + + return $configuration; + } + + /** + * Returns the namespace to be used for this extension (XML namespace). + * + * @return string The XML namespace + */ + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/swiftmailer'; + } + + /** + * Returns the recommanded alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ + public function getAlias() + { + return 'swift'; + } +} diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/doctrine/dbal-1.0.xml b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/doctrine/dbal-1.0.xml new file mode 100644 index 0000000000..7c244142f6 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/doctrine/dbal-1.0.xml @@ -0,0 +1,35 @@ + + + + + + root + + localhost + Doctrine\DBAL\Driver\PDOMySql\Driver + Doctrine\DBAL\Connection + Doctrine\DBAL\Configuration + Doctrine\Common\EventManager + + + + + + %doctrine.dbal.dbname% + %doctrine.dbal.user% + %doctrine.dbal.password% + %doctrine.dbal.host% + %doctrine.dbal.driver_class% + %doctrine.dbal.wrapper_class% + + + + + + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/swiftmailer/swiftmailer-1.0.xml b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/swiftmailer/swiftmailer-1.0.xml new file mode 100644 index 0000000000..81f9f63925 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/swiftmailer/swiftmailer-1.0.xml @@ -0,0 +1,91 @@ + + + + + + Swift_Mailer + + Swift_Transport_EsmtpTransport + Swift_Transport_SendmailTransport + Swift_Transport_MailTransport + + localhost + 25 + null + null + null + null + + Swift_FileSpool + + + + + + + + + + + + + + + %swiftmailer.transport.smtp.host% + %swiftmailer.transport.smtp.port% + %swiftmailer.transport.smtp.encryption% + %swiftmailer.transport.smtp.username% + %swiftmailer.transport.smtp.password% + %swiftmailer.transport.smtp.auth_mode% + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %swiftmailer.spool.file.path% + + + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/schema/doctrine/doctrine-1.0.xsd b/src/Symfony/Components/DependencyInjection/Loader/schema/doctrine/doctrine-1.0.xsd new file mode 100644 index 0000000000..01ad5fbdc1 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/schema/doctrine/doctrine-1.0.xsd @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/schema/swiftmailer/swiftmailer-1.0.xsd b/src/Symfony/Components/DependencyInjection/Loader/schema/swiftmailer/swiftmailer-1.0.xsd new file mode 100644 index 0000000000..5514ddd523 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/schema/swiftmailer/swiftmailer-1.0.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +