@@ -22,17 +22,31 @@ class MemCacheRead implements \YetAnotherWebStack\PhpMemcachedSession\Interfaces
22
22
*/
23
23
protected $ memcache ;
24
24
25
+ /**
26
+ *
27
+ * @var \Psr\Log\LoggerInterface
28
+ */
29
+ protected $ logger ;
30
+
31
+ /**
32
+ *
33
+ * @var \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration
34
+ */
35
+ protected $ configuration ;
36
+
25
37
/**
26
38
* parma \Memcached $memcache
27
39
*/
28
- public function __construct (\Memcached $ memcache ) {
40
+ public function __construct (\Memcached $ memcache ,
41
+ \Psr \Log \LoggerInterface $ logger ,
42
+ \YetAnotherWebStack \PhpMemcachedSession \Interfaces \Configuration $ configuration ) {
29
43
$ this ->memcache = $ memcache ;
44
+ $ this ->logger = $ logger ;
45
+ $ this ->configuration = $ configuration ;
30
46
$ this ->memcache ->setOption (\Memcached::OPT_BINARY_PROTOCOL , true );
31
47
$ this ->setMemcacheLogin ();
32
48
$ this ->initializeServer ();
33
- $ this ->duration = DependencyInjector::get (
34
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
35
- )->getGeneral ("gc_maxlifetime " );
49
+ $ this ->duration = $ configuration ->getGeneral ("gc_maxlifetime " );
36
50
if (!$ this ->duration ) {
37
51
$ this ->duration = 3600 ;
38
52
}
@@ -43,19 +57,10 @@ public function __construct(\Memcached $memcache) {
43
57
* add login data if provided
44
58
*/
45
59
protected function setMemcacheLogin () {
46
- if (\YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
47
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
48
- )->getSpecific ('memcache_user ' ) &&
49
- \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
50
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
51
- )->getSpecific ('memcache_password ' )) {
60
+ if ($ this ->configuration ->getSpecific ('memcache_user ' ) && $ this ->configuration ->getSpecific ('memcache_password ' )) {
52
61
$ this ->memcache ->setSaslAuthData (
53
- \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
54
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
55
- )->getSpecific ('memcache_user ' ),
56
- \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
57
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
58
- )->getSpecific ('memcache_password ' )
62
+ $ this ->configuration ->getSpecific ('memcache_user ' ),
63
+ $ this ->configuration ->getSpecific ('memcache_password ' )
59
64
);
60
65
}
61
66
}
@@ -66,12 +71,8 @@ protected function setMemcacheLogin() {
66
71
protected function initializeServer () {
67
72
if (count ($ this ->memcache ->getServerList ()) == 0 ) {
68
73
$ this ->memcache ->addServer (
69
- \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
70
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
71
- )->getSpecific ('memcache_server ' ),
72
- \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
73
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
74
- )->getSpecific ('memcache_port ' )
74
+ $ this ->configuration ->getSpecific ('memcache_server ' ),
75
+ $ this ->configuration ->getSpecific ('memcache_port ' )
75
76
);
76
77
}
77
78
}
@@ -98,10 +99,10 @@ public function getByKey(array $params) {
98
99
$ this ->memcache ->touch ($ this ->getKey ($ params ),
99
100
time () + $ this ->duration );
100
101
}
101
- $ unserializer = \YetAnotherWebStack \PhpMemcachedSession \Service \DependencyInjector::get (
102
- 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration '
103
- )->getSpecific ('unserializer ' );
102
+ $ unserializer = $ this ->configuration ->getSpecific ('unserializer ' );
104
103
if ($ unserializer && is_callable ($ unserializer )) {
104
+ $ this ->logger ->debug ("re-serializing value of " . implode ('. ' ,
105
+ $ params ));
105
106
$ value = serialize (call_user_func ($ unserializer , $ value ));
106
107
}
107
108
return $ value ;
@@ -114,6 +115,8 @@ public function getByKey(array $params) {
114
115
* @return boolean
115
116
*/
116
117
public function setByKey (array $ params , $ value ) {
118
+ $ this ->logger ->debug ("will not set value $ value at " . implode ('. ' ,
119
+ $ params ));
117
120
return false ;
118
121
}
119
122
@@ -123,6 +126,7 @@ public function setByKey(array $params, $value) {
123
126
* @return boolean
124
127
*/
125
128
public function removeByKey (array $ params ) {
129
+ $ this ->logger ->debug ("will not delete " . implode ('. ' , $ params ));
126
130
return false ;
127
131
}
128
132
0 commit comments