Update
This commit is contained in:
parent
a37785b391
commit
33458b2ca3
9915 changed files with 1247019 additions and 0 deletions
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection;
|
||||
|
||||
use Doctrine\Common\Inflector\Inflector;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Cache provider loader
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class CacheProviderLoader
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
public function loadCacheProvider($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
$serviceId = 'doctrine_cache.providers.' . $name;
|
||||
$decorator = $this->getProviderDecorator($container, $config);
|
||||
$service = $container->setDefinition($serviceId, $decorator);
|
||||
$type = ($config['type'] === 'custom_provider')
|
||||
? $config['custom_provider']['type']
|
||||
: $config['type'];
|
||||
|
||||
if ($config['namespace']) {
|
||||
$service->addMethodCall('setNamespace', array($config['namespace']));
|
||||
}
|
||||
|
||||
foreach ($config['aliases'] as $alias) {
|
||||
$container->setAlias($alias, $serviceId);
|
||||
}
|
||||
|
||||
if ($this->definitionClassExists($type, $container)) {
|
||||
$this->getCacheDefinition($type, $container)->configure($name, $config, $service, $container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param array $config
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\DefinitionDecorator
|
||||
*/
|
||||
protected function getProviderDecorator(ContainerBuilder $container, array $config)
|
||||
{
|
||||
$type = $config['type'];
|
||||
$id = 'doctrine_cache.abstract.' . $type;
|
||||
|
||||
static $childDefinition;
|
||||
|
||||
if (null === $childDefinition) {
|
||||
$childDefinition = class_exists('Symfony\Component\DependencyInjection\ChildDefinition') ? 'Symfony\Component\DependencyInjection\ChildDefinition' : 'Symfony\Component\DependencyInjection\DefinitionDecorator';
|
||||
}
|
||||
|
||||
if ($type === 'custom_provider') {
|
||||
$type = $config['custom_provider']['type'];
|
||||
$param = $this->getCustomProviderParameter($type);
|
||||
|
||||
if ($container->hasParameter($param)) {
|
||||
return new $childDefinition($container->getParameter($param));
|
||||
}
|
||||
}
|
||||
|
||||
if ($container->hasDefinition($id)) {
|
||||
return new $childDefinition($id);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('"%s" is an unrecognized Doctrine cache driver.', $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition\CacheDefinition
|
||||
*/
|
||||
private function getCacheDefinition($type, ContainerBuilder $container)
|
||||
{
|
||||
$class = $this->getDefinitionClass($type, $container);
|
||||
$object = new $class($type);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function definitionClassExists($type, ContainerBuilder $container)
|
||||
{
|
||||
if ($container->hasParameter($this->getCustomDefinitionClassParameter($type))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return class_exists($this->getDefinitionClass($type, $container));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefinitionClass($type, ContainerBuilder $container)
|
||||
{
|
||||
if ($container->hasParameter($this->getCustomDefinitionClassParameter($type))) {
|
||||
return $container->getParameter($this->getCustomDefinitionClassParameter($type));
|
||||
}
|
||||
|
||||
$name = Inflector::classify($type) . 'Definition';
|
||||
$class = sprintf('%s\Definition\%s', __NAMESPACE__, $name);
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomProviderParameter($type)
|
||||
{
|
||||
return 'doctrine_cache.custom_provider.' . $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomDefinitionClassParameter($type)
|
||||
{
|
||||
return 'doctrine_cache.custom_definition_class.' . $type;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,564 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\Definition\NodeInterface;
|
||||
|
||||
/**
|
||||
* Cache Bundle Configuration
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderParameters(array $parameters)
|
||||
{
|
||||
if (isset($parameters['type'])) {
|
||||
unset($parameters['type']);
|
||||
}
|
||||
|
||||
if (isset($parameters['aliases'])) {
|
||||
unset($parameters['aliases']);
|
||||
}
|
||||
|
||||
if (isset($parameters['namespace'])) {
|
||||
unset($parameters['namespace']);
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resolveNodeType(array $parameters)
|
||||
{
|
||||
$values = $this->getProviderParameters($parameters);
|
||||
$type = key($values);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Config\Definition\NodeInterface $tree
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProviderNames(NodeInterface $tree)
|
||||
{
|
||||
foreach ($tree->getChildren() as $providers) {
|
||||
if ($providers->getName() !== 'providers') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$children = $providers->getPrototype()->getChildren();
|
||||
$providers = array_diff(array_keys($children), array('type', 'aliases', 'namespace'));
|
||||
|
||||
return $providers;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param \Symfony\Component\Config\Definition\NodeInterface $tree
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isCustomProvider($type, NodeInterface $tree)
|
||||
{
|
||||
return ( ! in_array($type, $this->getProviderNames($tree)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$self = $this;
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('doctrine_cache', 'array');
|
||||
$normalization = function ($conf) use ($self, $builder) {
|
||||
$conf['type'] = isset($conf['type'])
|
||||
? $conf['type']
|
||||
: $self->resolveNodeType($conf);
|
||||
|
||||
if ($self->isCustomProvider($conf['type'], $builder->buildTree())) {
|
||||
$params = $self->getProviderParameters($conf);
|
||||
$options = reset($params);
|
||||
$conf = array(
|
||||
'type' => 'custom_provider',
|
||||
'namespace' => isset($conf['namespace']) ? $conf['namespace'] : null ,
|
||||
'custom_provider' => array(
|
||||
'type' => $conf['type'],
|
||||
'options' => $options ?: null,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $conf;
|
||||
};
|
||||
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('acl_cache')
|
||||
->beforeNormalization()
|
||||
->ifString()
|
||||
->then(function ($id) {
|
||||
return array('id' => $id);
|
||||
})
|
||||
->end()
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('id')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('custom_provider')
|
||||
->children()
|
||||
->arrayNode('custom_providers')
|
||||
->useAttributeAsKey('type')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('prototype')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('definition_class')->defaultNull()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('alias', 'aliases')
|
||||
->children()
|
||||
->arrayNode('aliases')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('provider')
|
||||
->children()
|
||||
->arrayNode('providers')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) use ($self, $builder) {
|
||||
return ( ! isset($v['type']) || ! $self->isCustomProvider($v['type'], $builder->buildTree()));
|
||||
})
|
||||
->then($normalization)
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('namespace')->defaultNull()->end()
|
||||
->scalarNode('type')->defaultNull()->end()
|
||||
->append($this->addBasicProviderNode('apc'))
|
||||
->append($this->addBasicProviderNode('apcu'))
|
||||
->append($this->addBasicProviderNode('array'))
|
||||
->append($this->addBasicProviderNode('void'))
|
||||
->append($this->addBasicProviderNode('wincache'))
|
||||
->append($this->addBasicProviderNode('xcache'))
|
||||
->append($this->addBasicProviderNode('zenddata'))
|
||||
->append($this->addCustomProviderNode())
|
||||
->append($this->addCouchbaseNode())
|
||||
->append($this->addChainNode())
|
||||
->append($this->addMemcachedNode())
|
||||
->append($this->addMemcacheNode())
|
||||
->append($this->addFileSystemNode())
|
||||
->append($this->addPhpFileNode())
|
||||
->append($this->addMongoNode())
|
||||
->append($this->addRedisNode())
|
||||
->append($this->addPredisNode())
|
||||
->append($this->addRiakNode())
|
||||
->append($this->addSqlite3Node())
|
||||
->end()
|
||||
->fixXmlConfig('alias', 'aliases')
|
||||
->children()
|
||||
->arrayNode('aliases')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addBasicProviderNode($name)
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root($name);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build custom node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addCustomProviderNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('custom_provider');
|
||||
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
|
||||
->arrayNode('options')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build chain node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addChainNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('chain');
|
||||
|
||||
$node
|
||||
->fixXmlConfig('provider')
|
||||
->children()
|
||||
->arrayNode('providers')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build memcache node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addMemcacheNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('memcache');
|
||||
$host = '%doctrine_cache.memcache.host%';
|
||||
$port = '%doctrine_cache.memcache.port%';
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->fixXmlConfig('server')
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->arrayNode('servers')
|
||||
->useAttributeAsKey('host')
|
||||
->normalizeKeys(false)
|
||||
->prototype('array')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) {
|
||||
return is_scalar($v);
|
||||
})
|
||||
->then(function ($val) {
|
||||
return array('port' => $val);
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('host')->defaultValue($host)->end()
|
||||
->scalarNode('port')->defaultValue($port)->end()
|
||||
->end()
|
||||
->end()
|
||||
->defaultValue(array($host => array(
|
||||
'host' => $host,
|
||||
'port' => $port
|
||||
)))
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build memcached node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addMemcachedNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('memcached');
|
||||
$host = '%doctrine_cache.memcached.host%';
|
||||
$port = '%doctrine_cache.memcached.port%';
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->fixXmlConfig('server')
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->scalarNode('persistent_id')->defaultNull()->end()
|
||||
->arrayNode('servers')
|
||||
->useAttributeAsKey('host')
|
||||
->normalizeKeys(false)
|
||||
->prototype('array')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) {
|
||||
return is_scalar($v);
|
||||
})
|
||||
->then(function ($val) {
|
||||
return array('port' => $val);
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('host')->defaultValue($host)->end()
|
||||
->scalarNode('port')->defaultValue($port)->end()
|
||||
->end()
|
||||
->end()
|
||||
->defaultValue(array($host => array(
|
||||
'host' => $host,
|
||||
'port' => $port
|
||||
)))
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build redis node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addRedisNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('redis');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->scalarNode('host')->defaultValue('%doctrine_cache.redis.host%')->end()
|
||||
->scalarNode('port')->defaultValue('%doctrine_cache.redis.port%')->end()
|
||||
->scalarNode('password')->defaultNull()->end()
|
||||
->scalarNode('timeout')->defaultNull()->end()
|
||||
->scalarNode('database')->defaultNull()->end()
|
||||
->booleanNode('persistent')->defaultFalse()->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build predis node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addPredisNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('predis');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('client_id')->defaultNull()->end()
|
||||
->scalarNode('scheme')->defaultValue('tcp')->end()
|
||||
->scalarNode('host')->defaultValue('%doctrine_cache.redis.host%')->end()
|
||||
->scalarNode('port')->defaultValue('%doctrine_cache.redis.port%')->end()
|
||||
->scalarNode('password')->defaultNull()->end()
|
||||
->scalarNode('timeout')->defaultNull()->end()
|
||||
->scalarNode('database')->defaultNull()->end()
|
||||
->arrayNode('options')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build riak node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addRiakNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('riak');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('host')->defaultValue('%doctrine_cache.riak.host%')->end()
|
||||
->scalarNode('port')->defaultValue('%doctrine_cache.riak.port%')->end()
|
||||
->scalarNode('bucket_name')->defaultValue('doctrine_cache')->end()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->scalarNode('bucket_id')->defaultNull()->end()
|
||||
->arrayNode('bucket_property_list')
|
||||
->children()
|
||||
->scalarNode('allow_multiple')->defaultNull()->end()
|
||||
->scalarNode('n_value')->defaultNull()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build couchbase node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addCouchbaseNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('couchbase');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->fixXmlConfig('hostname')
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->arrayNode('hostnames')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('%doctrine_cache.couchbase.hostnames%'))
|
||||
->end()
|
||||
->scalarNode('username')->defaultNull()->end()
|
||||
->scalarNode('password')->defaultNull()->end()
|
||||
->scalarNode('bucket_name')->defaultValue('doctrine_cache')->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build mongodb node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addMongoNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('mongodb');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->scalarNode('collection_id')->defaultNull()->end()
|
||||
->scalarNode('database_name')->defaultValue('doctrine_cache')->end()
|
||||
->scalarNode('collection_name')->defaultValue('doctrine_cache')->end()
|
||||
->scalarNode('server')->defaultValue('%doctrine_cache.mongodb.server%')->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build php_file node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addPhpFileNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('php_file');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/doctrine/cache/phpfile')->end()
|
||||
->scalarNode('extension')->defaultNull()->end()
|
||||
->integerNode('umask')->defaultValue(0002)->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build file_system node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addFileSystemNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('file_system');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/doctrine/cache/file_system')->end()
|
||||
->scalarNode('extension')->defaultNull()->end()
|
||||
->integerNode('umask')->defaultValue(0002)->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build sqlite3 node configuration definition
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
|
||||
*/
|
||||
private function addSqlite3Node()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('sqlite3');
|
||||
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('connection_id')->defaultNull()->end()
|
||||
->scalarNode('file_name')->defaultNull()->end()
|
||||
->scalarNode('table_name')->defaultNull()->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* Cache Definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
abstract class CacheDefinition
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $service
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
abstract public function configure($name, array $config, Definition $service, ContainerBuilder $container);
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Chain definition.
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
class ChainDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$providersConf = $config['chain'];
|
||||
$providers = $this->getProviders($name, $providersConf, $container);
|
||||
|
||||
$service->setArguments(array($providers));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getProviders($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
$providers = array();
|
||||
|
||||
foreach ($config['providers'] as $provider) {
|
||||
if (strpos($provider, 'doctrine_cache.providers.') === false) {
|
||||
$provider = sprintf('doctrine_cache.providers.%s', $provider);
|
||||
}
|
||||
|
||||
$providers[] = new Reference($provider);
|
||||
}
|
||||
|
||||
return $providers;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Couchbase definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class CouchbaseDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$couchbaseConf = $config['couchbase'];
|
||||
$connRef = $this->getConnectionReference($name, $couchbaseConf, $container);
|
||||
|
||||
$service->addMethodCall('setCouchbase', array($connRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$host = $config['hostnames'];
|
||||
$user = $config['username'];
|
||||
$pass = $config['password'];
|
||||
$bucket = $config['bucket_name'];
|
||||
$connClass = '%doctrine_cache.couchbase.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s_couchbase.connection', $name);
|
||||
$connDef = new Definition($connClass, array($host, $user, $pass, $bucket));
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* FileSystem definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class FileSystemDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$service->setArguments(array(
|
||||
$config['file_system']['directory'],
|
||||
$config['file_system']['extension'],
|
||||
$config['file_system']['umask']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Memcache definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class MemcacheDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$memcacheConf = $config['memcache'];
|
||||
$connRef = $this->getConnectionReference($name, $memcacheConf, $container);
|
||||
|
||||
$service->addMethodCall('setMemcache', array($connRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$connClass = '%doctrine_cache.memcache.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s.connection', $name);
|
||||
$connDef = new Definition($connClass);
|
||||
|
||||
foreach ($config['servers'] as $host => $server) {
|
||||
$connDef->addMethodCall('addServer', array($host, $server['port']));
|
||||
}
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Memcached definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class MemcachedDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$memcachedConf = $config['memcached'];
|
||||
$connRef = $this->getConnectionReference($name, $memcachedConf, $container);
|
||||
|
||||
$service->addMethodCall('setMemcached', array($connRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$connClass = '%doctrine_cache.memcached.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s.connection', $name);
|
||||
$connDef = new Definition($connClass);
|
||||
|
||||
if (isset($config['persistent_id']) === true) {
|
||||
$connDef->addArgument($config['persistent_id']);
|
||||
}
|
||||
|
||||
foreach ($config['servers'] as $host => $server) {
|
||||
$connDef->addMethodCall('addServer', array($host, $server['port']));
|
||||
}
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* MongoDB definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class MongodbDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$memcacheConf = $config['mongodb'];
|
||||
$collRef = $this->getCollectionReference($name, $memcacheConf, $container);
|
||||
|
||||
$service->setArguments(array($collRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getCollectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['collection_id'])) {
|
||||
return new Reference($config['collection_id']);
|
||||
}
|
||||
|
||||
$databaseName = $config['database_name'];
|
||||
$collectionName = $config['collection_name'];
|
||||
$collClass = '%doctrine_cache.mongodb.collection.class%';
|
||||
$collId = sprintf('doctrine_cache.services.%s.collection', $name);
|
||||
$collDef = new Definition($collClass, array($databaseName, $collectionName));
|
||||
$connRef = $this->getConnectionReference($name, $config, $container);
|
||||
|
||||
$definition = $container->setDefinition($collId, $collDef)->setPublic(false);
|
||||
|
||||
if (method_exists($definition, 'setFactory')) {
|
||||
$definition->setFactory(array($connRef, 'selectCollection'));
|
||||
|
||||
return new Reference($collId);
|
||||
}
|
||||
|
||||
$definition
|
||||
->setFactoryService($connRef)
|
||||
->setFactoryMethod('selectCollection')
|
||||
;
|
||||
|
||||
return new Reference($collId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$server = $config['server'];
|
||||
$connClass = '%doctrine_cache.mongodb.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s.connection', $name);
|
||||
$connDef = new Definition($connClass, array($server));
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$connDef->addMethodCall('connect');
|
||||
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* PhpFile definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class PhpFileDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$service->setArguments(array(
|
||||
$config['php_file']['directory'],
|
||||
$config['php_file']['extension'],
|
||||
$config['php_file']['umask']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Predis definition.
|
||||
*
|
||||
* @author Ivo Bathke <ivo.bathke@gmail.com>
|
||||
*/
|
||||
class PredisDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$redisConf = $config['predis'];
|
||||
$connRef = $this->getConnectionReference($name, $redisConf, $container);
|
||||
$service->addArgument($connRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['client_id'])) {
|
||||
return new Reference($config['client_id']);
|
||||
}
|
||||
|
||||
$parameters = array(
|
||||
'scheme' => $config['scheme'],
|
||||
'host' => $config['host'],
|
||||
'port' => $config['port'],
|
||||
);
|
||||
|
||||
if ($config['password']) {
|
||||
$parameters['password'] = $config['password'];
|
||||
}
|
||||
|
||||
if ($config['timeout']) {
|
||||
$parameters['timeout'] = $config['timeout'];
|
||||
}
|
||||
|
||||
if ($config['database']) {
|
||||
$parameters['database'] = $config['database'];
|
||||
}
|
||||
|
||||
$options = null;
|
||||
|
||||
if (isset($config['options'])) {
|
||||
$options = $config['options'];
|
||||
}
|
||||
|
||||
$clientClass = '%doctrine_cache.predis.client.class%';
|
||||
$clientId = sprintf('doctrine_cache.services.%s_predis.client', $name);
|
||||
$clientDef = new Definition($clientClass);
|
||||
|
||||
$clientDef->addArgument($parameters);
|
||||
$clientDef->addArgument($options);
|
||||
$clientDef->setPublic(false);
|
||||
|
||||
$container->setDefinition($clientId, $clientDef);
|
||||
|
||||
return new Reference($clientId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Redis definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class RedisDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$redisConf = $config['redis'];
|
||||
$connRef = $this->getConnectionReference($name, $redisConf, $container);
|
||||
|
||||
$service->addMethodCall('setRedis', array($connRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$host = $config['host'];
|
||||
$port = $config['port'];
|
||||
$connClass = '%doctrine_cache.redis.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s_redis.connection', $name);
|
||||
$connDef = new Definition($connClass);
|
||||
$connParams = array($host, $port);
|
||||
|
||||
if (isset($config['timeout'])) {
|
||||
$connParams[] = $config['timeout'];
|
||||
}
|
||||
|
||||
$connMethod = 'connect';
|
||||
|
||||
if (isset($config['persistent']) && $config['persistent']) {
|
||||
$connMethod = 'pconnect';
|
||||
}
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$connDef->addMethodCall($connMethod, $connParams);
|
||||
|
||||
if (isset($config['password'])) {
|
||||
$password = $config['password'];
|
||||
$connDef->addMethodCall('auth', array($password));
|
||||
}
|
||||
|
||||
if (isset($config['database'])) {
|
||||
$database = (int) $config['database'];
|
||||
$connDef->addMethodCall('select', array($database));
|
||||
}
|
||||
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Riak definition.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class RiakDefinition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$riakConf = $config['riak'];
|
||||
$bucketRef = $this->getBucketReference($name, $riakConf, $container);
|
||||
|
||||
$service->setArguments(array($bucketRef));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getBucketReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['bucket_id'])) {
|
||||
return new Reference($config['bucket_id']);
|
||||
}
|
||||
|
||||
$bucketName = $config['bucket_name'];
|
||||
$bucketClass = '%doctrine_cache.riak.bucket.class%';
|
||||
$bucketId = sprintf('doctrine_cache.services.%s.bucket', $name);
|
||||
$connDef = $this->getConnectionReference($name, $config, $container);
|
||||
$bucketDef = new Definition($bucketClass, array($connDef, $bucketName));
|
||||
|
||||
$bucketDef->setPublic(false);
|
||||
$container->setDefinition($bucketId, $bucketDef);
|
||||
|
||||
if ( ! empty($config['bucket_property_list'])) {
|
||||
$this->configureBucketPropertyList($name, $config['bucket_property_list'], $bucketDef, $container);
|
||||
}
|
||||
|
||||
return new Reference($bucketId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$host = $config['host'];
|
||||
$port = $config['port'];
|
||||
$connClass = '%doctrine_cache.riak.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s.connection', $name);
|
||||
$connDef = new Definition($connClass, array($host, $port));
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $bucketDefinition
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
private function configureBucketPropertyList($name, array $config, Definition $bucketDefinition, ContainerBuilder $container)
|
||||
{
|
||||
$propertyListClass = '%doctrine_cache.riak.bucket_property_list.class%';
|
||||
$propertyListServiceId = sprintf('doctrine_cache.services.%s.bucket_property_list', $name);
|
||||
$propertyListReference = new Reference($propertyListServiceId);
|
||||
$propertyListDefinition = new Definition($propertyListClass, array(
|
||||
$config['n_value'],
|
||||
$config['allow_multiple']
|
||||
));
|
||||
|
||||
$container->setDefinition($propertyListServiceId, $propertyListDefinition);
|
||||
$bucketDefinition->addMethodCall('setPropertyList', array($propertyListReference));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Sqlite3 definition.
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
class Sqlite3Definition extends CacheDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
|
||||
{
|
||||
$sqlite3Conf = $config['sqlite3'];
|
||||
$tableName = $sqlite3Conf['table_name'];
|
||||
$connectionRef = $this->getConnectionReference($name, $sqlite3Conf, $container);
|
||||
|
||||
$service->setArguments(array($connectionRef, $tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Reference
|
||||
*/
|
||||
private function getConnectionReference($name, array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['connection_id'])) {
|
||||
return new Reference($config['connection_id']);
|
||||
}
|
||||
|
||||
$fileName = $config['file_name'];
|
||||
$connClass = '%doctrine_cache.sqlite3.connection.class%';
|
||||
$connId = sprintf('doctrine_cache.services.%s.connection', $name);
|
||||
$connDef = new Definition($connClass, array($fileName, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE));
|
||||
|
||||
$connDef->setPublic(false);
|
||||
$container->setDefinition($connId, $connDef);
|
||||
|
||||
return new Reference($connId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* Cache Bundle Extension
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
* @author Danilo Cabello <danilo.cabello@gmail.com>
|
||||
*/
|
||||
class DoctrineCacheExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader $loader
|
||||
*/
|
||||
public function __construct(CacheProviderLoader $loader = null)
|
||||
{
|
||||
$this->loader = $loader ?: new CacheProviderLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$rootConfig = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$locator = new FileLocator(__DIR__ . '/../Resources/config/');
|
||||
$loader = new XmlFileLoader($container, $locator);
|
||||
|
||||
$loader->load('services.xml');
|
||||
|
||||
$this->loadAcl($rootConfig, $container);
|
||||
$this->loadCustomProviders($rootConfig, $container);
|
||||
$this->loadCacheProviders($rootConfig, $container);
|
||||
$this->loadCacheAliases($rootConfig, $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rootConfig
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
protected function loadAcl(array $rootConfig, ContainerBuilder $container)
|
||||
{
|
||||
if ( ! isset($rootConfig['acl_cache']['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! interface_exists('Symfony\Component\Security\Acl\Model\AclInterface')) {
|
||||
throw new \LogicException('You must install symfony/security-acl in order to use the acl_cache functionality.');
|
||||
}
|
||||
|
||||
$aclCacheDefinition = new Definition(
|
||||
$container->getParameter('doctrine_cache.security.acl.cache.class'),
|
||||
array(
|
||||
new Reference($rootConfig['acl_cache']['id']),
|
||||
new Reference('security.acl.permission_granting_strategy'),
|
||||
)
|
||||
);
|
||||
|
||||
$aclCacheDefinition->setPublic(false);
|
||||
|
||||
$container->setDefinition('doctrine_cache.security.acl.cache', $aclCacheDefinition);
|
||||
$container->setAlias('security.acl.cache', 'doctrine_cache.security.acl.cache');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rootConfig
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
protected function loadCacheProviders(array $rootConfig, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($rootConfig['providers'] as $name => $config) {
|
||||
$this->loader->loadCacheProvider($name, $config, $container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rootConfig
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
protected function loadCacheAliases(array $rootConfig, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($rootConfig['aliases'] as $alias => $name) {
|
||||
$container->setAlias($alias, 'doctrine_cache.providers.' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rootConfig
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
protected function loadCustomProviders(array $rootConfig, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($rootConfig['custom_providers'] as $type => $rootConfig) {
|
||||
$providerParameterName = $this->loader->getCustomProviderParameter($type);
|
||||
$definitionParameterName = $this->loader->getCustomDefinitionClassParameter($type);
|
||||
|
||||
$container->setParameter($providerParameterName, $rootConfig['prototype']);
|
||||
|
||||
if ($rootConfig['definition_class']) {
|
||||
$container->setParameter($definitionParameterName, $rootConfig['definition_class']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return 'doctrine_cache';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
return __DIR__ . '/../Resources/config/schema';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
**/
|
||||
public function getNamespace()
|
||||
{
|
||||
return 'http://doctrine-project.org/schemas/symfony-dic/cache';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Symfony bridge adpter
|
||||
*
|
||||
* @author Kinn Coelho Julião <kinncj@php.net>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class SymfonyBridgeAdapter
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader
|
||||
*/
|
||||
private $cacheProviderLoader;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $objectManagerName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $mappingResourceName;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader $cacheProviderLoader
|
||||
* @param string $objectManagerName
|
||||
* @param string $mappingResourceName
|
||||
*/
|
||||
public function __construct(CacheProviderLoader $cacheProviderLoader, $objectManagerName, $mappingResourceName)
|
||||
{
|
||||
$this->cacheProviderLoader = $cacheProviderLoader;
|
||||
$this->objectManagerName = $objectManagerName;
|
||||
$this->mappingResourceName = $mappingResourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
public function loadServicesConfiguration(ContainerBuilder $container)
|
||||
{
|
||||
$locator = new FileLocator(__DIR__ . '/../Resources/config/');
|
||||
$loader = new XmlFileLoader($container, $locator);
|
||||
|
||||
$loader->load('services.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cacheName
|
||||
* @param string $objectManagerName
|
||||
* @param array $cacheDriver
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container)
|
||||
{
|
||||
$id = $this->getObjectManagerElementName($objectManagerName . '_' . $cacheName);
|
||||
$host = isset($cacheDriver['host']) ? $cacheDriver['host'] : null;
|
||||
$port = isset($cacheDriver['port']) ? $cacheDriver['port'] : null;
|
||||
$password = isset($cacheDriver['password']) ? $cacheDriver['password'] : null;
|
||||
$database = isset($cacheDriver['database']) ? $cacheDriver['database'] : null;
|
||||
$type = $cacheDriver['type'];
|
||||
|
||||
if ($type == 'service') {
|
||||
$container->setAlias($id, new Alias($cacheDriver['id'], false));
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
$config = array(
|
||||
'aliases' => array($id),
|
||||
$type => array(),
|
||||
'type' => $type,
|
||||
'namespace' => null,
|
||||
);
|
||||
|
||||
if ( ! isset($cacheDriver['namespace'])) {
|
||||
// generate a unique namespace for the given application
|
||||
$seed = '_'.$container->getParameter('kernel.root_dir');
|
||||
|
||||
if ($container->hasParameter('cache.prefix.seed')) {
|
||||
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
|
||||
}
|
||||
|
||||
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
|
||||
$hash = hash('sha256', $seed);
|
||||
$namespace = 'sf_' . $this->mappingResourceName .'_' . $objectManagerName . '_' . $hash;
|
||||
|
||||
$cacheDriver['namespace'] = $namespace;
|
||||
}
|
||||
|
||||
$config['namespace'] = $cacheDriver['namespace'];
|
||||
|
||||
if (in_array($type, array('memcache', 'memcached'))) {
|
||||
$host = !empty($host) ? $host : 'localhost';
|
||||
$config[$type]['servers'][$host] = array(
|
||||
'host' => $host,
|
||||
'port' => !empty($port) ? $port : 11211,
|
||||
);
|
||||
}
|
||||
|
||||
if ($type === 'redis') {
|
||||
$config[$type] = array(
|
||||
'host' => !empty($host) ? $host : 'localhost',
|
||||
'port' => !empty($port) ? $port : 6379,
|
||||
'password' => !empty($password) ? $password : null,
|
||||
'database' => !empty($database) ? $database : 0
|
||||
);
|
||||
}
|
||||
|
||||
if ($type === 'predis') {
|
||||
$config[$type] = array(
|
||||
'scheme' => 'tcp',
|
||||
'host' => !empty($host) ? $host : 'localhost',
|
||||
'port' => !empty($port) ? $port : 6379,
|
||||
'password' => !empty($password) ? $password : null,
|
||||
'database' => !empty($database) ? $database : 0,
|
||||
'timeout' => null,
|
||||
);
|
||||
}
|
||||
|
||||
$this->cacheProviderLoader->loadCacheProvider($id, $config, $container);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $objectManager
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param string $cacheName
|
||||
*/
|
||||
public function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName)
|
||||
{
|
||||
$this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName.'_driver'], $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getObjectManagerElementName($name)
|
||||
{
|
||||
return $this->objectManagerName . '.' . $name;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue