Explorar o código

[DependencyInjection] added some extensions

Fabien Potencier %!s(int64=15) %!d(string=hai) anos
pai
achega
111a023466

+ 73 - 0
src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace Symfony\Components\DependencyInjection\Loader\Extension;
+
+use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
+use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Components\DependencyInjection\BuilderConfiguration;
+
+/*
+ * This file is part of the symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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 <fabien.potencier@symfony-project.com>
+ */
+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';
+  }
+}

+ 116 - 0
src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace Symfony\Components\DependencyInjection\Loader\Extension;
+
+use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
+use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Components\DependencyInjection\BuilderConfiguration;
+
+/*
+ * This file is part of the symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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 <fabien.potencier@symfony-project.com>
+ */
+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';
+  }
+}

+ 35 - 0
src/Symfony/Components/DependencyInjection/Loader/Extension/xml/doctrine/dbal-1.0.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://www.symfony-project.org/schema/services"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.symfony-project.org/schema/services http://www.symfony-project.org/schema/services/services-1.0.xsd">
+
+  <parameters>
+    <parameter key="doctrine.dbal.user">root</parameter>
+    <parameter key="doctrine.dbal.password"></parameter>
+    <parameter key="doctrine.dbal.host">localhost</parameter>
+    <parameter key="doctrine.dbal.driver_class">Doctrine\DBAL\Driver\PDOMySql\Driver</parameter>
+    <parameter key="doctrine.dbal.wrapper_class">Doctrine\DBAL\Connection</parameter>
+    <parameter key="doctrine.dbal.configuration_class">Doctrine\DBAL\Configuration</parameter>
+    <parameter key="doctrine.dbal.event_manager_class">Doctrine\Common\EventManager</parameter>
+  </parameters>
+
+  <services>
+    <service id="doctrine.dbal.connection" class="Doctrine\DBAL\DriverManager" constructor="getConnection">
+      <argument type="collection">
+        <argument key="dbname">%doctrine.dbal.dbname%</argument>
+        <argument key="user">%doctrine.dbal.user%</argument>
+        <argument key="password">%doctrine.dbal.password%</argument>
+        <argument key="host">%doctrine.dbal.host%</argument>
+        <argument key="driverClass">%doctrine.dbal.driver_class%</argument>
+        <argument key="wrapperClass">%doctrine.dbal.wrapper_class%</argument>
+      </argument>
+      <argument type="service" id="doctrine.dbal.configuration" />
+      <argument type="service" id="doctrine.dbal.event_manager" />
+    </service>
+
+    <service id="doctrine.dbal.configuration" class="%doctrine.dbal.configuration_class%" />
+
+    <service id="doctrine.dbal.event_manager" class="%doctrine.dbal.event_manager_class%" />
+  </services>
+</container>

+ 91 - 0
src/Symfony/Components/DependencyInjection/Loader/Extension/xml/swiftmailer/swiftmailer-1.0.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<container xmlns="http://www.symfony-project.org/schema/services"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.symfony-project.org/schema/services http://www.symfony-project.org/schema/services/services-1.0.xsd">
+
+  <parameters>
+    <parameter key="swiftmailer.class">Swift_Mailer</parameter>
+
+    <parameter key="swiftmailer.transport.smtp.class">Swift_Transport_EsmtpTransport</parameter>
+    <parameter key="swiftmailer.transport.sendmail.class">Swift_Transport_SendmailTransport</parameter>
+    <parameter key="swiftmailer.transport.mail.class">Swift_Transport_MailTransport</parameter>
+
+    <parameter key="swiftmailer.transport.smtp.host">localhost</parameter>
+    <parameter key="swiftmailer.transport.smtp.port">25</parameter>
+    <parameter key="swiftmailer.transport.smtp.encryption">null</parameter>
+    <parameter key="swiftmailer.transport.smtp.username">null</parameter>
+    <parameter key="swiftmailer.transport.smtp.password">null</parameter>
+    <parameter key="swiftmailer.transport.smtp.auth_mode">null</parameter>
+
+    <parameter key="swiftmailer.spool.file.class">Swift_FileSpool</parameter>
+  </parameters>
+
+  <services>
+    <service id="swiftmailer.mailer" class="%swiftmailer.class%">
+      <argument type="service" id="swiftmailer.transport" />
+    </service>
+
+    <service id="swiftmailer.transport.smtp" class="%swiftmailer.transport.smtp.class%">
+      <argument type="service" id="swiftmailer.transport.buffer" />
+      <argument type="collection">
+        <argument type="service" id="swiftmailer.transport.authhandler" />
+      </argument>
+      <argument type="service" id="swiftmailer.transport.eventdispatcher" />
+
+      <call method="setHost"><argument>%swiftmailer.transport.smtp.host%</argument></call>
+      <call method="setPort"><argument>%swiftmailer.transport.smtp.port%</argument></call>
+      <call method="setEncryption"><argument>%swiftmailer.transport.smtp.encryption%</argument></call>
+      <call method="setUsername"><argument>%swiftmailer.transport.smtp.username%</argument></call>
+      <call method="setPassword"><argument>%swiftmailer.transport.smtp.password%</argument></call>
+      <call method="setAuthMode"><argument>%swiftmailer.transport.smtp.auth_mode%</argument></call>
+    </service>
+
+    <service id="swiftmailer.transport.sendmail" class="%swiftmailer.transport.sendmail.class%">
+      <argument type="service" id="swiftmailer.transport.buffer" />
+      <argument type="service" id="swiftmailer.transport.eventdispatcher" />
+    </service>
+
+    <service id="swiftmailer.transport.mail" class="%swiftmailer.transport.mail.class%">
+      <argument type="service" id="swiftmailer.transport.mailinvoker" />
+      <argument type="service" id="swiftmailer.transport.eventdispatcher" />
+    </service>
+
+    <service id="swiftmailer.transport.failover" class="Swift_Transport_FailoverTransport" />
+
+    <service id="swiftmailer.transport.mailinvoker" class="Swift_Transport_SimpleMailInvoker" />
+
+    <service id="swiftmailer.transport.buffer" class="Swift_Transport_StreamBuffer">
+      <argument type="service" id="swiftmailer.transport.replacementfactory" />
+    </service>
+
+    <service id="swiftmailer.transport.authhandler" class="Swift_Transport_Esmtp_AuthHandler">
+      <argument type="collection">
+        <argument type="service"><service class="Swift_Transport_Esmtp_Auth_CramMd5Authenticator" /></argument>
+        <argument type="service"><service class="Swift_Transport_Esmtp_Auth_LoginAuthenticator" /></argument>
+        <argument type="service"><service class="Swift_Transport_Esmtp_Auth_PlainAuthenticator" /></argument>
+      </argument>
+    </service>
+
+    <service id="swiftmailer.transport.eventdispatcher" class="Swift_Events_SimpleEventDispatcher" />
+
+    <service id="swiftmailer.transport.replacementfactory" class="Swift_StreamFilters_StringReplacementFilterFactory" />
+
+    <service id="swiftmailer.transport.spool" class="Swift_Transport_SpoolTransport">
+      <argument type="service" id="swiftmailer.transport.eventdispatcher" />
+      <argument type="service" id="swiftmailer.spool" />
+    </service>
+
+    <service id="swiftmailer.transport.null" class="Swift_Transport_NullTransport">
+      <argument type="service" id="swiftmailer.transport.eventdispatcher" />
+    </service>
+
+    <service id="swiftmailer.spool.file" class="%swiftmailer.spool.file.class%">
+      <argument>%swiftmailer.spool.file.path%</argument>
+    </service>
+
+    <service id="swiftmailer.transport" alias="swiftmailer.transport.smtp" />
+
+    <service id="swiftmailer.spool" alias="swiftmailer.spool.file" />
+  </services>
+</container>

+ 16 - 0
src/Symfony/Components/DependencyInjection/Loader/schema/doctrine/doctrine-1.0.xsd

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<xsd:schema xmlns="http://www.symfony-project.org/schema/doctrine"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="http://www.symfony-project.org/schema/doctrine"
+    elementFormDefault="qualified">
+
+  <xsd:element name="dbal" type="dbal" />
+
+  <xsd:complexType name="dbal">
+    <xsd:attribute name="dbname" type="xsd:string" />
+    <xsd:attribute name="host" type="xsd:string" />
+    <xsd:attribute name="username" type="xsd:string" />
+    <xsd:attribute name="password" type="xsd:string" />
+  </xsd:complexType>
+</xsd:schema>

+ 53 - 0
src/Symfony/Components/DependencyInjection/Loader/schema/swiftmailer/swiftmailer-1.0.xsd

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<xsd:schema xmlns="http://www.symfony-project.org/schema/swiftmailer"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="http://www.symfony-project.org/schema/swiftmailer"
+    elementFormDefault="qualified">
+
+  <xsd:element name="mailer" type="mailer" />
+
+  <xsd:complexType name="mailer">
+    <xsd:sequence>
+      <xsd:element name="username" type="xsd:string" minOccurs="0" maxOccurs="1" />
+      <xsd:element name="password" type="xsd:string" minOccurs="0" maxOccurs="1" />
+      <xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
+      <xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
+      <xsd:element name="encryption" type="encryption" minOccurs="0" maxOccurs="1" />
+      <xsd:element name="auth_mode" type="auth_mode" minOccurs="0" maxOccurs="1" />
+
+      <xsd:element name="spool" type="spool" minOccurs="0" maxOccurs="1" />
+    </xsd:sequence>
+
+    <xsd:attribute name="transport" type="xsd:string" />
+    <xsd:attribute name="delivery_strategy" type="delivery_strategy" />
+  </xsd:complexType>
+
+  <xsd:complexType name="spool">
+    <xsd:attribute name="path" type="xsd:string" />
+  </xsd:complexType>
+
+  <xsd:simpleType name="encryption">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="tls" />
+      <xsd:enumeration value="ssl" />
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="auth_mode">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="plain" />
+      <xsd:enumeration value="login" />
+      <xsd:enumeration value="cram-md5" />
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:simpleType name="delivery_strategy">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="realtime" />
+      <xsd:enumeration value="spool" />
+      <xsd:enumeration value="single_address" />
+      <xsd:enumeration value="none" />
+    </xsd:restriction>
+  </xsd:simpleType>
+</xsd:schema>