Initial commit with Symfony 2.1+Vendors

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-07-01 09:52:20 +02:00
commit 082a0130c2
5381 changed files with 416709 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/**
* RegisterPluginsPass registers Swiftmailer plugins.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RegisterPluginsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('swiftmailer.mailer')) {
return;
}
$definition = $container->findDefinition('swiftmailer.transport');
foreach ($container->findTaggedServiceIds('swiftmailer.plugin') as $id => $args) {
$definition->addMethodCall('registerPlugin', array(new Reference($id)));
}
}
}

View File

@@ -0,0 +1,91 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This class contains the configuration information for the bundle
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class Configuration implements ConfigurationInterface
{
private $debug;
/**
* Constructor.
*
* @param Boolean $debug The kernel.debug value
*/
public function __construct($debug)
{
$this->debug = (Boolean) $debug;
}
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('swiftmailer');
$rootNode
->children()
->scalarNode('transport')->defaultValue('smtp')->end()
->scalarNode('username')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->scalarNode('host')->defaultValue('localhost')->end()
->scalarNode('port')->defaultFalse()->end()
->scalarNode('encryption')
->defaultNull()
->validate()
->ifNotInArray(array('tls', 'ssl', null))
->thenInvalid('The %s encryption is not supported')
->end()
->end()
->scalarNode('auth_mode')
->defaultNull()
->validate()
->ifNotInArray(array('plain', 'login', 'cram-md5', null))
->thenInvalid('The %s authentication mode is not supported')
->end()
->end()
->arrayNode('spool')
->children()
->scalarNode('type')->defaultValue('file')->end()
->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/spool')->end()
->end()
->end()
->scalarNode('sender_address')->end()
->arrayNode('antiflood')
->children()
->scalarNode('threshold')->defaultValue(99)->end()
->scalarNode('sleep')->defaultValue(0)->end()
->end()
->end()
->scalarNode('delivery_address')->end()
->booleanNode('disable_delivery')->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->end()
;
return $treeBuilder;
}
}

View File

@@ -0,0 +1,155 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
/**
* SwiftmailerExtension is an extension for the SwiftMailer library.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SwiftmailerExtension extends Extension
{
/**
* Loads the Swift Mailer configuration.
*
* Usage example:
*
* <swiftmailer:config transport="gmail">
* <swiftmailer:username>fabien</swift:username>
* <swiftmailer:password>xxxxx</swift:password>
* <swiftmailer:spool path="/path/to/spool/" />
* </swiftmailer:config>
*
* @param array $configs An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('swiftmailer.xml');
$container->setAlias('mailer', 'swiftmailer.mailer');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
if (null === $config['transport']) {
$transport = 'null';
} elseif ('gmail' === $config['transport']) {
$config['encryption'] = 'ssl';
$config['auth_mode'] = 'login';
$config['host'] = 'smtp.gmail.com';
$transport = 'smtp';
} else {
$transport = $config['transport'];
}
if (isset($config['disable_delivery']) && $config['disable_delivery']) {
$transport = 'null';
}
if ('smtp' === $transport) {
$loader->load('smtp.xml');
}
if (in_array($transport, array('smtp', 'mail', 'sendmail', 'null'))) {
// built-in transport
$transport = 'swiftmailer.transport.'.$transport;
}
$container->setAlias('swiftmailer.transport', $transport);
if (false === $config['port']) {
$config['port'] = 'ssl' === $config['encryption'] ? 465 : 25;
}
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
$container->setParameter('swiftmailer.transport.smtp.'.$key, $config[$key]);
}
// spool?
if (isset($config['spool'])) {
$type = $config['spool']['type'];
$loader->load('spool.xml');
if ($type === 'file') {
$loader->load('spool_file.xml');
} elseif ($type === 'memory') {
$loader->load('spool_memory.xml');
}
$container->setAlias('swiftmailer.transport.real', $transport);
$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
$container->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
foreach (array('path') as $key) {
$container->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]);
}
}
$container->setParameter('swiftmailer.spool.enabled', isset($config['spool']));
// antiflood?
if (isset($config['antiflood'])) {
$container->setParameter('swiftmailer.plugin.antiflood.threshold', $config['antiflood']['threshold']);
$container->setParameter('swiftmailer.plugin.antiflood.sleep', $config['antiflood']['sleep']);
$container->getDefinition('swiftmailer.plugin.antiflood')->addTag('swiftmailer.plugin');
}
if ($config['logging']) {
$container->getDefinition('swiftmailer.plugin.messagelogger')->addTag('swiftmailer.plugin');
$container->findDefinition('swiftmailer.data_collector')->addTag('data_collector', array('template' => 'SwiftmailerBundle:Collector:swiftmailer', 'id' => 'swiftmailer'));
}
if (isset($config['sender_address']) && $config['sender_address']) {
$container->setParameter('swiftmailer.sender_address', $config['sender_address']);
$container->getDefinition('swiftmailer.plugin.impersonate')->addTag('swiftmailer.plugin');
} else {
$container->setParameter('swiftmailer.sender_address', null);
}
if (isset($config['delivery_address']) && $config['delivery_address']) {
$container->setParameter('swiftmailer.single_address', $config['delivery_address']);
$container->getDefinition('swiftmailer.plugin.redirecting')->addTag('swiftmailer.plugin');
} else {
$container->setParameter('swiftmailer.single_address', null);
}
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
}
/**
* Returns the namespace to be used for this extension (XML namespace).
*
* @return string The XML namespace
*/
public function getNamespace()
{
return 'http://symfony.com/schema/dic/swiftmailer';
}
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
}