<?php

namespace Lsw\MemcacheBundle\DependencyInjection\Compiler;

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

/**
 * EnableSessionSupport is a compiler pass to set the session handler.
 * Based on Emagister\MemcachedBundle by Christian Soronellas
 */
class EnableSessionSupport implements CompilerPassInterface
{
    /**
     * {@inheritDoc}
     */
    public function process(ContainerBuilder $container)
    {
        // If there is no active session support, return
        if (!$container->hasAlias('session.storage')) {
            return;
        }
        // If the memcache.session_handler service is loaded set the alias
        if ($container->hasDefinition('memcache.session_handler')) {
            $container->setAlias('session.handler', 'memcache.session_handler');
        }
    }
}
<?php

namespace Lsw\MemcacheBundle\DependencyInjection\Compiler;

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

/**
 * EnableSessionSupport is a compiler pass to set the session handler.
 * Based on Emagister\MemcachedBundle by Christian Soronellas
 */
class EnableSessionSupport implements CompilerPassInterface
{
    /**
     * {@inheritDoc}
     */
    public function process(ContainerBuilder $container)
    {
        // If there is no active session support, return
        if (!$container->hasAlias('session.storage')) {
            return;
        }
        // If the memcache.session_handler service is loaded set the alias
        if ($container->hasDefinition('memcache.session_handler')) {
            if (!$container->hasAlias('session.handler')) {
                $container->setAlias('session.handler', 'memcache.session_handler');
            }
        }
    }
}
Fix for session handler overriding
Fix for session handler overriding

This fixes a bug where setting a session.handler_id in your symfony
configuration didn't work, due to this bundle overriding it.

The setting is now only overridden if the handler_id is not null.
