Skip to content

Commit 1b52477

Browse files
committed
Added a bunch of factories
1 parent fef0685 commit 1b52477

6 files changed

Lines changed: 223 additions & 0 deletions

File tree

src/Factory/ApcFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\Apc\ApcCachePool;
15+
16+
/**
17+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+
*/
19+
class ApcFactory extends AbstractAdapterFactory
20+
{
21+
protected static $dependencies = [
22+
['requiredClass' => 'Cache\Adapter\Apc\ApcCachePool', 'packageName' => 'cache/apc-adapter'],
23+
];
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getAdapter(array $config)
29+
{
30+
return new ApcCachePool();
31+
}
32+
}

src/Factory/ApcuFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\Apcu\ApcuCachePool;
15+
16+
/**
17+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+
*/
19+
class ApcuFactory extends AbstractAdapterFactory
20+
{
21+
protected static $dependencies = [
22+
['requiredClass' => 'Cache\Adapter\Apcu\ApcuCachePool', 'packageName' => 'cache/apcu-adapter'],
23+
];
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getAdapter(array $config)
29+
{
30+
return new ApcuCachePool();
31+
}
32+
}

src/Factory/ArrayFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\PHPArray\ArrayCachePool;
15+
16+
/**
17+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+
*/
19+
class ArrayFactory extends AbstractAdapterFactory
20+
{
21+
protected static $dependencies = [
22+
['requiredClass' => 'Cache\Adapter\PHPArray\ArrayCachePool', 'packageName' => 'cache/array-adapter'],
23+
];
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getAdapter(array $config)
29+
{
30+
return new ArrayCachePool();
31+
}
32+
}

src/Factory/FilesystemFactory.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\Filesystem\FilesystemCachePool;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
17+
/**
18+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
19+
*/
20+
class FilesystemFactory extends AbstractAdapterFactory
21+
{
22+
protected static $dependencies = [
23+
['requiredClass' => 'Cache\Adapter\Filesystem\FilesystemCachePool', 'packageName' => 'cache/filesystem-adapter'],
24+
];
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getAdapter(array $config)
30+
{
31+
return new FilesystemCachePool($config['flysystem']);
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected static function configureOptionResolver(OptionsResolver $resolver)
38+
{
39+
$resolver->setDefaults([
40+
'flysystem_service' => null,
41+
]);
42+
43+
$resolver->setAllowedTypes('host', ['string', 'object']);
44+
}
45+
}

src/Factory/MemcachedFactory.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\Memcached\MemcachedCachePool;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
17+
/**
18+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
19+
*/
20+
class MemcachedFactory extends AbstractAdapterFactory
21+
{
22+
protected static $dependencies = [
23+
['requiredClass' => 'Cache\Adapter\Memcached\MemcachedCachePool', 'packageName' => 'cache/memcached-adapter'],
24+
];
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getAdapter(array $config)
30+
{
31+
$client = new \Memcached();
32+
$client->addServer($config['host'], $config['port']);
33+
34+
return new MemcachedCachePool($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+
'port' => '6379',
45+
]);
46+
47+
$resolver->setAllowedTypes('host', ['string']);
48+
$resolver->setAllowedTypes('port', ['string', 'int']);
49+
}
50+
}

src/Factory/VoidFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\adapter-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
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\Void\VoidCachePool;
15+
16+
/**
17+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+
*/
19+
class VoidFactory extends AbstractAdapterFactory
20+
{
21+
protected static $dependencies = [
22+
['requiredClass' => 'Cache\Adapter\Void\VoidCachePool', 'packageName' => 'cache/void-adapter'],
23+
];
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getAdapter(array $config)
29+
{
30+
return new VoidCachePool();
31+
}
32+
}

0 commit comments

Comments
 (0)