Explorar o código

cleaned up some code to make use of Symfony 2.1 features

Johannes Schmitt %!s(int64=13) %!d(string=hai) anos
pai
achega
4880923323

+ 4 - 20
DependencyInjection/JMSSerializerExtension.php

@@ -18,7 +18,7 @@
 
 
 namespace JMS\SerializerBundle\DependencyInjection;
 namespace JMS\SerializerBundle\DependencyInjection;
 
 
-use JMS\SerializerBundle\SerializerBundleAwareInterface;
+use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
 use Symfony\Component\HttpKernel\KernelInterface;
 use Symfony\Component\HttpKernel\KernelInterface;
 use Symfony\Component\DependencyInjection\Alias;
 use Symfony\Component\DependencyInjection\Alias;
 use Symfony\Component\DependencyInjection\DefinitionDecorator;
 use Symfony\Component\DependencyInjection\DefinitionDecorator;
@@ -30,25 +30,17 @@ use Symfony\Component\Config\Definition\Processor;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\HttpKernel\DependencyInjection\Extension;
 use Symfony\Component\HttpKernel\DependencyInjection\Extension;
 
 
-class JMSSerializerExtension extends Extension
+class JMSSerializerExtension extends ConfigurableExtension
 {
 {
-    private $kernel;
     private $factories = array();
     private $factories = array();
 
 
-    public function __construct(KernelInterface $kernel)
-    {
-        $this->kernel = $kernel;
-    }
-
     public function addHandlerFactory(HandlerFactoryInterface $factory)
     public function addHandlerFactory(HandlerFactoryInterface $factory)
     {
     {
         $this->factories[$factory->getConfigKey()] = $factory;
         $this->factories[$factory->getConfigKey()] = $factory;
     }
     }
 
 
-    public function load(array $configs, ContainerBuilder $container)
+    public function loadInternal(array $config, ContainerBuilder $container)
     {
     {
-        $config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
-
         $loader = new XmlFileLoader($container, new FileLocator(array(
         $loader = new XmlFileLoader($container, new FileLocator(array(
                         __DIR__.'/../Resources/config/')));
                         __DIR__.'/../Resources/config/')));
         $loader->load('services.xml');
         $loader->load('services.xml');
@@ -161,14 +153,6 @@ class JMSSerializerExtension extends Extension
 
 
     public function getConfiguration(array $config, ContainerBuilder $container)
     public function getConfiguration(array $config, ContainerBuilder $container)
     {
     {
-        foreach ($this->kernel->getBundles() as $bundle) {
-            if (!method_exists($bundle, 'configureSerializerExtension')) {
-                continue;
-            }
-
-            $bundle->configureSerializerExtension($this);
-        }
-
-        return new Configuration($this->kernel->isDebug(), $this->factories);
+        return new Configuration($container->getParameterBag()->resolveValue('%kernel.debug%'), $this->factories);
     }
     }
 }
 }

+ 3 - 17
JMSSerializerBundle.php

@@ -32,20 +32,11 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
 
 
 class JMSSerializerBundle extends Bundle
 class JMSSerializerBundle extends Bundle
 {
 {
-    private $kernel;
-
-    public function __construct(KernelInterface $kernel)
-    {
-        $this->kernel = $kernel;
-    }
-
-    public function getContainerExtension()
+    public function build(ContainerBuilder $builder)
     {
     {
-        return new JMSSerializerExtension($this->kernel);
-    }
+        $builder->addCompilerPass(new SetVisitorsPass());
 
 
-    public function configureSerializerExtension(JMSSerializerExtension $ext)
-    {
+        $ext = $builder->getExtension('jms_serializer');
         $ext->addHandlerFactory(new ObjectBasedFactory());
         $ext->addHandlerFactory(new ObjectBasedFactory());
         $ext->addHandlerFactory(new DoctrineProxyFactory());
         $ext->addHandlerFactory(new DoctrineProxyFactory());
         $ext->addHandlerFactory(new ArrayCollectionFactory());
         $ext->addHandlerFactory(new ArrayCollectionFactory());
@@ -53,9 +44,4 @@ class JMSSerializerBundle extends Bundle
         $ext->addHandlerFactory(new DateTimeFactory());
         $ext->addHandlerFactory(new DateTimeFactory());
         $ext->addHandlerFactory(new FormErrorFactory());
         $ext->addHandlerFactory(new FormErrorFactory());
     }
     }
-
-    public function build(ContainerBuilder $builder)
-    {
-        $builder->addCompilerPass(new SetVisitorsPass());
-    }
 }
 }

+ 1 - 1
Resources/doc/installation.rst

@@ -41,7 +41,7 @@ register the new bundle:
     // in AppKernel::registerBundles()
     // in AppKernel::registerBundles()
     $bundles = array(
     $bundles = array(
         // ...
         // ...
-        new JMS\SerializerBundle\JMSSerializerBundle($this),
+        new JMS\SerializerBundle\JMSSerializerBundle(),
         // ...
         // ...
     );
     );
     
     

+ 0 - 10
SerializerBundleAwareInterface.php

@@ -1,10 +0,0 @@
-<?php
-
-namespace JMS\SerializerBundle;
-
-use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
-
-interface SerializerBundleAwareInterface
-{
-    function configureSerializerExtension(JMSSerializerExtension $extension);
-}

+ 1 - 0
Tests/DependencyInjection/JMSSerializerExtensionTest.php

@@ -141,6 +141,7 @@ class JMSSerializerExtensionTest extends \PHPUnit_Framework_TestCase
         $container->set('annotation_reader', new AnnotationReader());
         $container->set('annotation_reader', new AnnotationReader());
         $container->set('service_container', $container);
         $container->set('service_container', $container);
         $container->set('translator', $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'));
         $container->set('translator', $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'));
+        $container->registerExtension($extension);
         $extension->load($configs, $container);
         $extension->load($configs, $container);
 
 
         $bundle->build($container);
         $bundle->build($container);

+ 1 - 1
composer.json

@@ -15,7 +15,7 @@
         "php": ">=5.3.2",
         "php": ">=5.3.2",
         "jms/metadata": ">=1.1.0,<1.3-dev"
         "jms/metadata": ">=1.1.0,<1.3-dev"
     },
     },
-    "conflicts": {
+    "conflict": {
         "symfony/framework-bundle": "<2.1-dev"
         "symfony/framework-bundle": "<2.1-dev"
     },
     },
     "require-dev": {
     "require-dev": {