@@ -22,6 +22,9 @@ class Evictor
22
22
const DEFAULT_SLEEP_TIMEOUT = 20000 ;
23
23
const CONFIG_PATH_ENABLED = 'cache_evict/enabled ' ;
24
24
const CONFIG_PATH_LIMIT = 'cache_evict/limit ' ;
25
+ const BACKEND_OPTION_KEY_SERVER = 'server ' ;
26
+ const BACKEND_OPTION_KEY_PORT = 'port ' ;
27
+ const BACKEND_OPTION_KEY_DATABASE = 'database ' ;
25
28
26
29
/**
27
30
* @var DeploymentConfig
@@ -60,7 +63,8 @@ public function evict(): int
60
63
$ name
61
64
));
62
65
63
- if (!$ this ->isCacheConfigValid ($ cacheConfig )) {
66
+ $ backendOptions = $ this ->getConfigBackendOptions ((array )$ cacheConfig );
67
+ if (!$ this ->validateBackendOptions ($ backendOptions )) {
64
68
$ this ->logger ->debug (sprintf (
65
69
'Cache config for database "%s" config is not valid ' ,
66
70
$ name
@@ -70,9 +74,9 @@ public function evict(): int
70
74
}
71
75
72
76
$ dbKeys = $ this ->run (
73
- (string )$ this -> getCacheConfigValue ( $ name , $ cacheConfig , ' server ' ) ,
74
- (int )$ this -> getCacheConfigValue ( $ name , $ cacheConfig , ' port ' ) ,
75
- (int )$ this -> getCacheConfigValue ( $ name , $ cacheConfig , ' database ' )
77
+ (string )$ backendOptions [ self :: BACKEND_OPTION_KEY_SERVER ] ,
78
+ (int )$ backendOptions [ self :: BACKEND_OPTION_KEY_PORT ] ,
79
+ (int )$ backendOptions [ self :: BACKEND_OPTION_KEY_DATABASE ]
76
80
);
77
81
$ evictedKeys += $ dbKeys ;
78
82
@@ -86,31 +90,31 @@ public function evict(): int
86
90
* Get Cache Config Value
87
91
*
88
92
* @param array $cacheConfig
89
- * @param string $configKey
90
- * @return string
93
+ * @return array
91
94
*/
92
- private function getCacheConfigValue ( $ cacheConfig , $ configKey ): string
95
+ private function getConfigBackendOptions ( array $ cacheConfig ): array
93
96
{
94
- if (isset ($ cacheConfig ['backend_options ' ][$ configKey ])) {
95
- return $ cacheConfig ['backend_options ' ][$ configKey ];
97
+ $ backendOptions = [];
98
+ if (isset ($ cacheConfig ['backend_options ' ])) {
99
+ $ backendOptions = $ cacheConfig ['backend_options ' ];
96
100
}
97
- if (isset ($ cacheConfig ['backend_options ' ]['remote_backend_options ' ][ $ configKey ] )) {
98
- return $ cacheConfig ['backend_options ' ]['remote_backend_options ' ][ $ configKey ];
101
+ if (isset ($ cacheConfig ['backend_options ' ]['remote_backend_options ' ])) {
102
+ $ backendOptions = $ cacheConfig ['backend_options ' ]['remote_backend_options ' ];
99
103
}
100
- return '' ;
104
+ return ( array ) $ backendOptions ;
101
105
}
102
106
103
107
/**
104
108
* Validate Cache Configuration
105
109
*
106
- * @param $cacheConfig
110
+ * @param array $backendOptions
107
111
* @return bool
108
112
*/
109
- private function isCacheConfigValid ( $ cacheConfig ): bool
113
+ private function validateBackendOptions ( array $ backendOptions ): bool
110
114
{
111
- if ($ this -> getCacheConfigValue ( $ cacheConfig , ' server ' )
112
- && $ this -> getCacheConfigValue ( $ cacheConfig , ' port ' )
113
- && $ this -> getCacheConfigValue ( $ cacheConfig , ' database ' )
115
+ if (isset ( $ backendOptions [ self :: BACKEND_OPTION_KEY_SERVER ] )
116
+ && isset ( $ backendOptions [ self :: BACKEND_OPTION_KEY_PORT ] )
117
+ && isset ( $ backendOptions [ self :: BACKEND_OPTION_KEY_DATABASE ] )
114
118
) {
115
119
return true ;
116
120
}
0 commit comments