Skip to content

Commit

Permalink
Merge pull request #20 from php-cache/mongodb
Browse files Browse the repository at this point in the history
Mongodb factory
  • Loading branch information
Nyholm committed Jan 22, 2016
2 parents 04b087f + d50c886 commit 9bb5bd5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ $bundles(
);
```

Read the documentation at [www.php-cache.com/symfony/adapter-bundle](http://www.php-cache.com/en/latest/symfony/adapter-bundle/).
Read the documentation at [www.php-cache.com/symfony/adapter-bundle](http://www.php-cache.com/en/latest/symfony/adapter-bundle/).
53 changes: 53 additions & 0 deletions src/Factory/MongoDBFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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\MongoDB\MongoDBCachePool;
use MongoDB\Driver\Manager;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Tobias Nyholm <[email protected]>
*/
class MongoDBFactory extends AbstractAdapterFactory
{
protected static $dependencies = [
['requiredClass' => 'Cache\Adapter\MongoDB\MongoDBCachePool', 'packageName' => 'cache/mongodb-adapter'],
];

/**
* {@inheritdoc}
*/
public function getAdapter(array $config)
{
$manager = new Manager(sprintf('mongodb://%s:%s', $config['host'], $config['port']));
$collection = MongoDBCachePool::createCollection($manager, $config['namespace']);

return new MongoDBCachePool($collection);
}

/**
* {@inheritdoc}
*/
protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults([
'host' => '127.0.0.1',
'port' => 11211,
'namespace' => 'cache',
]);

$resolver->setAllowedTypes('host', ['string']);
$resolver->setAllowedTypes('port', ['string', 'int']);
$resolver->setAllowedTypes('namespace', ['string']);
}
}

0 comments on commit 9bb5bd5

Please sign in to comment.