DependencyInjection/LswMemcacheExtension.php
private function newMemcacheClient($name, array $config, ContainerBuilder $container)
    {
        // Check if the Memcache extension is loaded
        if (!extension_loaded('memcache')) {
            throw new \LogicException('Memcache extension is not loaded! To configure pools it MUST be loaded!');
        }

        $memcache = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache');
        $memcache->addArgument(new Parameter('kernel.debug'));

        // Add servers to the memcache pool
        foreach ($config['servers'] as $s) {
            $server = array(
                $s['host'],
                $s['tcp_port'],
                $s['udp_port'],
                $s['persistent'],
                $s['weight'],
                $s['timeout'],
                $s['retry_interval']
            );
            if ($s['host']) {
                $memcache->addMethodCall('addServer', $server);
            }
        }
        
        $memcache->addArgument($config['options']);

        $options = array();
        // Make sure that config values are human readable
        foreach ($config['options'] as $key => $value) {
            $options[$key] = var_export($value, true);
        }

        // Add the service to the container
        $serviceName = sprintf('memcache.%s', $name);
        $container->setDefinition($serviceName, $memcache);
        // Add the service to the data collector
        if ($container->hasDefinition('memcache.data_collector')) {
            $definition = $container->getDefinition('memcache.data_collector');
            $definition->addMethodCall('addClient', array($name, $options, new Reference($serviceName)));
        }
    }
private function newMemcacheClient($name, array $config, ContainerBuilder $container)
    {
        // Check if the Memcache extension is loaded
        if (!extension_loaded('memcache')) {
            throw new \LogicException('Memcache extension is not loaded! To configure pools it MUST be loaded!');
        }

        $memcache = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache');
        $memcache->addArgument(new Parameter('kernel.debug'));

        // Add servers to the memcache pool
        foreach ($config['servers'] as $s) {
            $server = array(
                $s['host'],
                $s['tcp_port'],
                $s['udp_port'],
                $s['persistent'],
                $s['weight'],
                $s['timeout'],
                $s['retry_interval']
            );
            if ($s['host']) {
                $memcache->addMethodCall('addServer', $server);
            }
        }
        
        $memcache->addArgument($config['options']);

        $options = array();
        // Make sure that config values are human readable
        foreach ($config['options'] as $key => $value) {
            $options[$key] = var_export($value, true);
        }

        // Add the service to the container
        $serviceName = sprintf('memcache.%s', $name);
        $container->setDefinition($serviceName, $memcache);
        // Add the service to the data collector
        if ($container->hasDefinition('memcache.data_collector')) {
            $definition = $container->getDefinition('memcache.data_collector');
            $definition->addMethodCall('addClient', array($name, $options, new Reference($serviceName)));
        }
    }
private function newMemcacheClient ( $ name , array $ config , ContainerBuilder $ container ) { // Check if the Memcache extension is loaded if ( ! extension_loaded ( 'memcache' ) ) { throw new \ LogicException ( 'Memcache extension is not loaded! To configure pools it MUST be loaded!' ) ; } $ memcache = new Definition ( 'Lsw\MemcacheBundle\Cache\AntiDogPileMemcache' ) ; $ memcache -> addArgument ( new Parameter ( 'kernel.debug' ) ) ; // Add servers to the memcache pool foreach ( $ config [ 'servers' ] as $ s ) { $ server = array ( $ s [ 'host' ] , $ s [ 'tcp_port' ] , $ s [ 'udp_port' ] , $ s [ 'persistent' ] , $ s [ 'weight' ] , $ s [ 'timeout' ] , $ s [ 'retry_interval' ] ) ; if ( $ s [ 'host' ] ) { $ memcache -> addMethodCall ( 'addServer' , $ server ) ; } } $ memcache -> addArgument ( $ config [ 'options' ] ) ; $ options = array ( ) ; // Make sure that config values are human readable foreach ( $ config [ 'options' ] as $ key => $ value ) { $ options [ $ key ] = var_export ( $ value , true ) ; } // Add the service to the container $ serviceName = sprintf ( 'memcache.%s' , $ name ) ; $ container -> setDefinition ( $ serviceName , $ memcache ) ; // Add the service to the data collector if ( $ container -> hasDefinition ( 'memcache.data_collector' ) ) { $ definition = $ container -> getDefinition ( 'memcache.data_collector' ) ; $ definition -> addMethodCall ( 'addClient' , array ( $ name , $ options , new Reference ( $ serviceName ) ) ) ; } }
Creates a new Memcache definition

@param string           $name      Client name
@param array            $config    Client configuration
@param ContainerBuilder $container Service container

@throws \LogicException
Creates a new Memcache definition