Initiale Version

This commit is contained in:
Jan Unger
2016-08-16 21:20:53 +02:00
commit 88cf71d772
10930 changed files with 1708903 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# for php-coveralls
service_name: travis-ci
src_dir: ./
coverage_clover: build/logs/clover.xml

View File

@@ -0,0 +1,35 @@
language: php
sudo: false
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
services:
- riak
- mongodb
- memcached
- redis-server
before_script:
- ./Tests/travis/install-deps.sh
- composer self-update
- if [ "$DEPS" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- composer update --prefer-source
script:
- ./vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml
- ./vendor/bin/phpcs -np --extensions=php --ignore=vendor/*,Tests/* --standard=ruleset.xml .
after_script:
- php ./vendor/bin/coveralls -v
matrix:
allow_failures:
- php: hhvm
include:
- php: 5.6
env: DEPS="dev"

View File

@@ -0,0 +1,239 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Acl\Model;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\Security\Acl\Model\AclCacheInterface;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
use Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface;
/**
* This class is a wrapper around the actual cache implementation.
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AclCache implements AclCacheInterface
{
/**
* @var \Doctrine\Common\Cache\CacheProvider
*/
private $cache;
/**
* @var \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface
*/
private $permissionGrantingStrategy;
/**
* Constructor
*
* @param \Doctrine\Common\Cache\CacheProvider $cache
* @param \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface $permissionGrantingStrategy
*/
public function __construct(CacheProvider $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy)
{
$this->cache = $cache;
$this->permissionGrantingStrategy = $permissionGrantingStrategy;
}
/**
* {@inheritdoc}
*/
public function evictFromCacheById($primaryKey)
{
if ( ! $this->cache->contains($primaryKey)) {
return;
}
$key = $this->cache->fetch($primaryKey);
$this->cache->delete($primaryKey);
$this->evictFromCacheByKey($key);
}
/**
* {@inheritdoc}
*/
public function evictFromCacheByIdentity(ObjectIdentityInterface $oid)
{
$key = $this->createKeyFromIdentity($oid);
$this->evictFromCacheByKey($key);
}
/**
* {@inheritdoc}
*/
public function getFromCacheById($primaryKey)
{
if ( ! $this->cache->contains($primaryKey)) {
return null;
}
$key = $this->cache->fetch($primaryKey);
$acl = $this->getFromCacheByKey($key);
if ( ! $acl) {
$this->cache->delete($primaryKey);
return null;
}
return $acl;
}
/**
* {@inheritdoc}
*/
public function getFromCacheByIdentity(ObjectIdentityInterface $oid)
{
$key = $this->createKeyFromIdentity($oid);
return $this->getFromCacheByKey($key);
}
/**
* {@inheritdoc}
*/
public function putInCache(AclInterface $acl)
{
if (null === $acl->getId()) {
throw new \InvalidArgumentException('Transient ACLs cannot be cached.');
}
$parentAcl = $acl->getParentAcl();
if (null !== $parentAcl) {
$this->putInCache($parentAcl);
}
$key = $this->createKeyFromIdentity($acl->getObjectIdentity());
$this->cache->save($key, serialize($acl));
$this->cache->save($acl->getId(), $key);
}
/**
* {@inheritdoc}
*/
public function clearCache()
{
return $this->cache->deleteAll();
}
/**
* Unserialize a given ACL.
*
* @param string $serialized
*
* @return \Symfony\Component\Security\Acl\Model\AclInterface
*/
private function unserializeAcl($serialized)
{
$acl = unserialize($serialized);
$parentId = $acl->getParentAcl();
if (null !== $parentId) {
$parentAcl = $this->getFromCacheById($parentId);
if (null === $parentAcl) {
return null;
}
$acl->setParentAcl($parentAcl);
}
$reflectionProperty = new \ReflectionProperty($acl, 'permissionGrantingStrategy');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($acl, $this->permissionGrantingStrategy);
$reflectionProperty->setAccessible(false);
$aceAclProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'acl');
$aceAclProperty->setAccessible(true);
foreach ($acl->getObjectAces() as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
foreach ($acl->getClassAces() as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
$aceClassFieldProperty = new \ReflectionProperty($acl, 'classFieldAces');
$aceClassFieldProperty->setAccessible(true);
foreach ($aceClassFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceClassFieldProperty->setAccessible(false);
$aceObjectFieldProperty = new \ReflectionProperty($acl, 'objectFieldAces');
$aceObjectFieldProperty->setAccessible(true);
foreach ($aceObjectFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceObjectFieldProperty->setAccessible(false);
$aceAclProperty->setAccessible(false);
return $acl;
}
/**
* Returns the key for the object identity
*
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $oid
*
* @return string
*/
private function createKeyFromIdentity(ObjectIdentityInterface $oid)
{
return $oid->getType() . '_' . $oid->getIdentifier();
}
/**
* Removes an ACL from the cache
*
* @param string $key
*/
private function evictFromCacheByKey($key)
{
if ( ! $this->cache->contains($key)) {
return;
}
$this->cache->delete($key);
}
/**
* Retrieves an ACL for the given key from the cache
*
* @param string $key
*
* @return null|\Symfony\Component\Security\Acl\Model\AclInterface
*/
private function getFromCacheByKey($key)
{
if ( ! $this->cache->contains($key)) {
return null;
}
$serialized = $this->cache->fetch($key);
return $this->unserializeAcl($serialized);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\Common\Cache\Cache;
/**
* Base cache command.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
abstract class CacheCommand extends Command implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* Get the requested cache provider service.
*
* @param string $cacheName
*
* @return \Doctrine\Common\Cache\Cache
*
* @throws \InvalidArgumentException
*/
protected function getCacheProvider($cacheName)
{
$container = $this->getContainer();
// Try to use user input as cache service alias.
$cacheProvider = $container->get($cacheName, ContainerInterface::NULL_ON_INVALID_REFERENCE);
// If cache provider was not found try the service provider name.
if ( ! $cacheProvider instanceof Cache) {
$cacheProvider = $container->get('doctrine_cache.providers.' . $cacheName, ContainerInterface::NULL_ON_INVALID_REFERENCE);
}
// Cache provider was not found.
if ( ! $cacheProvider instanceof Cache) {
throw new \InvalidArgumentException('Cache provider not found.');
}
return $cacheProvider;
}
/**
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected function getContainer()
{
return $this->container;
}
/**
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Check if a cache entry exists.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class ContainsCommand extends CacheCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('doctrine:cache:contains')
->setDescription('Check if a cache entry exists')
->addArgument('cache-name', InputArgument::REQUIRED, 'Which cache provider to use?')
->addArgument('cache-id', InputArgument::REQUIRED, 'Which cache ID to check?');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$cacheName = $input->getArgument('cache-name');
$cacheProvider = $this->getCacheProvider($cacheName);
$cacheId = $input->getArgument('cache-id');
$message = $cacheProvider->contains($cacheId) ? '<info>TRUE</info>' : '<error>FALSE</error>';
$output->writeln($message);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Delete cache entries.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class DeleteCommand extends CacheCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('doctrine:cache:delete')
->setDescription('Delete a cache entry')
->addArgument('cache-name', InputArgument::REQUIRED, 'Which cache provider to use?')
->addArgument('cache-id', InputArgument::OPTIONAL, 'Which cache ID to delete?')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Delete all cache entries in provider');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$cacheName = $input->getArgument('cache-name');
$cacheProvider = $this->getCacheProvider($cacheName);
$cacheId = $input->getArgument('cache-id');
$all = $input->getOption('all');
if ($all && ! method_exists($cacheProvider, 'deleteAll')) {
throw new \RuntimeException('Cache provider does not implement a deleteAll method.');
}
if ( ! $all && ! $cacheId) {
throw new \InvalidArgumentException('Missing cache ID');
}
$success = $all ? $cacheProvider->deleteAll() : $cacheProvider->delete($cacheId);
$color = $success ? 'info' : 'error';
$success = $success ? 'succeeded' : 'failed';
$message = null;
if ( ! $all) {
$message = "Deletion of <$color>%s</$color> in <$color>%s</$color> has <$color>%s</$color>";
$message = sprintf($message, $cacheId, $cacheName, $success, true);
}
if ($all) {
$message = "Deletion of <$color>all</$color> entries in <$color>%s</$color> has <$color>%s</$color>";
$message = sprintf($message, $cacheName, $success, true);
}
$output->writeln($message);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Flush a cache provider.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class FlushCommand extends CacheCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('doctrine:cache:flush')
->setAliases(array('doctrine:cache:clear'))
->setDescription('Flush a given cache')
->addArgument('cache-name', InputArgument::REQUIRED, 'Which cache provider to flush?');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$cacheName = $input->getArgument('cache-name');
$cacheProvider = $this->getCacheProvider($cacheName);
if ( ! method_exists($cacheProvider, 'flushAll')) {
throw new \RuntimeException('Cache provider does not implement a flushAll method.');
}
$cacheProviderName = get_class($cacheProvider);
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> provider of type <info>%s</info>', $cacheName, $cacheProviderName, true));
$cacheProvider->flushAll();
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Get stats from cache provider.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class StatsCommand extends CacheCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('doctrine:cache:stats')
->setDescription('Get stats on a given cache provider')
->addArgument('cache-name', InputArgument::REQUIRED, 'Which cache provider to flush?');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$cacheName = $input->getArgument('cache-name');
$cacheProvider = $this->getCacheProvider($cacheName);
$cacheProviderName = get_class($cacheProvider);
$stats = $cacheProvider->getStats();
if ($stats === null) {
$output->writeln(sprintf('Stats were not provided for the <info>%s</info> provider of type <info>%s</info>', $cacheName, $cacheProviderName, true));
return;
}
$formatter = $this->getHelperSet()->get('formatter');
$lines = array();
foreach ($stats as $key => $stat) {
$lines[] = $formatter->formatSection($key, $stat);
}
$output->writeln(sprintf('Stats for the <info>%s</info> provider of type <info>%s</info>:', $cacheName, $cacheProviderName, true));
$output->writeln($lines);
}
}

View File

@@ -0,0 +1,153 @@
<?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\DefinitionDecorator;
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;
if ($type === 'custom_provider') {
$type = $config['custom_provider']['type'];
$param = $this->getCustomProviderParameter($type);
if ($container->hasParameter($param)) {
return new DefinitionDecorator($container->getParameter($param));
}
}
if ($container->hasDefinition($id)) {
return new DefinitionDecorator($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;
}
}

View File

@@ -0,0 +1,563 @@
<?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',
'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()
->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;
}
}

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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']
));
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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']
));
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,77 @@
<?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'];
}
$connDef->setPublic(false);
$connDef->addMethodCall('connect', $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);
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -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';
}
}

View File

@@ -0,0 +1,155 @@
<?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
$environment = $container->getParameter('kernel.root_dir').$container->getParameter('kernel.environment');
$hash = hash('sha256', $environment);
$namespace = 'sf2' . $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
);
}
$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;
}
}

View File

@@ -0,0 +1,32 @@
<?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;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Symfony Bundle for Doctrine Cache
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
*/
class DoctrineCacheBundle extends Bundle
{
}

View File

@@ -0,0 +1,19 @@
Copyright (c) 2006-2012 Doctrine Project
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,32 @@
DoctrineCacheBundle
===================
Symfony Bundle for Doctrine Cache.
Master: [![Build Status](https://secure.travis-ci.org/doctrine/DoctrineCacheBundle.png?branch=master)](http://travis-ci.org/doctrine/DoctrineCacheBundle)
Master: [![Coverage Status](https://coveralls.io/repos/doctrine/DoctrineCacheBundle/badge.png?branch=master)](https://coveralls.io/r/doctrine/DoctrineCacheBundle?branch=master)
## Installation
1. Add this bundle to your project as a composer dependency:
```bash
composer require doctrine/doctrine-cache-bundle
```
2. Add this bundle in your application kernel:
```php
// app/AppKernel.php
public function registerBundles()
{
// ...
$bundles[] = new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle();
return $bundles;
}
```
Read the [documentation](Resources/doc/index.rst) to learn how to configure and
use your own cache providers.

View File

@@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://doctrine-project.org/schemas/symfony-dic/cache"
elementFormDefault="qualified">
<xsd:element name="doctrine_cache">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="acl_cache" type="acl_cache" minOccurs="0" maxOccurs="1" />
<xsd:element name="alias" type="alias" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="provider" type="provider" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="acl_cache">
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="alias">
<xsd:attribute name="key" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="provider">
<xsd:sequence>
<xsd:element name="type" type="xsd:string"/>
<xsd:element name="namespace" type="xsd:string"/>
<xsd:element name="alias" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:choice minOccurs="0" maxOccurs="1">
<xsd:element name="chain" type="chain_provider"/>
<xsd:element name="couchbase" type="couchbase_provider"/>
<xsd:element name="file-system" type="filesystem_provider"/>
<xsd:element name="memcached" type="memcached_provider"/>
<xsd:element name="memcache" type="memcache_provider"/>
<xsd:element name="mongodb" type="mongodb_provider"/>
<xsd:element name="php-file" type="phpfile_provider"/>
<xsd:element name="redis" type="redis_provider"/>
<xsd:element name="predis" type="predis_provider"/>
<xsd:element name="riak" type="riak_provider"/>
<xsd:element name="sqlite3" type="sqlite3_provider"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="namespace" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string" />
</xsd:complexType>
<!-- memcached -->
<xsd:complexType name="memcached_provider">
<xsd:sequence>
<xsd:element name="server" type="memcached_server" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="persistent-id" type="xsd:string"/>
<xsd:attribute name="connection-id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="memcached_server">
<xsd:sequence>
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="connection-id" type="xsd:string"/>
<xsd:attribute name="host" type="xsd:string"/>
<xsd:attribute name="port" type="xsd:string"/>
</xsd:complexType>
<!-- memcache -->
<xsd:complexType name="memcache_provider">
<xsd:sequence>
<xsd:element name="server" type="memcached_server" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="connection-id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="memcache_server">
<xsd:sequence>
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="host" type="xsd:string"/>
<xsd:attribute name="port" type="xsd:string"/>
</xsd:complexType>
<!-- redis -->
<xsd:complexType name="redis_provider">
<xsd:sequence>
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="password" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="timeout" type="xsd:unsignedInt" minOccurs="0" maxOccurs="1" />
<xsd:element name="database" type="xsd:unsignedInt" minOccurs="0" maxOccurs="1" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="host" type="xsd:string"/>
<xsd:attribute name="port" type="xsd:string"/>
<xsd:attribute name="password" type="xsd:string" />
<xsd:attribute name="timeout" type="xsd:unsignedInt" />
<xsd:attribute name="database" type="xsd:unsignedInt" />
</xsd:complexType>
<!-- predis -->
<xsd:complexType name="predis_provider">
<xsd:sequence>
<xsd:element name="scheme" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="password" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="timeout" type="xsd:unsignedInt" minOccurs="0" maxOccurs="1" />
<xsd:element name="database" type="xsd:unsignedInt" minOccurs="0" maxOccurs="1" />
<xsd:element name="options" type="predis_options" minOccurs="0" maxOccurs="0" />
</xsd:sequence>
<xsd:attribute name="scheme" type="xsd:string"/>
<xsd:attribute name="host" type="xsd:string"/>
<xsd:attribute name="port" type="xsd:string"/>
<xsd:attribute name="password" type="xsd:string" />
<xsd:attribute name="timeout" type="xsd:unsignedInt" />
<xsd:attribute name="database" type="xsd:unsignedInt" />
</xsd:complexType>
<xsd:complexType name="predis_options">
<xsd:sequence>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<!-- couchbase -->
<xsd:complexType name="couchbase_provider">
<xsd:sequence>
<xsd:element name="username" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="password" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="bucket-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="hostname" type="couchbase_hostname" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="username" type="xsd:string"/>
<xsd:attribute name="password" type="xsd:string"/>
<xsd:attribute name="bucket-name" type="xsd:string"/>
</xsd:complexType>
<xsd:simpleType name="couchbase_hostname">
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
<!-- riak -->
<xsd:complexType name="riak_provider">
<xsd:sequence>
<xsd:element name="bucket-property-list" type="memcache_bucket_property_list" minOccurs="0" maxOccurs="1" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="bucket-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="bucket-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="connection-id" type="xsd:string"/>
<xsd:attribute name="bucket-name" type="xsd:string"/>
<xsd:attribute name="bucket-id" type="xsd:string"/>
<xsd:attribute name="host" type="xsd:string"/>
<xsd:attribute name="port" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="memcache_bucket_property_list">
<xsd:sequence>
<xsd:element name="allow-multiple" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="n-value" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="allow-multiple" type="xsd:string" />
<xsd:attribute name="n-value" type="xsd:string" />
</xsd:complexType>
<!-- mongodb -->
<xsd:complexType name="mongodb_provider">
<xsd:sequence>
<xsd:element name="server" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="database-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="collection-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="connection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="collection-id" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="server" type="xsd:string" />
<xsd:attribute name="database-id" type="xsd:string" />
<xsd:attribute name="collection-id" type="xsd:string" />
<xsd:attribute name="database-name" type="xsd:string" />
<xsd:attribute name="collection-name" type="xsd:string" />
</xsd:complexType>
<!-- file-system -->
<xsd:complexType name="filesystem_provider">
<xsd:sequence>
<xsd:element name="extension" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="directory" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="umask" type="xsd:integer" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="extension" type="xsd:string"/>
<xsd:attribute name="directory" type="xsd:string"/>
<xsd:attribute name="umask" type="xsd:integer"/>
</xsd:complexType>
<!-- php-file -->
<xsd:complexType name="phpfile_provider">
<xsd:sequence>
<xsd:element name="extension" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="directory" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="umask" type="xsd:integer" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="extension" type="xsd:string"/>
<xsd:attribute name="directory" type="xsd:string"/>
<xsd:attribute name="umask" type="xsd:integer"/>
</xsd:complexType>
<!-- sqlite3 -->
<xsd:complexType name="sqlite3_provider">
<xsd:sequence>
<xsd:element name="file-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="table-name" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="file-name" type="xsd:string"/>
<xsd:attribute name="table-name" type="xsd:string"/>
</xsd:complexType>
<!-- chain -->
<xsd:complexType name="chain_provider">
<xsd:sequence>
<xsd:element name="provider" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,73 @@
<?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">
<parameters>
<parameter key="doctrine_cache.apc.class">Doctrine\Common\Cache\ApcCache</parameter>
<parameter key="doctrine_cache.apcu.class">Doctrine\Common\Cache\ApcuCache</parameter>
<parameter key="doctrine_cache.array.class">Doctrine\Common\Cache\ArrayCache</parameter>
<parameter key="doctrine_cache.chain.class">Doctrine\Common\Cache\ChainCache</parameter>
<parameter key="doctrine_cache.couchbase.class">Doctrine\Common\Cache\CouchbaseCache</parameter>
<parameter key="doctrine_cache.couchbase.connection.class">Couchbase</parameter>
<parameter key="doctrine_cache.couchbase.hostnames">localhost:8091</parameter>
<parameter key="doctrine_cache.file_system.class">Doctrine\Common\Cache\FilesystemCache</parameter>
<parameter key="doctrine_cache.php_file.class">Doctrine\Common\Cache\PhpFileCache</parameter>
<parameter key="doctrine_cache.memcache.class">Doctrine\Common\Cache\MemcacheCache</parameter>
<parameter key="doctrine_cache.memcache.connection.class">Memcache</parameter>
<parameter key="doctrine_cache.memcache.host">localhost</parameter>
<parameter key="doctrine_cache.memcache.port">11211</parameter>
<parameter key="doctrine_cache.memcached.class">Doctrine\Common\Cache\MemcachedCache</parameter>
<parameter key="doctrine_cache.memcached.connection.class">Memcached</parameter>
<parameter key="doctrine_cache.memcached.host">localhost</parameter>
<parameter key="doctrine_cache.memcached.port">11211</parameter>
<parameter key="doctrine_cache.mongodb.class">Doctrine\Common\Cache\MongoDBCache</parameter>
<parameter key="doctrine_cache.mongodb.collection.class">MongoCollection</parameter>
<parameter key="doctrine_cache.mongodb.connection.class">MongoClient</parameter>
<parameter key="doctrine_cache.mongodb.server">localhost:27017</parameter>
<parameter key="doctrine_cache.predis.client.class">Predis\Client</parameter>
<parameter key="doctrine_cache.predis.scheme">tcp</parameter>
<parameter key="doctrine_cache.predis.host">localhost</parameter>
<parameter key="doctrine_cache.predis.port">6379</parameter>
<parameter key="doctrine_cache.redis.class">Doctrine\Common\Cache\RedisCache</parameter>
<parameter key="doctrine_cache.redis.connection.class">Redis</parameter>
<parameter key="doctrine_cache.redis.host">localhost</parameter>
<parameter key="doctrine_cache.redis.port">6379</parameter>
<parameter key="doctrine_cache.riak.class">Doctrine\Common\Cache\RiakCache</parameter>
<parameter key="doctrine_cache.riak.bucket.class">Riak\Bucket</parameter>
<parameter key="doctrine_cache.riak.connection.class">Riak\Connection</parameter>
<parameter key="doctrine_cache.riak.bucket_property_list.class">Riak\BucketPropertyList</parameter>
<parameter key="doctrine_cache.riak.host">localhost</parameter>
<parameter key="doctrine_cache.riak.port">8087</parameter>
<parameter key="doctrine_cache.sqlite3.class">Doctrine\Common\Cache\SQLite3Cache</parameter>
<parameter key="doctrine_cache.sqlite3.connection.class">SQLite3</parameter>
<parameter key="doctrine_cache.void.class">Doctrine\Common\Cache\VoidCache</parameter>
<parameter key="doctrine_cache.wincache.class">Doctrine\Common\Cache\WinCacheCache</parameter>
<parameter key="doctrine_cache.xcache.class">Doctrine\Common\Cache\XcacheCache</parameter>
<parameter key="doctrine_cache.zenddata.class">Doctrine\Common\Cache\ZendDataCache</parameter>
<parameter key="doctrine_cache.security.acl.cache.class">Doctrine\Bundle\DoctrineCacheBundle\Acl\Model\AclCache</parameter>
</parameters>
<services>
<service id="doctrine_cache.abstract.apc" class="%doctrine_cache.apc.class%" abstract="true" />
<service id="doctrine_cache.abstract.apcu" class="%doctrine_cache.apcu.class%" abstract="true" />
<service id="doctrine_cache.abstract.array" class="%doctrine_cache.array.class%" abstract="true" />
<service id="doctrine_cache.abstract.chain" class="%doctrine_cache.chain.class%" abstract="true" />
<service id="doctrine_cache.abstract.couchbase" class="%doctrine_cache.couchbase.class%" abstract="true" />
<service id="doctrine_cache.abstract.file_system" class="%doctrine_cache.file_system.class%" abstract="true" />
<service id="doctrine_cache.abstract.php_file" class="%doctrine_cache.php_file.class%" abstract="true" />
<service id="doctrine_cache.abstract.memcache" class="%doctrine_cache.memcache.class%" abstract="true" />
<service id="doctrine_cache.abstract.memcached" class="%doctrine_cache.memcached.class%" abstract="true" />
<service id="doctrine_cache.abstract.mongodb" class="%doctrine_cache.mongodb.class%" abstract="true" />
<service id="doctrine_cache.abstract.redis" class="%doctrine_cache.redis.class%" abstract="true" />
<service id="doctrine_cache.abstract.predis" class="Doctrine\Common\Cache\PredisCache" abstract="true" />
<service id="doctrine_cache.abstract.riak" class="%doctrine_cache.riak.class%" abstract="true" />
<service id="doctrine_cache.abstract.sqlite3" class="%doctrine_cache.sqlite3.class%" abstract="true" />
<service id="doctrine_cache.abstract.void" class="%doctrine_cache.void.class%" abstract="true" />
<service id="doctrine_cache.abstract.wincache" class="%doctrine_cache.wincache.class%" abstract="true" />
<service id="doctrine_cache.abstract.xcache" class="%doctrine_cache.xcache.class%" abstract="true" />
<service id="doctrine_cache.abstract.zenddata" class="%doctrine_cache.zenddata.class%" abstract="true" />
</services>
</container>

View File

@@ -0,0 +1,37 @@
Symfony ACL Cache
=================
.. configuration-block::
.. code-block:: yaml
# app/config/config.yml
doctrine_cache:
acl_cache:
id: 'doctrine_cache.providers.acl_apc_provider'
providers:
acl_apc_provider:
type: 'apc'
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<dic:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:container>
<doctrine-cache>
<acl-cache id="doctrine_cache.providers.acl_apc_provider"/>
<provider name="acl_apc_provider" type="apc"/>
</doctrine-cache>
</srv:container>
Check the following sample::
/** @var $aclCache Symfony\Component\Security\Acl\Model\AclCacheInterface */
$aclCache = $this->container->get('security.acl.cache');

View File

@@ -0,0 +1,67 @@
Custom Providers
================
You can also register your own custom cache drivers:
.. configuration-block::
.. code-block:: yaml
# app/config/services.yml
services:
my_custom_provider_service:
class: "MyCustomType"
# ...
# app/config/config.yml
doctrine_cache:
custom_providers:
my_custom_type:
prototype: "my_custom_provider_service"
definition_class: "MyCustomTypeDefinition" # optional configuration
providers:
my_custom_type_provider:
my_custom_type:
config_foo: "foo"
config_bar: "bar"
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<dic:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:container>
<srv:services>
<srv:service id="my_custom_provider_service" class="MyCustomType">
<!-- ... -->
</srv:service>
</srv:services>
<doctrine-cache>
<!-- register your custom cache provider -->
<custom-provider type="my_custom_type">
<prototype>my_custom_provider_service</prototype>
<definition-class>MyCustomTypeDefinition</definition-class> <!-- optional configuration -->
</custom-provider>
<provider name="my_custom_type_provider">
<my_custom_type>
<config-foo>foo</config-foo>
<config-bar>bar</config-bar>
</my_custom_type>
</provider>
</doctrine-cache>
</srv:container>
.. note::
Definition class is a optional configuration that will parse option arguments
given to your custom cache driver. See `CacheDefinition code`_.
.. _`CacheDefinition code`: https://github.com/doctrine/DoctrineCacheBundle/blob/master/DependencyInjection/Definition/CacheDefinition.php

View File

@@ -0,0 +1,16 @@
DoctrineCacheBundle
===================
The DoctrineCacheBundle allows your Symfony application to use different caching
systems through the `Doctrine Cache`_ library.
.. toctree::
installation
usage
custom_providers
service_parameter
acl_cache
reference
.. _`Doctrine Cache`: http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/caching.html

View File

@@ -0,0 +1,43 @@
Installation
============
Step 1: Download the Bundle
---------------------------
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:
.. code-block:: bash
$ composer require doctrine/doctrine-cache-bundle
This command requires you to have Composer installed globally, as explained
in the `installation chapter`_ of the Composer documentation.
Step 2: Enable the Bundle
-------------------------
Then, enable the bundle by adding it to the list of registered bundles
in the ``app/AppKernel.php`` file of your project::
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
);
// ...
}
// ...
}
.. _`installation chapter`: https://getcomposer.org/doc/00-intro.md

View File

@@ -0,0 +1,181 @@
Built-in Cache Providers Reference
----------------------------------
This is the reference of all the built-in cache providers and their configuration
options:
``apc``
~~~~~~~
This provider defines no configuration options.
``array``
~~~~~~~~~
This provider defines no configuration options.
``chain``
~~~~~~~~~
``providers``
The list of service ids of Doctrine Cache Providers to use. Put the fastest
providers first (e.g. ``array`` cache) and you can skip
``doctrine_cache.providers``.
``couchbase``
~~~~~~~~~~~~~
``connection_id``
Couchbase connection service id
``hostnames``
Couchbase hostname list
``bucket_name``
Couchbase bucket name
``username``
Couchbase username
``password``
Couchbase password
``file_system``
~~~~~~~~~~~~~~~
``extension``
File extension
``directory``
Cache directory
``umask``
Umask to revoke permissions
``mongodb``
~~~~~~~~~~~
``connection_id``
MongoClient service id
``collection_id``
MongoCollection service id
``server``
mongodb server uri
``database_name``
mongodb database name
``collection_name``
mongodb collection name
``memcache``
~~~~~~~~~~~~
``connection_id``
Memcache connection service id
``servers``
Server list
* ``server``
* ``host``, Memcache host
* ``port``, Memcache port
``memcached``
~~~~~~~~~~~~~
``connection_id``
Memcache connection service id
``servers``
Server list
* ``server``
* ``host``, Memcached host
* ``port``, Memcached port
``php_file``
~~~~~~~~~~~~
``extension``
File extension
``directory``
Cache directory
``umask``
Umask to revoke permissions
``redis``
~~~~~~~~~
``connection_id``
Redis connection service id
``host``
Redis host
``port``
Redis port
``password``
Redis password
``timeout``
Redis connection timeout
``database``
Redis database selection (integer)
``predis``
~~~~~~~~~~
``client_id``
Provide a client service id to skip the client creation by the bundle
(optional, should be used for advanced configuration)
``scheme``
Connection scheme (tcp)
``host``
Redis host
``port``
Redis port
``password``
Redis password
``timeout``
Redis connection timeout
``database``
Redis database selection (integer)
``options``
Array of predis client options
``riak``
~~~~~~~~
``connection_id``
Riak\Connection service id
``bucket_id``
Riak\Bucket service id
``host``
Riak host
``port``
Riak port
``bucket_name``
Riak bucket name
``bucket_property_list``
Riak bucket configuration (property list)
* ``allow_multiple: false``, riak bucket allow multiple configuration
* ``n_value: 1``, riak bucket n-value configuration
``sqlite3``
~~~~~~~~~~~
``connection_id``
SQLite3 connection service id
``file_name``
SQLite3 database file name
``table_name``
Cache table name
``void``
~~~~~~~~
This provider defines no configuration options.
``xcache``
~~~~~~~~~~
This provider defines no configuration options.
``wincache``
~~~~~~~~~~~~
This provider defines no configuration options.
``zenddata``
~~~~~~~~~~~~
This provider defines no configuration options.

View File

@@ -0,0 +1,85 @@
Service Parameter
=================
Cache providers can be also configured using a specific connection, bucket or
collection. Example:
.. configuration-block::
.. code-block:: yaml
# app/config/services.yml
services:
# ...
my_riak_connection_service:
class: "Riak\Connection"
# ...
my_riak_bucket_service:
class: "Riak\Bucket"
# ...
my_memcached_connection_service:
class: "Memcached"
# ...
# app/config/config.yml
doctrine_cache:
providers:
service_bucket_riak_provider:
riak:
bucket_id : "my_riak_bucket_service"
service_connection_riak_provider:
riak:
connection_id: "my_riak_connection_service"
bucket_name: "my_bucket_name"
service_connection_memcached_provider:
memcached:
connection_id: "my_memcached_connection_service"
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<dic:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:container>
<srv:services>
<srv:service id="my_riak_connection_service" class="Riak\Connection">
<!-- ... -->
</srv:service>
<srv:service id="my_riak_bucket_service" class="Riak\Bucket">
<!-- ... -->
</srv:service>
<srv:service id="my_memcached_connection_service" class="Memcached">
<!-- ... -->
</srv:service>
</srv:services>
<doctrine-cache>
<provider name="service_bucket_riak_provider">
<riak bucket-id="my_riak_bucket_service"/>
</provider>
<provider name="service_connection_riak_provider">
<riak connection-id="my_riak_connection_service">
<bucket-name>my_bucket_name</bucket-name>
</riak>
</provider>
<provider name="service_connection_memcached_provider">
<memcached connection-id="my_memcached_connection_service"/>
</provider>
</doctrine-cache>
</srv:container>
See :doc:`reference` for all the specific configurations.

View File

@@ -0,0 +1,95 @@
Usage
=====
First, configure your cache providers under the ``doctrine_cache`` configuration
option. Example:
.. configuration-block::
.. code-block:: yaml
# app/config/config.yml
doctrine_cache:
providers:
my_apc_metadata_cache:
type: apc
namespace: metadata_cache_ns
my_apc_query_cache:
namespace: query_cache_ns
apc: ~
.. code-block:: yaml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doctrine-cache="http://doctrine-project.org/schemas/symfony-dic/cache"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache:doctrine-cache>
<doctrine-cache:provider name="my_apc_metadata_cache">
<doctrine-cache:type>apc</doctrine-cache:type>
<doctrine-cache:namespace>metadata_cache_ns</doctrine-cache:namespace>
</doctrine-cache:provider>
<doctrine-cache:provider name="my_apc_query_cache" namespace="query_cache_ns">
<doctrine-cache:apc/>
<doctrine-cache:provider>
</doctrine-cache:doctrine-cache>
</container>
Then, use the newly created ``doctrine_cache.providers.{provider_name}`` container
services anywhere in your application::
$apcCache = $this->container->get('doctrine_cache.providers.my_apc_cache');
$arrayCache = $this->container->get('doctrine_cache.providers.my_array_cache');
Service Aliases
---------------
In order to make your code more concise, you can define aliases for these services
thanks to the ``aliases`` configuration option. Example:
.. configuration-block::
.. code-block:: yaml
# app/config/config.yml
doctrine_cache:
aliases:
cache_apc: my_apc_cache
providers:
my_apc_cache:
type: apc
namespace: my_apc_cache_ns
aliases:
- apc_cache
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<dic:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:container>
<doctrine-cache>
<alias key="cache_apc">my_apc_cache</alias>
<provider name="my_apc_cache">
<type>apc</type>
<namespace>my_apc_cache_ns</namespace>
<alias>apc_cache</alias>
</provider>
</doctrine-cache>
</srv:container>
Now you can use the short ``apc_cache`` alias to get the provider called
``my_apc_cache``, instead of using ``doctrine_cache.providers.my_apc_cache``::
$apcCache = $this->container->get('apc_cache');

View File

@@ -0,0 +1,194 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Acl\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\Acl;
use Doctrine\Bundle\DoctrineCacheBundle\Acl\Model\AclCache;
use Doctrine\Common\Cache\ArrayCache;
class AclCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\Common\Cache\ArrayCache
*/
private $cacheProvider;
/**
* @var \Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy
*/
private $permissionGrantingStrategy;
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\Acl\Model\AclCache
*/
private $aclCache;
public function setUp()
{
$this->cacheProvider = new ArrayCache();
$this->permissionGrantingStrategy = new PermissionGrantingStrategy();
$this->aclCache = new AclCache($this->cacheProvider, $this->permissionGrantingStrategy);
}
public function tearDown()
{
$this->cacheProvider = null;
$this->permissionGrantingStrategy = null;
$this->aclCache = null;
}
/**
* @dataProvider provideDataForEvictFromCacheById
*/
public function testEvictFromCacheById($expected, $primaryKey)
{
$this->cacheProvider->save('bar', 'foo_1');
$this->cacheProvider->save('foo_1', 's:4:test;');
$this->aclCache->evictFromCacheById($primaryKey);
$this->assertEquals($expected, $this->cacheProvider->contains('bar'));
$this->assertEquals($expected, $this->cacheProvider->contains('foo_1'));
}
public function provideDataForEvictFromCacheById()
{
return array(
array(false, 'bar'),
array(true, 'test'),
);
}
/**
* @dataProvider provideDataForEvictFromCacheByIdentity
*/
public function testEvictFromCacheByIdentity($expected, $identity)
{
$this->cacheProvider->save('foo_1', 's:4:test;');
$this->aclCache->evictFromCacheByIdentity($identity);
$this->assertEquals($expected, $this->cacheProvider->contains('foo_1'));
}
public function provideDataForEvictFromCacheByIdentity()
{
return array(
array(false, new ObjectIdentity(1, 'foo')),
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testPutInCacheWithoutId()
{
$acl = new Acl(null, new ObjectIdentity(1, 'foo'), $this->permissionGrantingStrategy, array(), false);
$this->aclCache->putInCache($acl);
}
public function testPutInCacheWithoutParent()
{
$acl = $this->getAcl(0);
$this->aclCache->putInCache($acl);
$this->assertTrue($this->cacheProvider->contains('foo1_class'));
$this->assertTrue($this->cacheProvider->contains('oid1'));
}
public function testPutInCacheWithParent()
{
$acl = $this->getAcl(2);
$this->aclCache->putInCache($acl);
// current
$this->assertTrue($this->cacheProvider->contains('foo2_class'));
$this->assertTrue($this->cacheProvider->contains('oid2'));
// parent
$this->assertTrue($this->cacheProvider->contains('foo3_class'));
$this->assertTrue($this->cacheProvider->contains('oid3'));
// grand-parent
$this->assertTrue($this->cacheProvider->contains('foo4_class'));
$this->assertTrue($this->cacheProvider->contains('oid4'));
}
public function testClearCache()
{
$acl = $this->getAcl(0);
$this->aclCache->putInCache($acl);
$this->aclCache->clearCache();
$this->assertFalse($this->cacheProvider->contains('foo5_class'));
$this->assertFalse($this->cacheProvider->contains('oid5'));
}
public function testGetFromCacheById()
{
$acl = $this->getAcl(1);
$this->aclCache->putInCache($acl);
$cachedAcl = $this->aclCache->getFromCacheById($acl->getId());
$this->assertEquals($acl->getId(), $cachedAcl->getId());
$this->assertNotNull($cachedParentAcl = $cachedAcl->getParentAcl());
$this->assertEquals($acl->getParentAcl()->getId(), $cachedParentAcl->getId());
$this->assertEquals($acl->getClassFieldAces('foo'), $cachedAcl->getClassFieldAces('foo'));
$this->assertEquals($acl->getObjectFieldAces('foo'), $cachedAcl->getObjectFieldAces('foo'));
}
public function testGetFromCacheByIdentity()
{
$acl = $this->getAcl(1);
$this->aclCache->putInCache($acl);
$cachedAcl = $this->aclCache->getFromCacheByIdentity($acl->getObjectIdentity());
$this->assertEquals($acl->getId(), $cachedAcl->getId());
$this->assertNotNull($cachedParentAcl = $cachedAcl->getParentAcl());
$this->assertEquals($acl->getParentAcl()->getId(), $cachedParentAcl->getId());
$this->assertEquals($acl->getClassFieldAces('foo'), $cachedAcl->getClassFieldAces('foo'));
$this->assertEquals($acl->getObjectFieldAces('foo'), $cachedAcl->getObjectFieldAces('foo'));
}
protected function getAcl($depth = 0)
{
static $id = 1;
$acl = new Acl(
'oid' . $id,
new ObjectIdentity('class', 'foo' . $id),
$this->permissionGrantingStrategy,
array(),
$depth > 0
);
// insert some ACEs
$sid = new UserSecurityIdentity('johannes', 'Foo');
$acl->insertClassAce($sid, 1);
$acl->insertClassFieldAce('foo', $sid, 1);
$acl->insertObjectAce($sid, 1);
$acl->insertObjectFieldAce('foo', $sid, 1);
$id++;
if ($depth > 0) {
$acl->setParentAcl($this->getAcl($depth - 1));
}
return $acl;
}
}

View File

@@ -0,0 +1,382 @@
<?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\Tests\DependencyInjection;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\DoctrineCacheExtension;
/**
* @group Extension
* @group DependencyInjection
*/
abstract class AbstractDoctrineCacheExtensionTest extends TestCase
{
protected function setUp()
{
parent::setUp();
}
abstract protected function loadFromFile(ContainerBuilder $container, $file);
public function testParameters()
{
$container = $this->createContainer();
$cacheExtension = new DoctrineCacheExtension();
$cacheExtension->load(array(), $container);
$this->assertTrue($container->hasParameter('doctrine_cache.apc.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.array.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.couchbase.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.file_system.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.memcached.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.memcache.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.mongodb.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.php_file.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.redis.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.riak.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.sqlite3.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.void.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.xcache.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.wincache.class'));
$this->assertTrue($container->hasParameter('doctrine_cache.zenddata.class'));
}
public function testBasicCache()
{
$container = $this->compileContainer('basic');
$drivers = array(
'basic_apc_provider' => '%doctrine_cache.apc.class%',
'basic_array_provider' => '%doctrine_cache.array.class%',
'basic_void_provider' => '%doctrine_cache.void.class%',
'basic_xcache_provider' => '%doctrine_cache.xcache.class%',
'basic_wincache_provider' => '%doctrine_cache.wincache.class%',
'basic_zenddata_provider' => '%doctrine_cache.zenddata.class%',
'basic_ns_zenddata_provider' => '%doctrine_cache.zenddata.class%',
'basic_apc_provider2' => '%doctrine_cache.apc.class%',
'basic_array_provider2' => '%doctrine_cache.array.class%',
'basic_void_provider2' => '%doctrine_cache.void.class%',
'basic_xcache_provider2' => '%doctrine_cache.xcache.class%',
'basic_wincache_provider2' => '%doctrine_cache.wincache.class%',
'basic_zenddata_provider2' => '%doctrine_cache.zenddata.class%',
);
foreach ($drivers as $key => $value) {
$this->assertCacheProvider($container, $key, $value);
}
}
public function testBasicConfigurableCache()
{
$container = $this->compileContainer('configurable');
$drivers = array(
'configurable_chain_provider' => array(
'%doctrine_cache.chain.class%'
),
'configurable_couchbase_provider' => array(
'%doctrine_cache.couchbase.class%'
),
'configurable_filesystem_provider' => array(
'%doctrine_cache.file_system.class%'
),
'configurable_memcached_provider' => array(
'%doctrine_cache.memcached.class%', array('setMemcached' => array())
),
'configurable_memcache_provider' => array(
'%doctrine_cache.memcache.class%', array('setMemcache' => array())
),
'configurable_mongodb_provider' => array(
'%doctrine_cache.mongodb.class%'
),
'configurable_phpfile_provider' => array(
'%doctrine_cache.php_file.class%'
),
'configurable_redis_provider' => array(
'%doctrine_cache.redis.class%', array('setRedis' => array())
),
'configurable_riak_provider' => array(
'%doctrine_cache.riak.class%'
),
'configurable_sqlite3_provider' => array(
'%doctrine_cache.sqlite3.class%'
),
);
foreach ($drivers as $id => $value) {
$this->assertCacheProvider($container, $id, $value[0]);
}
}
public function testBasicConfigurableDefaultCache()
{
$container = $this->compileContainer('configurable_defaults');
$drivers = array(
'configurable_memcached_provider' => array(
'%doctrine_cache.memcached.class%', array('setMemcached' => array())
),
'configurable_memcache_provider' => array(
'%doctrine_cache.memcache.class%', array('setMemcache' => array())
),
'configurable_redis_provider' => array(
'%doctrine_cache.redis.class%', array('setRedis' => array())
),
'configurable_mongodb_provider' => array(
'%doctrine_cache.mongodb.class%'
),
'configurable_riak_provider' => array(
'%doctrine_cache.riak.class%'
),
'configurable_filesystem_provider' => array(
'%doctrine_cache.file_system.class%'
),
'configurable_phpfile_provider' => array(
'%doctrine_cache.php_file.class%'
),
'configurable_couchbase_provider' => array(
'%doctrine_cache.couchbase.class%'
),
'configurable_memcached_provider_type' => array(
'%doctrine_cache.memcached.class%', array('setMemcached' => array())
),
'configurable_memcache_provider_type' => array(
'%doctrine_cache.memcache.class%', array('setMemcache' => array())
),
'configurable_redis_provider_type' => array(
'%doctrine_cache.redis.class%', array('setRedis' => array())
),
'configurable_mongodb_provider_type' => array(
'%doctrine_cache.mongodb.class%'
),
'configurable_riak_provider_type' => array(
'%doctrine_cache.riak.class%'
),
'configurable_filesystem_provider_type' => array(
'%doctrine_cache.file_system.class%'
),
'configurable_phpfile_provider_type' => array(
'%doctrine_cache.php_file.class%'
),
'configurable_couchbase_provider_type' => array(
'%doctrine_cache.couchbase.class%'
),
);
foreach ($drivers as $id => $value) {
$this->assertCacheProvider($container, $id, $value[0]);
}
}
public function testBasicNamespaceCache()
{
$container = $this->compileContainer('namespaced');
$drivers = array(
'doctrine_cache.providers.foo_namespace_provider' => 'foo_namespace',
'doctrine_cache.providers.barNamespaceProvider' => 'barNamespace',
);
foreach ($drivers as $key => $value) {
$this->assertTrue($container->hasDefinition($key));
$def = $container->getDefinition($key);
$calls = $def->getMethodCalls();
$this->assertEquals('setNamespace', $calls[0][0]);
$this->assertEquals($value, $calls[0][1][0]);
}
}
public function testAliasesCache()
{
$container = $this->compileContainer('aliased');
$providers = array(
'doctrine_cache.providers.foo_namespace_provider' => array('fooNamespaceProvider', 'foo'),
'doctrine_cache.providers.barNamespaceProvider' => array('bar_namespace_provider', 'bar'),
);
foreach ($providers as $key => $aliases) {
$this->assertTrue($container->hasDefinition($key));
foreach ($aliases as $alias) {
$this->assertEquals(strtolower($key), (string) $container->getAlias($alias));
}
}
}
public function testServiceParameters()
{
$container = $this->compileContainer('service_parameter');
$providers = array(
'service_bucket_riak_provider' => array(
'%doctrine_cache.riak.class%'
),
'service_connection_riak_provider' => array(
'%doctrine_cache.riak.class%'
),
'service_connection_memcached_provider' => array(
'%doctrine_cache.memcached.class%'
),
'service_connection_memcache_provider' => array(
'%doctrine_cache.memcache.class%'
),
'service_connection_redis_provider' => array(
'%doctrine_cache.redis.class%'
),
'service_connection_mongodb_provider' => array(
'%doctrine_cache.mongodb.class%'
),
'service_collection_mongodb_provider' => array(
'%doctrine_cache.mongodb.class%'
),
'service_connection_sqlite3_provider' => array(
'%doctrine_cache.sqlite3.class%'
),
);
foreach ($providers as $id => $value) {
$this->assertCacheProvider($container, $id, $value[0]);
}
}
public function testCustomCacheProviders()
{
$container = $this->compileContainer('custom_providers');
$providers = array(
'my_custom_type_provider' => array(
'Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Cache\MyCustomType',
array('addConfig' => array(
array('config_foo', 'foo'),
array('config_bar', 'bar'),
))
),
'my_custom_type_provider2' => array(
'Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Cache\MyCustomType',
array()
),
);
foreach ($providers as $id => $value) {
$this->assertCacheProvider($container, $id, $value[0], $value[1]);
}
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage "unrecognized_type" is an unrecognized Doctrine cache driver.
*/
public function testUnrecognizedCacheDriverException()
{
$this->compileContainer('unrecognized');
}
public function testAcl()
{
$container = $this->compileContainer('acl');
$this->assertTrue($container->hasDefinition('doctrine_cache.security.acl.cache'));
$definition = $container->getDefinition('doctrine_cache.security.acl.cache');
$this->assertEquals('Doctrine\Bundle\DoctrineCacheBundle\Acl\Model\AclCache', $definition->getClass());
$this->assertCount(2, $definition->getArguments());
$this->assertEquals('doctrine_cache.providers.acl_apc_provider', (string) $definition->getArgument(0));
$this->assertEquals('security.acl.permission_granting_strategy', (string) $definition->getArgument(1));
$this->assertFalse($definition->isPublic());
}
public function assertCacheProvider(ContainerBuilder $container, $name, $class, array $expectedCalls = array())
{
$service = "doctrine_cache.providers." . $name;
$this->assertTrue($container->hasDefinition($service));
$definition = $container->getDefinition($service);
$this->assertTrue($definition->isPublic());
$this->assertEquals($class, $definition->getClass());
foreach (array_unique($expectedCalls) as $methodName => $params) {
$this->assertMethodCall($definition, $methodName, $params);
}
}
public function assertCacheResource(ContainerBuilder $container, $name, $class, array $expectedCalls = array())
{
$service = "doctrine_cache.services.$name";
$this->assertTrue($container->hasDefinition($service));
$definition = $container->getDefinition($service);
$this->assertTrue($definition->isPublic());
$this->assertEquals($class, $definition->getClass());
foreach ($expectedCalls as $methodName => $params) {
$this->assertMethodCall($definition, $methodName, $params);
}
}
private function assertMethodCall(Definition $definition, $methodName, array $parameters = array())
{
$methodCalls = $definition->getMethodCalls();
$actualCalls = array();
foreach ($methodCalls as $call) {
$actualCalls[$call[0]][] = $call[1];
}
$this->assertArrayHasKey($methodName, $actualCalls);
$this->assertCount(count($parameters), $actualCalls[$methodName]);
foreach ($parameters as $index => $param) {
$this->assertArrayHasKey($index, $actualCalls[$methodName]);
$this->assertEquals($param, $actualCalls[$methodName][$index]);
}
}
/**
* @param string $file
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function compileContainer($file, ContainerBuilder $container = null)
{
$container = $container ?: $this->createContainer();
$cacheExtension = new DoctrineCacheExtension();
$container->registerExtension($cacheExtension);
$compilerPassConfig = $container->getCompilerPassConfig();
$compilerPassConfig->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
$compilerPassConfig->setRemovingPasses(array());
$this->loadFromFile($container, $file);
$container->compile();
return $container;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the Doctrine Bundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Fixtures\Bundles\YamlBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class XmlBundle extends Bundle
{
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the Doctrine Bundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Fixtures\Bundles\YamlBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class YamlBundle extends Bundle
{
}

View File

@@ -0,0 +1,24 @@
<?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\Tests\DependencyInjection\Fixtures\Cache;
use Doctrine\Common\Cache\ArrayCache;
class MyCustomType extends ArrayCache
{
public $configs;
public function addConfig($name, $value)
{
$this->configs[$name] = $value;
}
}

View File

@@ -0,0 +1,29 @@
<?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\Tests\DependencyInjection\Fixtures\Definition;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Definition\CacheDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class MyCustomTypeDefinition extends CacheDefinition
{
/**
* {@inheritDoc}
*/
public function configure($name, array $config, Definition $service, ContainerBuilder $container)
{
foreach ($config['custom_provider']['options'] as $name => $value) {
$service->addMethodCall('addConfig', array($name, $value));
}
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<acl-cache id="doctrine_cache.providers.acl_apc_provider"/>
<provider name="acl_apc_provider" type="apc"/>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<alias key="foo">foo_namespace_provider</alias>
<provider name="foo_namespace_provider" type="array">
<alias>fooNamespaceProvider</alias>
</provider>
<provider name="barNamespaceProvider" type="array">
<alias>bar_namespace_provider</alias>
<alias>bar</alias>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="basic_apc_provider" type="apc"/>
<provider name="basic_array_provider" type="array"/>
<provider name="basic_void_provider" type="void"/>
<provider name="basic_xcache_provider" type="xcache"/>
<provider name="basic_wincache_provider" type="wincache"/>
<provider name="basic_zenddata_provider" type="zenddata"/>
<provider name="basic_ns_zenddata_provider" type="zenddata" namespace="zenddata_ns"/>
<provider name="basic_apc_provider2">
<apc/>
</provider>
<provider name="basic_array_provider2">
<array/>
</provider>
<provider name="basic_void_provider2">
<void/>
</provider>
<provider name="basic_xcache_provider2">
<xcache/>
</provider>
<provider name="basic_wincache_provider2">
<wincache/>
</provider>
<provider name="basic_zenddata_provider2">
<zenddata/>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="configurable_apc_provider">
<apc/>
</provider>
<provider name="configurable_array_provider">
<array/>
</provider>
<provider name="configurable_chain_provider">
<chain>
<provider>configurable_array_provider</provider>
<provider>configurable_apc_provider</provider>
</chain>
</provider>
<provider name="configurable_memcached_provider">
<memcached>
<server host="memcached01.ss"/>
<server host="memcached02.ss"/>
</memcached>
</provider>
<provider name="configurable_memcache_provider">
<memcache>
<server host="memcached01.ss"/>
<server host="memcached02.ss"/>
</memcache>
</provider>
<provider name="configurable_redis_provider">
<redis host="localhost" port="11211" />
</provider>
<provider name="configurable_mongodb_provider">
<mongodb server="localhost:11211" >
<database-name>my_database</database-name>
<collection-name>my_collection</collection-name>
</mongodb>
</provider>
<provider name="configurable_riak_provider">
<riak host="localhost" port="8087">
<bucket-name>my_bucket</bucket-name>
<bucket-property-list>
<allow-multiple>false</allow-multiple>
<n-value>1</n-value>
</bucket-property-list>
</riak>
</provider>
<provider name="configurable_sqlite3_provider">
<sqlite3 file-name="cache.db" >
<table-name>my_table</table-name>
</sqlite3>
</provider>
<provider name="configurable_filesystem_provider">
<file-system extension="fsc">
<directory>%kernel.cache_dir%/configurable-filesystem-provider</directory>
</file-system>
</provider>
<provider name="configurable_phpfile_provider">
<php-file extension="phpc">
<directory>%kernel.cache_dir%/configurable-phpfile-provider</directory>
</php-file>
</provider>
<provider name="configurable_couchbase_provider">
<couchbase username="Administrator" password="password">
<bucket-name>my_bucket</bucket-name>
<hostname>127.0.0.1:809</hostname>
</couchbase>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="configurable_memcached_provider" namespace="memcached_ns">
<memcached />
</provider>
<provider name="configurable_memcache_provider">
<memcache />
</provider>
<provider name="configurable_redis_provider">
<redis />
</provider>
<provider name="configurable_mongodb_provider">
<mongodb />
</provider>
<provider name="configurable_riak_provider">
<riak />
</provider>
<provider name="configurable_filesystem_provider">
<file-system />
</provider>
<provider name="configurable_phpfile_provider">
<php-file />
</provider>
<provider name="configurable_couchbase_provider">
<couchbase />
</provider>
<provider name="configurable_memcached_provider_type" type="memcached">
<alias>memcached_provider_type</alias>
</provider>
<provider name="configurable_memcache_provider_type" type="memcache">
<alias>memcache_provider_type</alias>
</provider>
<provider name="configurable_redis_provider_type" type="redis">
<alias>redis_provider_type</alias>
</provider>
<provider name="configurable_mongodb_provider_type" type="mongodb">
<alias>mongodb_provider_type</alias>
</provider>
<provider name="configurable_riak_provider_type" type="riak">
<alias>memcached_provider_type</alias>
</provider>
<provider name="configurable_filesystem_provider_type" type="file_system">
<alias>filesystem_provider_type</alias>
</provider>
<provider name="configurable_phpfile_provider_type" type="php_file">
<alias>phpfile_provider_type</alias>
</provider>
<provider name="configurable_couchbase_provider_type" type="couchbase">
<alias>couchbase_provider_type</alias>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:services>
<srv:service id="my_custom_provider_service" class="Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Cache\MyCustomType"/>
</srv:services>
<doctrine-cache>
<custom-provider type="my_custom_type">
<prototype>my_custom_provider_service</prototype>
<definition-class>Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Definition\MyCustomTypeDefinition</definition-class>
</custom-provider>
<custom-provider type="my_custom_type2">
<prototype>my_custom_provider_service</prototype>
</custom-provider>
<provider name="my_custom_type_provider">
<my_custom_type>
<config-foo>foo</config-foo>
<config-bar>bar</config-bar>
</my_custom_type>
</provider>
<provider name="my_custom_type_provider2">
<my_custom_type2>
<config-foobar>foobar</config-foobar>
</my_custom_type2>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="foo_namespace_provider" type="array" namespace="foo_namespace"/>
<provider name="barNamespaceProvider" type="array" namespace="barNamespace"/>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,95 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<srv:services>
<srv:service id="my_riak_connection_service" class="%doctrine_cache.riak.connection.class%">
<srv:argument>localhost</srv:argument>
<srv:argument>8087</srv:argument>
</srv:service>
<srv:service id="my_riak_bucket_service" class="%doctrine_cache.riak.bucket.class%">
<srv:argument type="service" id="my_riak_connection_service"/>
<srv:argument>my_service_bucket_name</srv:argument>
</srv:service>
<srv:service id="my_sqlite3_connection_service" class="%doctrine_cache.sqlite3.connection.class%">
<srv:argument>cache.db</srv:argument>
</srv:service>
<srv:service id="my_memcached_connection_service" class="%doctrine_cache.memcached.connection.class%">
<srv:call method="addServer">
<srv:argument>localhost</srv:argument>
<srv:argument>11211</srv:argument>
</srv:call>
</srv:service>
<srv:service id="my_memcache_connection_service" class="%doctrine_cache.memcache.connection.class%">
<srv:call method="connect">
<srv:argument>localhost</srv:argument>
<srv:argument>11211</srv:argument>
</srv:call>
</srv:service>
<srv:service id="my_redis_connection_service" class="%doctrine_cache.redis.connection.class%">
<srv:call method="connect">
<srv:argument>localhost</srv:argument>
<srv:argument>6379</srv:argument>
</srv:call>
</srv:service>
<srv:service id="my_mongodb_connection_service" class="%doctrine_cache.mongodb.connection.class%">
<srv:argument>localhost:27017</srv:argument>
</srv:service>
<srv:service id="my_mongodb_collection_service" class="%doctrine_cache.mongodb.collection.class%" abstract="true">
<srv:argument>my_database</srv:argument>
<srv:argument>my_cache_collection</srv:argument>
</srv:service>
</srv:services>
<doctrine-cache>
<provider name="service_bucket_riak_provider">
<riak bucket-id="my_riak_bucket_service"/>
</provider>
<provider name="service_connection_riak_provider">
<riak connection-id="my_riak_connection_service">
<bucket-name>my_bucket_name</bucket-name>
</riak>
</provider>
<provider name="service_connection_memcached_provider">
<memcached connection-id="my_memcached_connection_service"/>
</provider>
<provider name="service_connection_memcache_provider">
<memcache>
<connection-id>my_memcache_connection_service</connection-id>
</memcache>
</provider>
<provider name="service_connection_redis_provider">
<redis connection-id="my_redis_connection_service"/>
</provider>
<provider name="service_collection_mongodb_provider">
<mongodb collection-id="my_mongodb_collection_service"/>
</provider>
<provider name="service_connection_sqlite3_provider">
<sqlite3 connection-id="my_sqlite3_connection_service" table-name="my_table"/>
</provider>
<provider name="service_connection_mongodb_provider">
<mongodb>
<connection-id>my_memcache_connection_service</connection-id>
<database-name>my_database</database-name>
<collection-name>my_cache_collection</collection-name>
</mongodb>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="unrecognized_cache_provider" type="unrecognized_type"/>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,6 @@
doctrine_cache:
acl_cache:
id: 'doctrine_cache.providers.acl_apc_provider'
providers:
acl_apc_provider:
type: 'apc'

View File

@@ -0,0 +1,13 @@
doctrine_cache:
aliases:
foo: foo_namespace_provider
providers:
foo_namespace_provider:
type: array
aliases:
- fooNamespaceProvider
barNamespaceProvider:
type: array
aliases:
- bar_namespace_provider
- bar

View File

@@ -0,0 +1,30 @@
doctrine_cache:
providers:
basic_apc_provider:
type: apc
basic_array_provider:
type: array
basic_void_provider:
type: void
basic_xcache_provider:
type: xcache
basic_wincache_provider:
type: wincache
basic_zenddata_provider:
type: zenddata
basic_ns_zenddata_provider:
type: zenddata
namespace: zenddata_ns
basic_apc_provider2:
apc: ~
basic_array_provider2:
array: ~
basic_void_provider2:
void: ~
basic_xcache_provider2:
xcache: ~
basic_wincache_provider2:
wincache: ~
basic_zenddata_provider2:
zenddata: ~

View File

@@ -0,0 +1,67 @@
doctrine_cache:
providers:
configurable_apc_provider:
apc: ~
configurable_array_provider:
array: ~
configurable_chain_provider:
chain:
providers:
- configurable_array_provider
- configurable_apc_provider
configurable_memcached_provider:
memcached:
servers:
memcached01.ss: ~
memcached02.ss: ~
configurable_memcache_provider:
memcache:
servers:
memcache01.ss: ~
memcache02.ss: ~
configurable_redis_provider:
redis:
host: localhost
port: 11211
configurable_couchbase_provider:
couchbase:
hostnames: [ 127.0.0.1:809 ]
bucket_name: my_bucket
username: Administrator
password: password
configurable_phpfile_provider:
php_file:
extension: phpc
directory: "%kernel.cache_dir%/configurable-phpfile-provider"
configurable_filesystem_provider:
file_system:
extension: fsc
directory: "%kernel.cache_dir%/configurable-filesystem-provider"
configurable_mongodb_provider:
mongodb:
server: localhost:11211
database_name: my_database
collection_name: my_collection
configurable_riak_provider:
riak:
host: localhost
port: 8087
bucket_name: my_bucket
bucket_property_list:
allow_multiple: false
n_value: 1
configurable_sqlite3_provider:
sqlite3:
file_name: cache.db
table_name: my_table

View File

@@ -0,0 +1,65 @@
doctrine_cache:
providers:
configurable_memcached_provider:
memcached: ~
configurable_memcache_provider:
memcache: ~
configurable_redis_provider:
redis: ~
configurable_couchbase_provider:
couchbase: ~
configurable_phpfile_provider:
php_file: ~
configurable_filesystem_provider:
file_system: ~
configurable_mongodb_provider:
mongodb: ~
configurable_riak_provider:
riak: ~
configurable_memcached_provider_type:
type : memcached
aliases :
- memcached_provider_type
configurable_memcache_provider_type:
type : memcache
aliases :
- memcache_provider_type
configurable_redis_provider_type:
type : redis
aliases :
- redis_provider_type
configurable_couchbase_provider_type:
type : couchbase
aliases :
- couchbase_provider_type
configurable_phpfile_provider_type:
type : php_file
aliases :
- php_file_provider_type
configurable_filesystem_provider_type:
type : file_system
aliases :
- file_system_provider_type
configurable_mongodb_provider_type:
type : mongodb
aliases :
- mongodb_provider_type
configurable_riak_provider_type:
type : riak
aliases :
- riak_provider_type

View File

@@ -0,0 +1,22 @@
services:
my_custom_provider_service:
class: Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Cache\MyCustomType
doctrine_cache:
custom_providers:
my_custom_type:
prototype: "my_custom_provider_service"
definition_class: Doctrine\Bundle\DoctrineCacheBundle\Tests\DependencyInjection\Fixtures\Definition\MyCustomTypeDefinition
my_custom_type2:
prototype: "my_custom_provider_service"
providers:
my_custom_type_provider:
my_custom_type:
config_foo: "foo"
config_bar: "bar"
my_custom_type_provider2:
my_custom_type2:
config_foobar: "foobar"

View File

@@ -0,0 +1,8 @@
doctrine_cache:
providers:
foo_namespace_provider:
type: array
namespace: foo_namespace
barNamespaceProvider:
type: array
namespace: barNamespace

View File

@@ -0,0 +1,77 @@
services:
my_memcached_connection_service:
class: "%doctrine_cache.memcached.connection.class%"
calls:
- [addServer, ["localhost", 11211]]
my_memcache_connection_service:
class: "%doctrine_cache.memcache.connection.class%"
calls:
- [connect, ["localhost", 11211]]
my_mongodb_connection_service:
class: "%doctrine_cache.mongodb.connection.class%"
arguments: ["localhost:27017"]
my_mongodb_collection_service:
class: "%doctrine_cache.mongodb.collection.class%"
arguments: ["my_database", "my_cache_collection"]
my_redis_connection_service:
class: "%doctrine_cache.redis.connection.class%"
calls:
- [connect, ["localhost", 6379]]
my_riak_connection_service:
class: "%doctrine_cache.riak.connection.class%"
arguments: ["localhost", 8087]
my_riak_bucket_service:
class: "%doctrine_cache.riak.bucket.class%"
arguments: ["@my_riak_connection_service", "my_service_bucket_name"]
my_sqlite3_connection_service:
class: "%doctrine_cache.sqlite3.connection.class%"
arguments: ["cache.db"]
doctrine_cache:
providers:
service_connection_couchbase_provider:
couchbase:
connection_id: "my_couchbase_connection_service"
service_connection_memcached_provider:
memcached:
connection_id: "my_memcached_connection_service"
service_connection_memcache_provider:
memcache:
connection_id: "my_memcache_connection_service"
service_collection_mongodb_provider:
mongodb:
collection_id: "my_mongodb_collection_service"
service_connection_mongodb_provider:
mongodb:
connection_id: "my_mongodb_connection_service"
collection_name: "my_cache_collection"
database_name: "my_database"
service_connection_redis_provider:
redis:
connection_id: "my_redis_connection_service"
service_bucket_riak_provider:
riak:
bucket_id : "my_riak_bucket_service"
service_connection_riak_provider:
riak:
connection_id: "my_riak_connection_service"
bucket_name: "my_bucket_name"
service_connection_sqlite3_provider:
sqlite3:
connection_id: "my_sqlite3_connection_service"
table_name: 'my_table'

View File

@@ -0,0 +1,4 @@
doctrine_cache:
providers:
unrecognized_cache_provider:
type: unrecognized_type

View File

@@ -0,0 +1,143 @@
<?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\Tests\DependencyInjection;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader;
/**
* @group Extension
* @group SymfonyBridge
*
* @author Kinn Coelho Julião <kinncj@php.net>
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
*/
class SymfonyBridgeAdpterTest extends TestCase
{
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter
*/
private $adapter;
protected function setUp()
{
parent::setUp();
$this->adapter = new SymfonyBridgeAdapter(new CacheProviderLoader(), 'doctrine.orm', 'orm');
}
public function providerBasicDrivers()
{
return array(
array('%doctrine_cache.apc.class%', array('type' => 'apc')),
array('%doctrine_cache.array.class%', array('type' => 'array')),
array('%doctrine_cache.xcache.class%', array('type' => 'xcache')),
array('%doctrine_cache.wincache.class%', array('type' => 'wincache')),
array('%doctrine_cache.zenddata.class%', array('type' => 'zenddata')),
array('%doctrine_cache.redis.class%', array('type' => 'redis'), array('setRedis')),
array('%doctrine_cache.memcache.class%', array('type' => 'memcache'), array('setMemcache')),
array('%doctrine_cache.memcached.class%', array('type' => 'memcached'), array('setMemcached')),
);
}
/**
* @param string $class
* @param array $config
*
* @dataProvider providerBasicDrivers
*/
public function testLoadBasicCacheDriver($class, array $config, array $expectedCalls = array())
{
$container = $this->createServiceContainer();
$cacheName = 'metadata_cache';
$objectManager = array(
'name' => 'default',
'metadata_cache_driver' => $config
);
$this->adapter->loadObjectManagerCacheDriver($objectManager, $container, $cacheName);
$this->assertTrue($container->hasAlias('doctrine.orm.default_metadata_cache'));
$alias = $container->getAlias('doctrine.orm.default_metadata_cache');
$decorator = $container->getDefinition($alias);
$definition = $container->getDefinition($decorator->getParent());
$defCalls = $decorator->getMethodCalls();
$expectedCalls[] = 'setNamespace';
$actualCalls = array_map(function ($call) {
return $call[0];
}, $defCalls);
$this->assertEquals($class, $definition->getClass());
foreach (array_unique($expectedCalls) as $call) {
$this->assertContains($call, $actualCalls);
}
}
public function testServiceCacheDriver()
{
$cacheName = 'metadata_cache';
$container = $this->createServiceContainer();
$definition = new Definition('%doctrine.orm.cache.apc.class%');
$objectManager = array(
'name' => 'default',
'metadata_cache_driver' => array(
'type' => 'service',
'id' => 'service_driver'
)
);
$container->setDefinition('service_driver', $definition);
$this->adapter->loadObjectManagerCacheDriver($objectManager, $container, $cacheName);
$this->assertTrue($container->hasAlias('doctrine.orm.default_metadata_cache'));
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage "unrecognized_type" is an unrecognized Doctrine cache driver.
*/
public function testUnrecognizedCacheDriverException()
{
$cacheName = 'metadata_cache';
$container = $this->createServiceContainer();
$objectManager = array(
'name' => 'default',
'metadata_cache_driver' => array(
'type' => 'unrecognized_type'
)
);
$this->adapter->loadObjectManagerCacheDriver($objectManager, $container, $cacheName);
}
public function testLoadServicesConfiguration()
{
$container = $this->createContainer();
$this->assertFalse($container->hasParameter('doctrine_cache.array.class'));
$this->adapter->loadServicesConfiguration($container);
$this->assertTrue($container->hasParameter('doctrine_cache.array.class'));
}
}

View File

@@ -0,0 +1,41 @@
<?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\Tests\DependencyInjection;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
/**
* @group Extension
* @group DependencyInjection
*/
class XmlDoctrineCacheExtensionTest extends AbstractDoctrineCacheExtensionTest
{
/**
* {@inheritdoc}
*/
protected function loadFromFile(ContainerBuilder $container, $file)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/xml'));
$loader->load($file . '.xml');
}
}

View File

@@ -0,0 +1,41 @@
<?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\Tests\DependencyInjection;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
/**
* @group Extension
* @group DependencyInjection
*/
class YmlDoctrineCacheExtensionTest extends AbstractDoctrineCacheExtensionTest
{
/**
* {@inheritdoc}
*/
protected function loadFromFile(ContainerBuilder $container, $file)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/yml'));
$loader->load($file . '.yml');
}
}

View File

@@ -0,0 +1,39 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group Array
*/
class ArrayCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('array');
$cache = $container->get('doctrine_cache.providers.my_array_cache');
return $cache;
}
}

View File

@@ -0,0 +1,48 @@
<?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\Tests\Functional;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\FunctionalTestCase;
/**
* @group Functional
*/
abstract class BaseCacheTest extends FunctionalTestCase
{
/**
* @return \Doctrine\Common\Cache\Cache
*/
abstract protected function createCacheDriver();
public function testCacheDriver()
{
$cache = $this->createCacheDriver();
$this->assertNotNull($cache);
$this->assertInstanceOf('Doctrine\Common\Cache\Cache', $cache);
$this->assertTrue($cache->save('key', 'value'));
$this->assertTrue($cache->contains('key'));
$this->assertEquals('value', $cache->fetch('key'));
$this->assertTrue($cache->delete('key'));
$this->assertFalse($cache->contains('key'));
}
}

View File

@@ -0,0 +1,48 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group Chain
*/
class ChainCacheTest extends BaseCacheTest
{
public function setUp()
{
parent::setUp();
if (!class_exists('Doctrine\Common\Cache\ChainCache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of ChainCache available in doctrine/cache since 1.4');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('chain');
$cache = $container->get('doctrine_cache.providers.my_chain_cache');
return $cache;
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Command;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\FunctionalTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Doctrine\Common\Cache\Cache;
use Doctrine\Bundle\DoctrineCacheBundle\Command\CacheCommand;
class CommandTestCase extends FunctionalTestCase
{
/**
* @var string
*/
protected $cacheProviderClass = 'Doctrine\Common\Cache\ArrayCache';
/**
* @var string
*/
protected $cacheName = 'my_array_cache';
/**
* @var string
*/
protected $cacheId = 'test_cache_id';
/**
* @var
*/
protected $container;
/**
* @var \Doctrine\Common\Cache\Cache
*/
protected $provider;
/**
* @var \Symfony\Component\HttpKernel\Kernel
*/
protected $kernel;
/**
* @var \Symfony\Bundle\FrameworkBundle\Console\Application
*/
protected $app;
public function setUp()
{
$this->container = $this->compileContainer('array');
$this->provider = $this->container->get('doctrine_cache.providers.' . $this->cacheName);
$this->kernel = $this->getMockKernel();
$this->app = new Application($this->kernel);
}
/**
* @param \Doctrine\Bundle\DoctrineCacheBundle\Command\CacheCommand $command
*
* @return \Symfony\Component\Console\Tester\CommandTester
*/
protected function getTester(CacheCommand $command)
{
$command->setContainer($this->container);
$command->setApplication($this->app);
return new CommandTester($command);
}
/**
* Gets Kernel mock instance
*
* @return \Symfony\Component\HttpKernel\Kernel
*/
private function getMockKernel()
{
return $this->getMock('\Symfony\Component\HttpKernel\Kernel', array(), array(), '', false, false);
}
/**
* Gets Filesystem mock instance
*
* @return \Symfony\Bundle\FrameworkBundle\Util\Filesystem
*/
private function getMockFilesystem()
{
return $this->getMock('\Symfony\Bundle\FrameworkBundle\Util\Filesystem', array(), array(), '', false, false);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Doctrine\Bundle\DoctrineCacheBundle\Command\ContainsCommand;
/**
* Functional test for delete command.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class ContainsCommandTest extends CommandTestCase
{
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\Command\ContainsCommand
*/
protected $command;
/**
* @var \Symfony\Component\Console\Tester\CommandTester
*/
protected $tester;
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->command = new ContainsCommand();
$this->tester = $this->getTester($this->command);
}
/**
* Tests if a cache does not contain an entry.
*/
public function testContainsFalse()
{
$this->tester->execute(array(
'cache-name' => $this->cacheName,
'cache-id' => $this->cacheId,
));
$this->assertEquals("FALSE\n", $this->tester->getDisplay());
}
/**
* Tests if a cache contains an entry.
*/
public function testContainsTrue()
{
$this->provider->save($this->cacheId, 'hello world');
$this->tester->execute(array(
'cache-name' => $this->cacheName,
'cache-id' => $this->cacheId,
));
$this->assertEquals("TRUE\n", $this->tester->getDisplay());
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Doctrine\Bundle\DoctrineCacheBundle\Command\DeleteCommand;
/**
* Functional test for delete command.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class DeleteCommandTest extends CommandTestCase
{
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\Command\DeleteCommand
*/
protected $command;
/**
* @var \Symfony\Component\Console\Tester\CommandTester
*/
protected $tester;
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->command = new DeleteCommand();
$this->tester = $this->getTester($this->command);
}
/**
* Tests a cache delete success.
*/
public function testDeleteSuccess()
{
$this->provider->save($this->cacheId, 'hello world');
$this->tester->execute(array(
'cache-name' => $this->cacheName,
'cache-id' => $this->cacheId,
));
$this->assertEquals("Deletion of {$this->cacheId} in {$this->cacheName} has succeeded\n", $this->tester->getDisplay());
}
/**
* Tests a cache delete all.
*/
public function testDeleteAll()
{
$this->tester->execute(array(
'cache-name' => $this->cacheName,
'cache-id' => $this->cacheId,
'--all' => true
));
$this->assertEquals("Deletion of all entries in {$this->cacheName} has succeeded\n", $this->tester->getDisplay());
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Doctrine\Bundle\DoctrineCacheBundle\Command\FlushCommand;
/**
* Functional test for delete command.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class FlushCommandTest extends CommandTestCase
{
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\Command\FlushCommand
*/
protected $command;
/**
* @var \Symfony\Component\Console\Tester\CommandTester
*/
protected $tester;
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->command = new FlushCommand();
$this->tester = $this->getTester($this->command);
}
/**
* Tests flushing a cache.
*/
public function testFlush()
{
$this->tester->execute(array(
'cache-name' => $this->cacheName,
));
$this->assertEquals("Clearing the cache for the {$this->cacheName} provider of type {$this->cacheProviderClass}\n", $this->tester->getDisplay());
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Doctrine\Bundle\DoctrineCacheBundle\Command\StatsCommand;
/**
* Functional test for delete command.
*
* @author Alan Doucette <dragonwize@gmail.com>
*/
class StatsCommandTest extends CommandTestCase
{
/**
* @var \Doctrine\Bundle\DoctrineCacheBundle\Command\StatsCommand
*/
protected $command;
/**
* @var \Symfony\Component\Console\Tester\CommandTester
*/
protected $tester;
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->command = new StatsCommand();
$this->tester = $this->getTester($this->command);
}
/**
* Tests getting cache provider stats.
*/
public function testStats()
{
$this->tester->execute(array(
'cache-name' => $this->cacheName,
));
$stats = $this->tester->getDisplay();
if (strpos($stats, 'Stats were not') === false) {
// This test is for Doctrine/Cache >= 1.6.0 only
$this->assertStringStartsWith(
"Stats for the {$this->cacheName} provider of type Doctrine\\Common\\Cache\\ArrayCache:",
$stats
);
$this->assertContains("[hits] 0\n", $stats);
$this->assertContains("[misses] 0\n", $stats);
$this->assertRegExp('/\[uptime\] [0-9]{10}' . "\n/", $stats);
$this->assertContains("[memory_usage] \n", $stats);
$this->assertContains("[memory_available] \n", $stats);
} else {
// This test is for Doctrine/Cache < 1.6.0 only
$this->assertEquals("Stats were not provided for the {$this->cacheName} provider of type Doctrine\\Common\\Cache\\ArrayCache\n", $this->tester->getDisplay());
}
}
}

View File

@@ -0,0 +1,39 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group FileSystem
*/
class FileSystemCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('file_system');
$cache = $container->get('doctrine_cache.providers.my_filesystem_cache');
return $cache;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Fixtures;
class Memcached extends \Memcached
{
protected $persistentId;
public function __construct($persistent_id = null, $callback = null)
{
parent::__construct($persistent_id, $callback);
$this->persistentId = $persistent_id;
}
public function getPersistentId()
{
return $this->persistentId;
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_array_cache" type="array" />
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_array_cache" type="array" />
<provider name="my_second_array_cache" type="array" />
<provider name="my_chain_cache">
<chain>
<provider>my_array_cache</provider>
<provider>my_second_array_cache</provider>
</chain>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_filesystem_cache">
<file-system extension="fsc">
<directory>%kernel.cache_dir%/configurable-filesystem-provider</directory>
</file-system>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_memcache_cache">
<memcache>
<server host="127.0.0.1" port="11211"/>
</memcache>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_memcached_cache">
<memcached persistent-id="app">
<server host="127.0.0.1" port="11211"/>
</memcached>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_mongodb_cache">
<mongodb server="localhost:27017" >
<database-name>my_database</database-name>
<collection-name>my_collection</collection-name>
</mongodb>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_phpfile_cache">
<php-file extension="phpc">
<directory>%kernel.cache_dir%/configurable-phpfile-provider</directory>
</php-file>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_predis_cache">
<predis scheme="tcp" host="127.0.0.1" port="6379">
<database>2</database>
<timeout>10</timeout>
<options>
<prefix>test_</prefix>
</options>
</predis>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_riak_cache">
<riak host="localhost" port="8087">
<bucket-name>my_bucket</bucket-name>
<bucket-property-list>
<allow-multiple>false</allow-multiple>
<n-value>1</n-value>
</bucket-property-list>
</riak>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_sqlite3_cache">
<sqlite3 file-name="cache.db">
<table-name>my_table</table-name>
</sqlite3>
</provider>
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://doctrine-project.org/schemas/symfony-dic/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://doctrine-project.org/schemas/symfony-dic/cache http://doctrine-project.org/schemas/symfony-dic/cache/doctrine_cache-1.0.xsd">
<doctrine-cache>
<provider name="my_void_cache" type="void" />
</doctrine-cache>
</srv:container>

View File

@@ -0,0 +1,55 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group Memcache
*/
class MemcacheCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! extension_loaded('memcache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
if (@fsockopen('localhost', 11211) === false) {
$this->markTestSkipped('The ' . __CLASS__ .' cannot connect to memcache');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('memcache');
$cache = $container->get('doctrine_cache.providers.my_memcache_cache');
return $cache;
}
}

View File

@@ -0,0 +1,68 @@
<?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\Tests\Functional;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @group Functional
* @group Memcached
*/
class MemcachedCacheTest extends BaseCacheTest
{
public function testPersistentId()
{
$cache = $this->createCacheDriver();
$this->assertEquals('app', $cache->getMemcached()->getPersistentId());
}
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! extension_loaded('memcached')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcached');
}
if (@fsockopen('localhost', 11211) === false) {
$this->markTestSkipped('The ' . __CLASS__ .' cannot connect to memcached');
}
}
protected function overrideContainer(ContainerBuilder $container)
{
$container->setParameter('doctrine_cache.memcached.connection.class', 'Doctrine\Bundle\DoctrineCacheBundle\Tests\Functional\Fixtures\Memcached');
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('memcached');
$cache = $container->get('doctrine_cache.providers.my_memcached_cache');
return $cache;
}
}

View File

@@ -0,0 +1,55 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group MongoDB
*/
class MongoDBCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! extension_loaded('mongo')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of mongo >= 1.3.0');
}
if (@fsockopen('localhost', 27017) === false) {
$this->markTestSkipped('The ' . __CLASS__ .' cannot connect to mongo');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('mongodb');
$cache = $container->get('doctrine_cache.providers.my_mongodb_cache');
return $cache;
}
}

View File

@@ -0,0 +1,39 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group PhpFile
*/
class PhpFileCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('php_file');
$cache = $container->get('doctrine_cache.providers.my_phpfile_cache');
return $cache;
}
}

View File

@@ -0,0 +1,54 @@
<?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\Tests\Functional;
/**
* Predis Driver Test
*
* @group Functional
* @group Predis
* @author Ivo Bathke <ivo.bathke@gmail.com>
*/
class PredisCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! class_exists('Doctrine\Common\Cache\PredisCache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of PredisCache available in doctrine/cache since 1.4');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('predis');
$cache = $container->get('doctrine_cache.providers.my_predis_cache');
return $cache;
}
}

View File

@@ -0,0 +1,55 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group Riak
*/
class RiakCacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! extension_loaded('riak')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of riak');
}
if (@fsockopen('localhost', 8087) === false) {
$this->markTestSkipped('The ' . __CLASS__ .' cannot connect to riak');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('riak');
$cache = $container->get('doctrine_cache.providers.my_riak_cache');
return $cache;
}
}

View File

@@ -0,0 +1,55 @@
<?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\Tests\Functional;
/**
* @group Functional
* @group Sqlite3
*/
class Sqlite3CacheTest extends BaseCacheTest
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
if ( ! extension_loaded('sqlite3')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of sqlite3');
}
if (!class_exists('Doctrine\Common\Cache\SQLite3Cache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of SQLite3Cache available in doctrine/cache since 1.4');
}
}
/**
* {@inheritDoc}
*/
protected function createCacheDriver()
{
$container = $this->compileContainer('sqlite3');
$cache = $container->get('doctrine_cache.providers.my_sqlite3_cache');
return $cache;
}
}

View File

@@ -0,0 +1,61 @@
<?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\Tests\Functional;
use Doctrine\Bundle\DoctrineCacheBundle\Tests\FunctionalTestCase;
/**
* @group Functional
* @group Void
*/
class VoidCacheTest extends BaseCacheTest
{
public function setUp()
{
parent::setUp();
if (!class_exists('Doctrine\Common\Cache\VoidCache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of VoidCache available in doctrine/cache since 1.5');
}
}
public function testCacheDriver()
{
$cache = $this->createCacheDriver();
$this->assertNotNull($cache);
$this->assertInstanceOf('Doctrine\Common\Cache\Cache', $cache);
$this->assertTrue($cache->save('key', 'value'));
$this->assertFalse($cache->contains('key'));
$this->assertFalse($cache->fetch('key'));
$this->assertTrue($cache->delete('key'));
$this->assertFalse($cache->contains('key'));
}
protected function createCacheDriver()
{
$container = $this->compileContainer('void');
$cache = $container->get('doctrine_cache.providers.my_void_cache');
return $cache;
}
}

View File

@@ -0,0 +1,69 @@
<?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\Tests;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\DoctrineCacheExtension;
class FunctionalTestCase extends TestCase
{
/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @param type $file
*/
protected function loadFromFile(ContainerBuilder $container, $file)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/Functional/Fixtures/config'));
$loader->load($file . '.xml');
}
/**
* @param string $file
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function compileContainer($file, ContainerBuilder $container = null)
{
$container = $container ?: $this->createContainer();
$loader = new DoctrineCacheExtension();
$container->registerExtension($loader);
$this->loadFromFile($container, $file);
$this->overrideContainer($container);
$container->compile();
return $container;
}
/**
* Override this hook in your functional TestCase to customize the container
*
* @param ContainerBuilder $container
*/
protected function overrideContainer(ContainerBuilder $container)
{
}
}

View File

@@ -0,0 +1,67 @@
<?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\Tests;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class TestCase extends \PHPUnit_Framework_TestCase
{
/**
* @param array $bundles
* @param string $vendor
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function createContainer(array $bundles = array('YamlBundle'), $vendor = null)
{
$mappings = array();
foreach ($bundles as $bundle) {
require_once __DIR__.'/DependencyInjection/Fixtures/Bundles/'.($vendor ? $vendor.'/' : '').$bundle.'/'.$bundle.'.php';
$mappings[$bundle] = 'DependencyInjection\\Fixtures\\Bundles\\'.($vendor ? $vendor.'\\' : '').$bundle.'\\'.$bundle;
}
return new ContainerBuilder(new ParameterBag(array(
'kernel.debug' => false,
'kernel.bundles' => $mappings,
'kernel.environment' => 'test',
'kernel.root_dir' => __DIR__.'/../',
'kernel.cache_dir' => sys_get_temp_dir(),
)));
}
/**
* @param array $bundles
* @param string $vendor
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function createServiceContainer(array $bundles = array('YamlBundle'), $vendor = null)
{
$container = $this->createContainer($bundles, $vendor);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
return $container;
}
}

View File

@@ -0,0 +1,25 @@
<?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>.
*/
if ( ! @include __DIR__ . '/../vendor/autoload.php') {
die("You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install --dev
");
}

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env sh
BASEDIR=$(dirname $0);
if [ "$TRAVIS_PHP_VERSION" = "hhvm" ]; then
exit 0;
fi
pecl install riak
phpenv config-add $BASEDIR/php.ini

View File

@@ -0,0 +1,6 @@
extension="mongo.so"
extension="memcache.so"
extension="memcached.so"
apc.enabled=1
apc.enable_cli=1

View File

@@ -0,0 +1,67 @@
{
"name": "doctrine/doctrine-cache-bundle",
"homepage": "http://www.doctrine-project.org",
"description": "Symfony Bundle for Doctrine Cache",
"keywords": ["cache", "caching"],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Fabio B. Silva",
"email": "fabio.bat.silva@gmail.com"
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@hotmail.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Doctrine Project",
"homepage": "http://www.doctrine-project.org/"
}
],
"require": {
"php": ">=5.3.2",
"symfony/doctrine-bridge": "~2.2|~3.0",
"doctrine/inflector": "~1.0",
"doctrine/cache": "^1.4.2"
},
"require-dev": {
"phpunit/phpunit": "~4",
"symfony/phpunit-bridge": "~2.7|~3.0",
"symfony/yaml": "~2.2|~3.0",
"symfony/validator": "~2.2|~3.0",
"symfony/console": "~2.2|~3.0",
"symfony/finder": "~2.2|~3.0",
"symfony/framework-bundle": "~2.2|~3.0",
"symfony/security-acl": "~2.3|~3.0",
"instaclick/coding-standard": "~1.1",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~1.5",
"instaclick/object-calisthenics-sniffs": "dev-master",
"instaclick/symfony2-coding-standard": "dev-remaster",
"predis/predis": "~0.8"
},
"suggest": {
"symfony/security-acl": "For using this bundle to cache ACLs"
},
"autoload": {
"psr-4": { "Doctrine\\Bundle\\DoctrineCacheBundle\\": "" }
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="Tests/bootstrap.php"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertErrorsToExceptions="true"
backupStaticAttributes="false"
processIsolation="false"
backupGlobals="false"
stopOnFailure="false"
syntaxCheck="false"
colors="true">
<testsuites>
<testsuite name="Symfony Bundle for Doctrine Cache">
<directory>./Tests</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>benchmark</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>./Resources</directory>
<directory>./vendor</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Instaclick">
<description>Instaclick Coding Standard</description>
<exclude-pattern>*/Resources/*</exclude-pattern>
<rule ref="./vendor/instaclick/coding-standard/Instaclick/ruleset.xml">
<exclude name="Instaclick.Namespaces.NamespaceStructure"/>
</rule>
</ruleset>