Skip to content

Instantly share code, notes, and snippets.

@carteni
Last active February 9, 2017 11:56
Show Gist options
  • Save carteni/311274b97a95a52c8a8e2722b139b2df to your computer and use it in GitHub Desktop.
Save carteni/311274b97a95a52c8a8e2722b139b2df to your computer and use it in GitHub Desktop.
Symfony Validation / Caching using Predis and CacheBundle (PSR-6).
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
// AdapterBubndle & CacheBundle
new Cache\AdapterBundle\CacheAdapterBundle(),
new Cache\CacheBundle\CacheBundle(),
new AppBundle\AppBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
framework:
validation: { enable_annotations: true, cache: 'cache.service.validation' }
# -------------------------------------------------------------
# CacheBundle Configuration.
# see: http://www.php-cache.com/en/latest/symfony/cache-bundle/
# -------------------------------------------------------------
#
# Packages to download.
# $ composer predis/predis cache/adapter-bundle cache/cache-bundle cache/predis-adapter
#
# Create Predis Adapter.
# /** @var CacheItemPoolInterface $pool */
# $pool = $this->container->get('cache.provider.predis_adapter');
# or
# $pool = $this->container->get('alias.predis_adapter');
# or (the first configured adapter or a adapter named default will be aliased to service id cache).
# $cache = $this->container->get('cache');
# -------------------------------------------------------------
cache_adapter:
providers:
predis_adapter:
factory: 'cache.factory.predis'
options:
pool_namespace: '%validator.mapping.cache.prefix%'
aliases: ['alias.predis_adapter']
# To use a PSR-6 cache for the validation, use the following configuration.
cache:
validation:
enabled: true
service_id: 'cache.provider.predis_adapter'
use_tagging: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment