Skip to content

Commit 82b1942

Browse files
committed
Added doctrine factories
1 parent 16d9895 commit 82b1942

14 files changed

+507
-13
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
/**
15+
* @author Tobias Nyholm <[email protected]>
16+
*/
17+
abstract class AbstractDoctrineAdapterFactory extends AbstractAdapterFactory
18+
{
19+
protected static $dependencies = [
20+
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'],
21+
];
22+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Couchbase;
16+
use Doctrine\Common\Cache\CouchbaseCache;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Tobias Nyholm <[email protected]>
21+
*/
22+
class DoctrineCouchbaseFactory extends AbstractDoctrineAdapterFactory
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getAdapter(array $config)
28+
{
29+
$couchbase = new Couchbase($config['host'], $config['user'], $config['password'], $config['bucket']);
30+
31+
$client = new CouchbaseCache();
32+
$client->setCouchbase($couchbase);
33+
34+
return new DoctrineCachePool($client);
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
protected static function configureOptionResolver(OptionsResolver $resolver)
41+
{
42+
$resolver->setDefaults([
43+
'host' => '127.0.0.1',
44+
'user' => 'Administrator',
45+
'password' => 'password',
46+
'bucket' => 'default',
47+
]);
48+
49+
$resolver->setAllowedTypes('host', ['string']);
50+
$resolver->setAllowedTypes('user', ['string']);
51+
$resolver->setAllowedTypes('password', ['string']);
52+
$resolver->setAllowedTypes('bucket', ['string']);
53+
}
54+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Doctrine\Common\Cache\MemcacheCache;
16+
use Memcache;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Tobias Nyholm <[email protected]>
21+
*/
22+
class DoctrineMemcacheFactory extends AbstractDoctrineAdapterFactory
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getAdapter(array $config)
28+
{
29+
$memcache = new Memcache();
30+
$memcache->connect($config['host'], $config['port']);
31+
32+
return new DoctrineCachePool(new MemcacheCache($memcache));
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected static function configureOptionResolver(OptionsResolver $resolver)
39+
{
40+
$resolver->setDefaults([
41+
'host' => '127.0.0.1',
42+
'port' => '11211',
43+
]);
44+
45+
$resolver->setAllowedTypes('host', ['string']);
46+
$resolver->setAllowedTypes('port', ['string', 'int']);
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Doctrine\Common\Cache\MemcachedCache;
16+
use Memcached;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Tobias Nyholm <[email protected]>
21+
*/
22+
class DoctrineMemcachedFactory extends AbstractDoctrineAdapterFactory
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getAdapter(array $config)
28+
{
29+
$memcached = new Memcached();
30+
$memcached->addServer($config['host'], $config['port']);
31+
32+
return new DoctrineCachePool(new MemcachedCache($memcached));
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected static function configureOptionResolver(OptionsResolver $resolver)
39+
{
40+
$resolver->setDefaults([
41+
'host' => '127.0.0.1',
42+
'port' => '11211',
43+
]);
44+
45+
$resolver->setAllowedTypes('host', ['string']);
46+
$resolver->setAllowedTypes('port', ['string', 'int']);
47+
}
48+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Doctrine\Common\Cache\MongoDBCache;
16+
use MongoClient;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Tobias Nyholm <[email protected]>
21+
*/
22+
class DoctrineMongodDBFactory extends AbstractDoctrineAdapterFactory
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getAdapter(array $config)
28+
{
29+
$mongo = new MongoClient();
30+
$collection = $mongo->selectCollection($config['host'], $config['collection']);
31+
32+
return new DoctrineCachePool(new MongoDBCache($collection));
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected static function configureOptionResolver(OptionsResolver $resolver)
39+
{
40+
$resolver->setRequired(['host', 'collection']);
41+
42+
$resolver->setAllowedTypes('host', ['string']);
43+
$resolver->setAllowedTypes('collection', ['string']);
44+
}
45+
46+
protected static function verifyDependencies()
47+
{
48+
if (!version_compare(phpversion('mongo'), '1.3.0', '>=')) {
49+
throw new \LogicException('Mongo >= 1.3.0 is required.');
50+
}
51+
52+
parent::verifyDependencies();
53+
}
54+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Doctrine\Common\Cache\PredisCache;
16+
use Predis\Client;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Tobias Nyholm <[email protected]>
21+
*/
22+
class DoctrinePredisFactory extends AbstractDoctrineAdapterFactory
23+
{
24+
protected static $dependencies = [
25+
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'],
26+
['requiredClass' => 'Predis\Client', 'packageName' => 'predis/predis'],
27+
];
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function getAdapter(array $config)
33+
{
34+
$client = new Client([
35+
'scheme' => $config['scheme'],
36+
'host' => $config['host'],
37+
'port' => $config['port'],
38+
]);
39+
40+
return new DoctrineCachePool(new PredisCache($client));
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected static function configureOptionResolver(OptionsResolver $resolver)
47+
{
48+
$resolver->setDefaults([
49+
'host' => '127.0.0.1',
50+
'port' => '6379',
51+
'scheme' => 'tcp',
52+
]);
53+
54+
$resolver->setAllowedTypes('host', ['string']);
55+
$resolver->setAllowedTypes('port', ['string', 'int']);
56+
$resolver->setAllowedTypes('scheme', ['string']);
57+
}
58+
}

src/Factory/DoctrineRedisFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
/**
1919
* @author Tobias Nyholm <[email protected]>
2020
*/
21-
class DoctrineRedisFactory extends AbstractAdapterFactory
21+
class DoctrineRedisFactory extends AbstractDoctrineAdapterFactory
2222
{
23-
protected static $dependencies = [
24-
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'],
25-
];
26-
2723
/**
2824
* {@inheritdoc}
2925
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Adapter\Doctrine\DoctrineCachePool;
15+
use Doctrine\Common\Cache\RiakCache;
16+
use Riak\Bucket;
17+
use Riak\Connection;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
19+
20+
/**
21+
* @author Tobias Nyholm <[email protected]>
22+
*/
23+
class DoctrineRiakFactory extends AbstractDoctrineAdapterFactory
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getAdapter(array $config)
29+
{
30+
$connection = new Connection($config['host'], $config['port']);
31+
$bucket = new Bucket($connection, $config['type']);
32+
33+
return new DoctrineCachePool(new RiakCache($bucket));
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
protected static function configureOptionResolver(OptionsResolver $resolver)
40+
{
41+
$resolver->setDefaults([
42+
'host' => '127.0.0.1',
43+
'port' => '8087',
44+
'type' => null,
45+
]);
46+
47+
$resolver->setAllowedTypes('host', ['string']);
48+
$resolver->setAllowedTypes('port', ['string', 'int']);
49+
$resolver->setAllowedTypes('type', ['string', 'null']);
50+
}
51+
}

0 commit comments

Comments
 (0)