8000 [2.3][Enhancement][WIP] Cachebundle by vicb · Pull Request #3225 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.3][Enhancement][WIP] Cachebundle #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[CacheBundle] Import LiipDoctrineCacheBundle
  • Loading branch information
lsmith77 authored and vicb committed Feb 15, 2012
commit fdad9ecef6069c6ec5609ff3ceb62f4dac35e387
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Liip\DoctrineCacheBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface,
Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Reference,
Symfony\Component\DependencyInjection\DefinitionDecorator;

class ServiceCreationCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$namespaces = $container->getParameter('liip_doctrine_cache.namespaces');

foreach ($namespaces as $name => $config) {
$id = 'liip_doctrine_cache.'.$config['type'];
if (!$container->hasDefinition($id)) {
throw new \InvalidArgumentException('Supplied cache type is not supported: '.$config['type']);
}

$namespace = empty($config['namespace']) ? $name : $config['namespace'];
$service = $container
->setDefinition('liip_doctrine_cache.ns.'.$name, new DefinitionDecorator($id))
->addMethodCall('setNamespace', array($namespace));

switch ($config['type']) {
case 'memcache':
if (empty($config['id'])) {
throw new \InvalidArgumentException('Service id for memcache missing');
}
$service->addMethodCall('setMemcache', array(new Reference($config['id'])));
break;
case 'memcached':
if (empty($config['id'])) {
throw new \InvalidArgumentException('Service id for memcached missing');
}
$service->addMethodCall('setMemcached', array(new Reference($config['id'])));
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Liip\DoctrineCacheBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder,
Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition,
Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This class contains the configuration information for the bundle
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('liip_doctrine_cache', 'array');

$rootNode
->fixXmlConfig('namespace', 'namespaces')
->children()
->arrayNode('namespaces')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('namespace')->defaultNull()->end()
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
->scalarNode('id')->defaultNull()->end()
->end()
->end()
->end()
->end();
;

return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Liip\DoctrineCacheBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor,
Symfony\Component\Config\FileLocator,
Symfony\Component\HttpKernel\DependencyInjection\Extension,
Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* LiipDoctrineCacheExtension is an extension for the Doctrine\Common\Cache interface.
*/
class LiipDoctrineCacheExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

$container->setParameter($this->getAlias().'.namespaces', $config['namespaces']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Liip\DoctrineCacheBundle;

use Liip\DoctrineCacheBundle\DependencyInjection\Compiler\ServiceCreationCompilerPass;

use Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\HttpKernel\Bundle\Bundle;

class LiipDoctrineCacheBundle extends Bundle
{
/**
* @see Symfony\Component\HttpKernel\Bundle.Bundle::build()
*/
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new ServiceCreationCompilerPass());
}
}
64 changes: 64 additions & 0 deletions src/Symfony/Bundle/LiipDoctrineCacheBundle/README.md
EDBE
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
DoctrineCacheBundle
===================

This Bundle provides integration into Symfony2 with the Doctrine Common Cache layer

Installation
============

1. Add this bundle to your project as a Git submodule:

$ git submodule add git://github.com/liip/LiipDoctrineCacheBundle.git vendor/bundles/Liip/DoctrineCacheBundle

2. Add the Liip namespace to your autoloader:

// app/autoload.php
$loader->registerNamespaces(array(
'Liip' => __DIR__.'/../vendor/bundles',
// your other namespaces
));

3. Add this bundle to your application's kernel:

// application/ApplicationKernel.php
public function registerBundles()
{
return array(
// ...
new Liip\DoctrineCacheBundle\LiipDoctrineCacheBundle(),
// ...
);
}

Configuration
=============

Simply configure any number of cache services:

# app/config.yml
liip_doctrine_cache:
namespaces:
# name of the service (aka liip_doctrine_cache.ns.foo)
foo:
# cache namespace is "ding"
namespace: ding
# cache type is "apc"
type: apc
# name of the service (aka liip_doctrine_cache.ns.foo) and namespace
lala:
# cache type is "apc"
type: apc
# name of the service (aka liip_doctrine_cache.ns.bar)
bar:
# cache namespace is "ding"
namespace: ding
# cache type is "memcached"
type: memcached
# name of a service of class Memcached that is fully configured
id: my_memcached_service

Custom cache types
==================

Simply define a new type my defining a service named `liip_doctrine_cache.[type name]`.
Note the service needs to implement ``Doctrine\Common\Cache\Cache`` interface.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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="liip_doctrine_cache.apc.class">Doctrine\Common\Cache\ApcCache</parameter>
<parameter key="liip_doctrine_cache.array.class">Doctrine\Common\Cache\ArrayCache</parameter>
< 1E0A /td> <parameter key="liip_doctrine_cache.memcache.class">Doctrine\Common\Cache\MemcacheCache</parameter>
<parameter key="liip_doctrine_cache.memcached.class">Doctrine\Common\Cache\MemcachedCache</parameter>
<parameter key="liip_doctrine_cache.win_cache.class">Doctrine\Common\Cache\WinCacheCache</parameter>
<parameter key="liip_doctrine_cache.xcache.class">Doctrine\Common\Cache\XcacheCache</parameter>
<parameter key="liip_doctrine_cache.zend_data.class">Doctrine\Common\Cache\ZendDataCache</parameter>

</parameters>

<services>

<service id="liip_doctrine_cache.apc" class="%liip_doctrine_cache.apc.class%" abstract="true" />
<service id="liip_doctrine_cache.array" class="%liip_doctrine_cache.array.class%" abstract="true" />
<service id="liip_doctrine_cache.memcache" class="%liip_doctrine_cache.memcache.class%" abstract=" 10646 true" />
<service id="liip_doctrine_cache.memcached" class="%liip_doctrine_cache.memcached.class%" abstract="true" />
<service id="liip_doctrine_cache.win_cache" class="%liip_doctrine_cache.win_cache.class%" abstract="true" />
<service id="liip_doctrine_cache.xcache" class="%liip_doctrine_cache.xcache.class%" abstract="true" />
<service id="liip_doctrine_cache.zend_data" class="%liip_doctrine_cache.zend_data.class%" abstract="true" />

</services>

</container>
19 changes: 19 additions & 0 deletions src/Symfony/Bundle/LiipDoctrineCacheBundle/Resources/meta/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2011 Liip

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.
24 changes: 24 additions & 0 deletions src/Symfony/Bundle/LiipDoctrineCacheBundle/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "liip/doctrine-cache-bundle",
"description": "This Bundle provides integration into Symfony2 with the Doctrine Common Cache layer.",
"keywords": ["symfony2", "cache"],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Liip AG",
"homepage": "http://www.liip.ch/"
}
],
"require": {
"php": ">=5.3.0",
"symfony/symfony": ">=2.0",
"doctrine/common": ">=2.2"
},
"autoload": {
"psr-0": {
"Liip\\DoctrineCacheBundle\\": ""
}
},
"target-dir" : "Liip/DoctrineCacheBundle"
}
0