8000 [DependencyInjection] added some extensions · Dahipster/symfony@104ee29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 104ee29

Browse files
committed
[DependencyInjection] added some extensions
1 parent 6092709 commit 104ee29

File tree

6 files changed

+384
-0
lines changed

6 files changed

+384
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Symfony\Components\DependencyInjection\Loader\Extension;
4+
5+
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
6+
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
7+
use Symfony\Components\DependencyInjection\BuilderConfiguration;
8+
9+
/*
10+
* This file is part of the symfony framework.
11+
*
12+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
13+
*
14+
* This source file is subject to the MIT license that is bundled
15+
* with this source code in the file LICENSE.
16+
*/
17+
18+
/**
19+
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
20+
*
21+
* @package symfony
22+
* @subpackage dependency_injection
23+
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
24+
*/
25+
class DoctrineExtension extends LoaderExtension
26+
{
27+
/**
28+
* Loads the DBAL configuration.
29+
*
30+
* @param array $config A configuration array
31+
*
32+
* @return BuilderConfiguration A BuilderConfiguration instance
33+
*/
34+
public function dbalLoad($config)
35+
{
36+
$configuration = new BuilderConfiguration();
37+
38+
$loader = new XmlFileLoader(__DIR__.'/xml/doctrine');
39+
$configuration->merge($loader->load('dbal-1.0.xml'));
40+
41+
foreach (array('dbname', 'driverClass', 'host', 'username', 'password') as $key)
42+
{
43+
if (isset($config[$key]))
44+
{
45+
$configuration->setParameter('doctrine.dbal.'.$key, $config[$key]);
46+
}
47+
}
48+
49+
return $configuration;
50+
}
51+
52+
/**
53+
* Returns the namespace to be used for this extension (XML namespace).
54+
*
55+
* @return string The XML namespace
56+
*/
57+
public function getNamespace()
58+
{
59+
return 'http://www.symfony-project.org/schema/doctrine';
60+
}
61+
62+
/**
63+
* Returns the recommanded alias to use in XML.
64+
*
65+
* This alias is also the mandatory prefix to use when using YAML.
66+
*
67+
* @return string The alias
68+
*/
69+
public function getAlias()
70+
{
71+
return 'doctrine';
72+
}
73+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace Symfony\Components\DependencyInjection\Loader\Extension;
4+
5+
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
6+
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
7+
use Symfony\Components\DependencyInjection\BuilderConfiguration;
8+
9+
/*
10+
* This file is part of the symfony framework.
11+
*
12+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
13+
*
14+
* This source file is subject to the MIT license that is bundled
15+
* with this source code in the file LICENSE.
16+
*/
17+
18+
/**
19+
* SwiftMailerExtension is an extension for the Swift Mailer library.
20+
*
21+
* @package symfony
22+
* @subpackage dependency_injection
23+
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
24+
*/
25+
class SwiftMailerExtension extends LoaderExtension
26+
{
27+
/**
28+
* Loads the Swift Mailer configuration.
29+
*
30+
* @param array $config A configuration array
31+
*
32+
* @return BuilderConfiguration A BuilderConfiguration instance
33+
*/
34+
public function mailerLoad($config)
35+
{
36+
$configuration = new BuilderConfiguration();
37+
38+
$loader = new XmlFileLoader(__DIR__.'/xml/swiftmailer');
39+
$configuration->merge($loader->load('swiftmailer-1.0.xml'));
40+
41+
if (null === $config['transport'])
42+
{
43+
$config['transport'] = 'null';
44+
}
45+
elseif (!isset($config['transport']))
46+
{
47+
$config['transport'] = 'smtp';
48+
}
49+
elseif ('gmail' === $config['transport'])
50+
{
51+
$config['encryption'] = 'ssl';
52+
$config['auth_mode'] = 'login';
53+
$config['host'] = 'smtp.gmail.com';
54+
$config['transport'] = 'smtp';
55+
}
56+
57+
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$config['transport']);
58+
59+
if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port']))
60+
{
61+
$config['port'] = 465;
62+
}
63+
64+
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key)
65+
{
66+
if (isset($config[$key]))
67+
{
68+
$configuration->setParameter('swiftmailer.transport.'.$config['transport'].'.'.$key, $config[$key]);
69+
}
70+
}
71+
72+
// spool?
73+
if (isset($config['spool']))
74+
{
75+
$type = isset($config['type']) ? $config['type'] : 'file';
76+
77+
$configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$config['transport']);
78+
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
79+
$configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
80+
81+
foreach (array('path') as $key)
82+
{
83+
if (isset($config['spool'][$key]))
84+
{
85+
$configuration->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]);
86+
}
87+
}
88+
}
89+
90+
$configuration->setAlias(isset($config['alias']) ? $config['alias'] : 'mailer', 'swiftmailer.mailer');
91+
92+
return $configuration;
93+
}
94+
95+
/**
96+
* Returns the namespace to be used for this extension (XML namespace).
97+
*
98+
* @return string The XML namespace
99+
*/
100+
public function getNamespace()
101+
{
102+
return 'http://www.symfony-project.org/schema/swiftmailer';
103+
}
104+
105+
/**
106+
* Returns the recommanded alias to use in XML.
107+
*
108+
* This alias is also the mandatory prefix to use when using YAML.
109+
*
110+
* @return string The alias
111+
*/
112+
public function getAlias()
113+
{
114+
return 'swift';
115+
}
116+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://www.symfony-project.org/schema/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.symfony-project.org/schema/services http://www.symfony-project.org/schema/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="doctrine.dbal.user">root</parameter>
9+
<parameter key="doctrine.dbal.password"></parameter>
10+
<parameter key="doctrine.dbal.host">localhost</parameter>
11+
<parameter key="doctrine.dbal.driver_class">Doctrine\DBAL\Driver\PDOMySql\Driver</parameter>
12+
<parameter key="doctrine.dbal.wrapper_class">Doctrine\DBAL\Connection</parameter>
13+
<parameter key="doctrine.dbal.configuration_class">Doctrine\DBAL\Configuration</parameter>
14+
<parameter key="doctrine.dbal.event_manager_class">Doctrine\Common\EventManager</parameter>
15+
</parameters>
16+
17+
<services>
18+
<service id="doctrine.dbal.connection" class="Doctrine\DBAL\DriverManager" constructor="getConnection">
19+
<argument type="collection">
20+
<argument key="dbname">%doctrine.dbal.dbname%</argument>
21+
<argument key="user">%doctrine.dbal.user%</argument>
22+
<argument key="password">%doctrine.dbal.password%</argument>
23+
<argument key="host">%doctrine.dbal.host%</argument>
24+
<argument key="driverClass">%doctrine.dbal.driver_class%</argument>
25+
<argument key="wrapperClass">%doctrine.dbal.wrapper_class%</argument>
26+
</argument>
27+
<argument type="service" id="doctrine.dbal.configuration" />
28+
<argument type="service" id="doctrine.dbal.event_manager" />
29+
</service>
30+
31+
<service id="doctrine.dbal.configuration" class="%doctrine.dbal.configuration_class%" />
32+
33+
<service id="doctrine.dbal.event_manager" class="%doctrine.dbal.event_manager_class%" />
34+
</services>
35+
</container>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<container xmlns="http://www.symfony-project.org/schema/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.symfony-project.org/schema/services http://www.symfony-project.org/schema/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="swiftmailer.class">Swift_Mailer</parameter>
9+
10+
<parameter key="swiftmailer.transport.smtp.class">Swift_Transport_EsmtpTransport</parameter>
11+
<parameter key="swiftmailer.transport.sendmail.class">Swift_Transport_SendmailTransport</parameter>
12+
<parameter key="swiftmailer.transport.mail.class">Swift_Transport_MailTransport</parameter>
13+
14+
<parameter key="swiftmailer.transport.smtp.host">localhost</parameter>
15+
<parameter key="swiftmailer.transport.smtp.port">25</parameter>
16+
<parameter key="swiftmailer.transport.smtp.encryption">null</parameter>
17+
<parameter key="swiftmailer.transport.smtp.username">null</parameter>
18+
<parameter key="swiftmailer.transport.smtp.password">null</parameter>
19+
<parameter key="swiftmailer.transport.smtp.auth_mode">null</parameter>
20+
21+
<parameter key="swiftmailer.spool.file.class">Swift_FileSpool</parameter>
22+
</parameters>
23+
24+
<services>
25+
<service id="swiftmailer.mailer" class="%swiftmailer.class%">
26+
<argument type="service" id="swiftmailer.transport" />
27+
</service>
28+
29+
<service id="swiftmailer.transport.smtp" class="%swiftmailer.transport.smtp.class%">
30+
<argument type="service" id="swiftmailer.transport.buffer" />
31+
<argument type="collection">
32+
<argument type 10000 ="service" id="swiftmailer.transport.authhandler" />
33+
</argument>
34+
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
35+
36+
<call method="setHost"><argument>%swiftmailer.transport.smtp.host%</argument></call>
37+
<call method="setPort"><argument>%swiftmailer.transport.smtp.port%</argument></call>
38+
<call method="setEncryption"><argument>%swiftmailer.transport.smtp.encryption%</argument></call>
39+
<call method="setUsername"><argument>%swiftmailer.transport.smtp.username%</argument></call>
40+
<call method="setPassword"><argument>%swiftmailer.transport.smtp.password%</argument></call>
41+
<call method="setAuthMode"><argument>%swiftmailer.transport.smtp.auth_mode%</argument></call>
42+
</service>
43+
44+
<service id="swiftmailer.transport.sendmail" class="%swiftmailer.transport.sendmail.class%">
45+
<argument type="service" id="swiftmailer.transport.buffer" />
46+
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
47+
</service>
48+
49+
<service id="swiftmailer.transport.mail" class="%swiftmailer.transport.mail.class%">
50+
<argument type="service" id="swiftmailer.transport.mailinvoker" />
51+
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
52+
</service>
53+
54+
<service id="swiftmailer.transport.failover" class="Swift_Transport_FailoverTransport" />
55+
56+
<service id="swiftmailer.transport.mailinvoker" class="Swift_Transport_SimpleMailInvoker" />
57+
58+
<service id="swiftmailer.transport.buffer" class="Swift_Transport_StreamBuffer">
59+
<argument type="service" id="swiftmailer.transport.replacementfactory" />
60+
</service>
61+
62+
<service id="swiftmailer.transport.authhandler" class="Swift_Transport_Esmtp_AuthHandler">
63+
<argument type="collection">
64+
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_CramMd5Authenticator" /></argument>
65+
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_LoginAuthenticator" /></argument>
66+
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_PlainAuthenticator" /></argument>
67+
</argument>
68+
</service>
69+
70+
<service id="swiftmailer.transport.eventdispatcher" class="Swift_Events_SimpleEventDispatcher" />
71+
72+
<service id="swiftmailer.transport.replacementfactory" class="Swift_StreamFilters_StringReplacementFilterFactory" />
73+
74+
<service id="swiftmailer.transport.spool" class="Swift_Transport_SpoolTransport">
75+
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
76+
<argument type="service" id="swiftmailer.spool" />
77+
</service>
78+
79+
<service id="swiftmailer.transport.null" class="Swift_Transport_NullTransport">
80+
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
81+
</service>
82+
83+
<service id="swiftmailer.spool.file" class="%swiftmailer.spool.file.class%">
84+
<argument>%swiftmailer.spool.file.path%</argument>
85+
</service>
86+
87+
<service id="swiftmailer.transport" alias="swiftmailer.transport.smtp" />
88+
89+
<service id="swiftmailer.spool" alias="swiftmailer.spool.file" />
90+
</services>
91+
</container>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<xsd:schema xmlns="http://www.symfony-project.org/schema/doctrine"
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
targetNamespace="http://www.symfony-project.org/schema/doctrine"
6+
elementFormDefault="qualified">
7+
8+
<xsd:element name="dbal" type="dbal" />
9+
10+
<xsd:complexType name="dbal">
11+
<xsd:attribute name="dbname" type="xsd:string" />
12+
<xsd:attribute name="host" type="xsd:string" />
13+
<xsd:attribute name="username" type="xsd:string" />
14+
<xsd:attribute name="password" type="xsd:string" />
15+
</xsd:complexType>
16+
</xsd:schema>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<xsd:schema xmlns="http://www.symfony-project.org/schema/swiftmailer"
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
targetNamespace="http://www.symfony-project.org/schema/swiftmailer"
6+
elementFormDefault="qualified">
7+
8+
<xsd:element name="mailer" type="mailer" />
9+
10+
<xsd:complexType name="mailer">
11+
<xsd:sequence>
12+
<xsd:element name="username" type="xsd:string" minOccurs="0" maxOccurs="1" />
13+
<xsd:element name="password" type="xsd:string" minOccurs="0" maxOccurs="1" />
14+
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
15+
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
16+
<xsd:element name="encryption" type="encryption" minOccurs="0" maxOccurs="1" />
17+
<xsd:element name="auth_mode" type="auth_mode" minOccurs="0" maxOccurs="1" />
18+
19+
<xsd:element name="spool" type="spool" minOccurs="0" maxOccurs="1" />
20+
</xsd:sequence>
21+
22+
<xsd:attribute name="transport" type="xsd:string" />
23+
<xsd:attribute name="delivery_strategy" type="delivery_strategy" />
24+
</xsd:complexType>
25+
26+
<xsd:complexType name="spool">
27+
<xsd:attribute name="path" type="xsd:string" />
28+
</xsd:complexType>
29+
30+
<xsd:simpleType name="encryption">
31+
<xsd:restriction base="xsd:string">
32+
<xsd:enumeration value="tls" />
33+
<xsd:enumeration value="ssl" />
34+
</xsd:restriction>
35+
</xsd:simpleType>
36+
37+
<xsd:simpleType name="auth_mode">
38+
<xsd:restriction base="xsd:string">
39+
<xsd:enumeration value="plain" />
40+
<xsd:enumeration value="login" />
41+
<xsd:enumeration value="cram-md5" />
42+
</xsd:restriction>
43+
</xsd:simpleType>
44+
45+
<xsd:simpleType name="delivery_strategy">
46+
<xsd:restriction base="xsd:string">
47+
<xsd:enumeration value="realtime" />
48+
<xsd:enumeration value="spool" />
49+
<xsd:enumeration value="single_address" />
50+
<xsd:enumeration value="none" />
51+
</xsd:restriction>
52+
</xsd:simpleType>
53+
</xsd:schema>

0 commit comments

Comments
 (0)
0