Selaa lähdekoodia

[DependencyInjection] made extension entry points configurable

Fabien Potencier 15 vuotta sitten
vanhempi
commit
9a478f134a

+ 7 - 2
src/Symfony/Components/DependencyInjection/Loader/Extension/DoctrineExtension.php

@@ -24,6 +24,11 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
  */
 class DoctrineExtension extends LoaderExtension
 {
+  protected $resources = array(
+    'dbal' => 'dbal-1.0.xml',
+    'orm'  => 'orm-1.0.xml',
+  );
+
   protected $alias;
 
   public function setAlias($alias)
@@ -47,7 +52,7 @@ class DoctrineExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/doctrine');
-    $configuration->merge($loader->load('dbal-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['dbal']));
 
     foreach (array('dbname', 'host', 'username', 'password', 'path', 'port') as $key)
     {
@@ -90,7 +95,7 @@ class DoctrineExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/doctrine');
-    $configuration->merge($loader->load('orm-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['orm']));
 
     return $configuration;
   }

+ 5 - 1
src/Symfony/Components/DependencyInjection/Loader/Extension/SwiftMailerExtension.php

@@ -24,6 +24,10 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
  */
 class SwiftMailerExtension extends LoaderExtension
 {
+  protected $resources = array(
+    'mailer' => 'swiftmailer-1.0.xml',
+  );
+
   /**
    * Loads the Swift Mailer configuration.
    *
@@ -44,7 +48,7 @@ class SwiftMailerExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/swiftmailer');
-    $configuration->merge($loader->load('swiftmailer-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['mailer']));
 
     if (null === $config['transport'])
     {

+ 4 - 1
src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php

@@ -25,6 +25,9 @@ use Symfony\Components\DependencyInjection\Reference;
  */
 class SymfonyTemplatingExtension extends LoaderExtension
 {
+  protected $resources = array(
+    'templating' => 'templating-1.0.xml',
+  );
   protected $defaultHelpers = array();
   protected $alias;
 
@@ -60,7 +63,7 @@ class SymfonyTemplatingExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/symfony');
-    $configuration->merge($loader->load('templating-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['templating']));
 
     // path for the filesystem loader
     if (isset($config['path']))

+ 7 - 2
src/Symfony/Components/DependencyInjection/Loader/Extension/ZendExtension.php

@@ -24,6 +24,11 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
  */
 class ZendExtension extends LoaderExtension
 {
+  protected $resources = array(
+    'logger' => 'logger-1.0.xml',
+    'mail'   => 'mail-1.0.xml',
+  );
+
   /**
    * Loads the logger configuration.
    *
@@ -40,7 +45,7 @@ class ZendExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/zend');
-    $configuration->merge($loader->load('logger-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['logger']));
 
     if (isset($config['priority']))
     {
@@ -76,7 +81,7 @@ class ZendExtension extends LoaderExtension
     $configuration = new BuilderConfiguration();
 
     $loader = new XmlFileLoader(__DIR__.'/xml/zend');
-    $configuration->merge($loader->load('mail-1.0.xml'));
+    $configuration->merge($loader->load($this->resources['logger']));
 
     if (isset($config['transport']))
     {

+ 3 - 7
src/Symfony/Components/DependencyInjection/Loader/Extension/xml/zend/logger-1.0.xml

@@ -11,16 +11,12 @@
 
   <services>
     <service id="zend.logger" class="%zend.logger.class%">
-      <call method="addWriter">
-        <argument type="service" id="zend.logger.writer_stream" />
-      </call>
+      <call method="addWriter"><argument type="service" id="zend.logger.writer.filesystem" /></call>
     </service>
 
-    <service id="zend.logger.writer_stream" class="Zend_Log_Writer_Stream">
+    <service id="zend.logger.writer.filesystem" class="Zend_Log_Writer_Stream">
       <argument>%zend.logger.path%</argument>
-      <call method="addFilter">
-        <argument type="service" id="zend.logger.filter" />
-      </call>
+      <call method="addFilter"><argument type="service" id="zend.logger.filter" /></call>
     </service>
 
     <service id="zend.logger.filter" class="Zend_Log_Filter_Priority">

+ 13 - 0
src/Symfony/Components/DependencyInjection/Loader/LoaderExtension.php

@@ -20,6 +20,19 @@ namespace Symfony\Components\DependencyInjection\Loader;
  */
 abstract class LoaderExtension implements LoaderExtensionInterface
 {
+  protected $resources = array();
+
+  /**
+   * Sets a configuration entry point for the given extension name.
+   *
+   * @param string The configuration extension name
+   * @param mixed  A resource
+   */
+  public function setConfiguration($name, $resource)
+  {
+    $this->resources[$name] = $resource;
+  }
+
   /**
    * Loads a specific configuration.
    *

+ 8 - 0
src/Symfony/Components/DependencyInjection/Loader/LoaderExtensionInterface.php

@@ -20,6 +20,14 @@ namespace Symfony\Components\DependencyInjection\Loader;
  */
 interface LoaderExtensionInterface
 {
+  /**
+   * Sets a configuration entry point for the given extension name.
+   *
+   * @param string The configuration extension name
+   * @param mixed  A resource
+   */
+  public function setConfiguration($name, $resource);
+
   /**
    * Loads a specific configuration.
    *