From 4cfae0a2668208cb66cef09772a59b8ab641b6e6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Jan 2010 08:18:05 +0100 Subject: [PATCH] [DependencyInjection] added an extension for the Zend Framework --- .../Loader/Extension/ZendExtension.php | 121 ++++++++++++++++++ .../Loader/Extension/xml/zend/logger-1.0.xml | 32 +++++ .../Loader/Extension/xml/zend/mail-1.0.xml | 48 +++++++ .../Loader/schema/zend/zend-1.0.xsd | 65 ++++++++++ 4 files changed, 266 insertions(+) create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/ZendExtension.php create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/logger-1.0.xml create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/mail-1.0.xml create mode 100644 src/Symfony/Components/DependencyInjection/Loader/schema/zend/zend-1.0.xsd diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/ZendExtension.php b/src/Symfony/Components/DependencyInjection/Loader/Extension/ZendExtension.php new file mode 100644 index 0000000000..8d8ecf9495 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/ZendExtension.php @@ -0,0 +1,121 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * ZendExtension is an extension for the Zend Framework libraries. + * + * @package symfony + * @subpackage dependency_injection + * @author Fabien Potencier + */ +class ZendExtension extends LoaderExtension +{ + /** + * Loads the logger configuration. + * + * @param array $config A configuration array + * + * @return BuilderConfiguration A BuilderConfiguration instance + */ + public function loggerLoad($config) + { + $configuration = new BuilderConfiguration(); + + $loader = new XmlFileLoader(__DIR__.'/xml/zend'); + $configuration->merge($loader->load('logger-1.0.xml')); + + if (isset($config['priority'])) + { + $configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\Zend_Log::'.strtoupper($config['priority']))); + } + + if (isset($config['path'])) + { + $configuration->setParameter('zend.logger.path', $config['path']); + } + + return $configuration; + } + + /** + * Loads the mail configuration. + * + * @param array $config A configuration array + * + * @return BuilderConfiguration A BuilderConfiguration instance + */ + public function mailLoad($config) + { + $configuration = new BuilderConfiguration(); + + $loader = new XmlFileLoader(__DIR__.'/xml/zend'); + $configuration->merge($loader->load('mail-1.0.xml')); + + if (isset($config['transport'])) + { + if ('gmail' === $config['transport']) + { + $config['ssl'] = 'ssl'; + $config['auth'] = 'login'; + $config['host'] = 'smtp.gmail.com'; + + $configuration->setAlias('zend.mail.transport', 'zend.mail.transport.smtp.ssl'); + } + else + { + if (isset($config['ssl']) && $config['ssl']) + { + $config['transport'] = $config['transport'].'.ssl'; + } + $configuration->setAlias('zend.mail.transport', 'zend.mail.transport.'.$config['transport']); + } + } + + if (isset($config['ssl'])) + { + if (true === $config['ssl'] || 'ssl' === $config['ssl']) + { + $config['ssl'] = 'ssl'; + if (!isset($config['port'])) + { + $config['port'] = 465; + } + } + $configuration->setParameter('zend.mail.smtp.ssl', $config['ssl']); + } + + foreach (array('port', 'host', 'username', 'password', 'auth') as $key) + { + if (isset($config[$key])) + { + $configuration->setParameter('zend.mail.smtp.'.$key, $config[$key]); + } + } + + return $configuration; + } + + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/zend'; + } + + public function getAlias() + { + return 'zend'; + } +} diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/logger-1.0.xml b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/logger-1.0.xml new file mode 100644 index 0000000000..5352dfd494 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/logger-1.0.xml @@ -0,0 +1,32 @@ + + + + + + \Zend_Log + \Zend_Log::CRIT + + + + + + + + + + + %zend.logger.path% + + + + + + + %zend.logger.priority% + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/mail-1.0.xml b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/mail-1.0.xml new file mode 100644 index 0000000000..fba8776fa8 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/mail-1.0.xml @@ -0,0 +1,48 @@ + + + + + + Zend_Mail + Zend_Mail_Transport_Smtp + localhost + null + null + null + null + 25 + + + + + + + + + + + %zend.mail.smtp.host% + + %zend.mail.smtp.auth% + %zend.mail.smtp.username% + %zend.mail.smtp.password% + %zend.mail.smtp.port% + + + + + %zend.mail.smtp.host% + + %zend.mail.smtp.auth% + %zend.mail.smtp.username% + %zend.mail.smtp.password% + %zend.mail.smtp.ssl% + %zend.mail.smtp.port% + + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/schema/zend/zend-1.0.xsd b/src/Symfony/Components/DependencyInjection/Loader/schema/zend/zend-1.0.xsd new file mode 100644 index 0000000000..c8233b5aff --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/schema/zend/zend-1.0.xsd @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +