-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Nyholm/doctrine
Added doctrine factories
- Loading branch information
Showing
14 changed files
with
507 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
abstract class AbstractDoctrineAdapterFactory extends AbstractAdapterFactory | ||
{ | ||
protected static $dependencies = [ | ||
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Couchbase; | ||
use Doctrine\Common\Cache\CouchbaseCache; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineCouchbaseFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$couchbase = new Couchbase($config['host'], $config['user'], $config['password'], $config['bucket']); | ||
|
||
$client = new CouchbaseCache(); | ||
$client->setCouchbase($couchbase); | ||
|
||
return new DoctrineCachePool($client); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'host' => '127.0.0.1', | ||
'user' => 'Administrator', | ||
'password' => 'password', | ||
'bucket' => 'default', | ||
]); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('user', ['string']); | ||
$resolver->setAllowedTypes('password', ['string']); | ||
$resolver->setAllowedTypes('bucket', ['string']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Doctrine\Common\Cache\MemcacheCache; | ||
use Memcache; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineMemcacheFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$memcache = new Memcache(); | ||
$memcache->connect($config['host'], $config['port']); | ||
|
||
return new DoctrineCachePool(new MemcacheCache($memcache)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'host' => '127.0.0.1', | ||
'port' => '11211', | ||
]); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('port', ['string', 'int']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Doctrine\Common\Cache\MemcachedCache; | ||
use Memcached; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineMemcachedFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$memcached = new Memcached(); | ||
$memcached->addServer($config['host'], $config['port']); | ||
|
||
return new DoctrineCachePool(new MemcachedCache($memcached)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'host' => '127.0.0.1', | ||
'port' => '11211', | ||
]); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('port', ['string', 'int']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Doctrine\Common\Cache\MongoDBCache; | ||
use MongoClient; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineMongodDBFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$mongo = new MongoClient(); | ||
$collection = $mongo->selectCollection($config['host'], $config['collection']); | ||
|
||
return new DoctrineCachePool(new MongoDBCache($collection)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setRequired(['host', 'collection']); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('collection', ['string']); | ||
} | ||
|
||
protected static function verifyDependencies() | ||
{ | ||
if (!version_compare(phpversion('mongo'), '1.3.0', '>=')) { | ||
throw new \LogicException('Mongo >= 1.3.0 is required.'); | ||
} | ||
|
||
parent::verifyDependencies(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Doctrine\Common\Cache\PredisCache; | ||
use Predis\Client; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrinePredisFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
protected static $dependencies = [ | ||
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'], | ||
['requiredClass' => 'Predis\Client', 'packageName' => 'predis/predis'], | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$client = new Client([ | ||
'scheme' => $config['scheme'], | ||
'host' => $config['host'], | ||
'port' => $config['port'], | ||
]); | ||
|
||
return new DoctrineCachePool(new PredisCache($client)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'host' => '127.0.0.1', | ||
'port' => '6379', | ||
'scheme' => 'tcp', | ||
]); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('port', ['string', 'int']); | ||
$resolver->setAllowedTypes('scheme', ['string']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,8 @@ | |
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineRedisFactory extends AbstractAdapterFactory | ||
class DoctrineRedisFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
protected static $dependencies = [ | ||
['requiredClass' => 'Cache\Adapter\Doctrine\DoctrineCachePool', 'packageName' => 'cache/doctrine-adapter'], | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\adapter-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\AdapterBundle\Factory; | ||
|
||
use Cache\Adapter\Doctrine\DoctrineCachePool; | ||
use Doctrine\Common\Cache\RiakCache; | ||
use Riak\Bucket; | ||
use Riak\Connection; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class DoctrineRiakFactory extends AbstractDoctrineAdapterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter(array $config) | ||
{ | ||
$connection = new Connection($config['host'], $config['port']); | ||
$bucket = new Bucket($connection, $config['type']); | ||
|
||
return new DoctrineCachePool(new RiakCache($bucket)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function configureOptionResolver(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'host' => '127.0.0.1', | ||
'port' => '8087', | ||
'type' => null, | ||
]); | ||
|
||
$resolver->setAllowedTypes('host', ['string']); | ||
$resolver->setAllowedTypes('port', ['string', 'int']); | ||
$resolver->setAllowedTypes('type', ['string', 'null']); | ||
} | ||
} |
Oops, something went wrong.