Skip to content

Commit 8a6f132

Browse files
committed
Implements factory for cache/memcache-adapter
1 parent e8e8d18 commit 8a6f132

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/Factory/MemcacheFactory.php

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\Memcache\MemcacheCachePool;
15+
use Memcache;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
18+
/**
19+
* @author Nicholas Ruunu <[email protected]>
20+
*/
21+
class MemcacheFactory extends AbstractAdapterFactory
22+
{
23+
protected static $dependencies = [
24+
['requiredClass' => 'Cache\Adapter\Memcache\MemcacheCachePool', 'packageName' => 'cache/memcache-adapter'],
25+
];
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function getAdapter(array $config)
31+
{
32+
$client = new Memcache();
33+
$client->connect($config['host'], $config['port']);
34+
35+
return new MemcacheCachePool($client);
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected static function configureOptionResolver(OptionsResolver $resolver)
42+
{
43+
$resolver->setDefaults([
44+
'host' => '127.0.0.1',
45+
'port' => 11211,
46+
]);
47+
48+
$resolver->setAllowedTypes('host', ['string']);
49+
$resolver->setAllowedTypes('port', ['string', 'int']);
50+
}
51+
}

0 commit comments

Comments
 (0)