1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Connection\PrefixedCachePoolFactory |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Connection; |
22
|
|
|
|
23
|
|
|
use Cache\Prefixed\PrefixedCachePool; |
24
|
|
|
use TechDivision\Import\ConfigurationInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Factory for prefixed array cache pool instances. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
class PrefixedCachePoolFactory |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The configuration instance. |
40
|
|
|
* |
41
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
42
|
|
|
*/ |
43
|
|
|
protected $configuration; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The cache factory instance. |
47
|
|
|
* |
48
|
|
|
* @var \TechDivision\Import\Connection\CachePoolFactoryInterface |
49
|
|
|
*/ |
50
|
|
|
protected $cachePoolFactory; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Initialize the cache adapter factory with the passed configuration instances. |
54
|
|
|
* . |
55
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
56
|
|
|
* @param \TechDivision\Import\Connection\CachePoolFactoryInterface $cachePoolFactory The cache factory instance |
57
|
|
|
*/ |
58
|
|
|
public function __construct(ConfigurationInterface $configuration, CachePoolFactoryInterface $cachePoolFactory) |
59
|
|
|
{ |
60
|
|
|
$this->configuration = $configuration; |
61
|
|
|
$this->cachePoolFactory = $cachePoolFactory; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Creates and returns the cache pool instance. |
66
|
|
|
* |
67
|
|
|
* @return \Cache\Prefixed\PrefixedCachePool The prefixed cache pool instance |
68
|
|
|
*/ |
69
|
|
|
public function createCachePool() |
70
|
|
|
{ |
71
|
|
|
return new PrefixedCachePool($this->cachePoolFactory->createCachePool(), sprintf('%s_', $this->configuration->getSerial())); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.