Skip to content

Commit 052fb1c

Browse files
authored
Added namespaced factory (#54)
1 parent 46fb62e commit 052fb1c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Factory/NamespacedFactory.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache organization.
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\Namespaced\NamespacedCachePool;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
17+
/**
18+
* @author Tobias Nyholm <[email protected]>
19+
*/
20+
class NamespacedFactory extends AbstractAdapterFactory
21+
{
22+
protected static $dependencies = [
23+
['requiredClass' => 'Cache\Namespaced\NamespacedCachePool', 'packageName' => 'cache/namespaced-cache'],
24+
];
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getAdapter(array $config)
30+
{
31+
return new NamespacedCachePool($config['service'], $config['namespace']);
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected static function configureOptionResolver(OptionsResolver $resolver)
38+
{
39+
parent::configureOptionResolver($resolver);
40+
41+
$resolver->setRequired(['namespace', 'service']);
42+
$resolver->setAllowedTypes('namespace', ['string']);
43+
}
44+
}

src/Resources/config/services.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
class: Cache\AdapterBundle\Factory\MemcachedFactory
1414
cache.factory.memcache:
1515
class: Cache\AdapterBundle\Factory\MemcacheFactory
16+
cache.factory.namespaced:
17+
class: Cache\AdapterBundle\Factory\NamespacedFactory
1618
cache.factory.predis:
1719
class: Cache\AdapterBundle\Factory\PredisFactory
1820
cache.factory.prefixed:

0 commit comments

Comments
 (0)