Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit ffae180

Browse files
committed
Updated service to be provided by a service factory to avoid multiprocessor issues with PhpUnit (@Geolim4)
1 parent efd2567 commit ffae180

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parameters:
77

88
services:
99
phpfastcache:
10+
factory: ['%php_fast_cache.cache.class%', 'getInstance']
1011
class: "%php_fast_cache.cache.class%"
1112
arguments:
1213
- "%phpfastcache%"

Service/Cache.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
2626
*/
2727
class Cache
2828
{
29+
/**
30+
* @var self
31+
*/
32+
protected static $selfInstance;
33+
2934
/**
3035
* @var array
3136
*/
32-
private $config = [];
37+
protected $config = [];
3338

3439
/**
3540
* @var Stopwatch
@@ -41,7 +46,7 @@ class Cache
4146
*
4247
* @var \phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface[]
4348
*/
44-
private $cacheInstances = [];
49+
protected $cacheInstances = [];
4550

4651
/**
4752
* Cache constructor.
@@ -51,12 +56,26 @@ class Cache
5156
*
5257
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
5358
*/
54-
public function __construct($config, Stopwatch $stopwatch = null)
59+
protected function __construct($config, Stopwatch $stopwatch = null)
5560
{
5661
$this->config = (array) $config;
5762
$this->stopwatch = $stopwatch;
5863
}
5964

65+
/**
66+
* Factory instance provider
67+
*
68+
* @param array $config
69+
* @param Stopwatch $stopwatch
70+
*
71+
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
72+
* @return self
73+
*/
74+
public static function getInstance($config, Stopwatch $stopwatch = null)
75+
{
76+
return self::$selfInstance ?: self::$selfInstance = new self($config, $stopwatch);
77+
}
78+
6079
/**
6180
* Set a new cache instance
6281
*

0 commit comments

Comments
 (0)