Skip to content

Commit

Permalink
Fix #6 : SerializerHandler loaded only if jms_serializer is available
Browse files Browse the repository at this point in the history
  • Loading branch information
iamluc committed Jun 10, 2013
1 parent 2dde19d commit 3a51bd1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
20 changes: 20 additions & 0 deletions DependencyInjection/ContainerBuilder/SerializerCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Gloomy\PagerBundle\DependencyInjection\ContainerBuilder;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;

class SerializerCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->has('jms_serializer')) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('serializer.xml');
}
}
}
8 changes: 8 additions & 0 deletions GloomyPagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
namespace Gloomy\PagerBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

use Gloomy\PagerBundle\DependencyInjection\ContainerBuilder\SerializerCompilerPass;

class GloomyPagerBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new SerializerCompilerPass());
}
}
12 changes: 12 additions & 0 deletions Resources/config/serializer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="gloomy.serializer.pager_handler" class="Gloomy\PagerBundle\Serializer\Handler\GloomyPagerHandler">
<tag name="jms_serializer.subscribing_handler" />
</service>
</services>
</container>
4 changes: 0 additions & 4 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,5 @@
<tag name="twig.extension" />
<argument type="service" id="router" />
</service>

<service id="gloomy.serializer.pager_handler" class="Gloomy\PagerBundle\Serializer\Handler\GloomyPagerHandler">
<tag name="jms_serializer.subscribing_handler" />
</service>
</services>
</container>

0 comments on commit 3a51bd1

Please sign in to comment.