22
33namespace G4 \Session \SaveHandler ;
44
5- class Couchbase implements \Zend \Session \SaveHandler \SaveHandlerInterface
5+ use G4 \Mcache \Mcache ;
6+ use G4 \Mcache \McacheFactory ;
7+ use Laminas \Session \SaveHandler \SaveHandlerInterface ;
8+
9+ class Couchbase implements SaveHandlerInterface
610{
711
812 /**
9- * @var \G4\Mcache\ Mcache
13+ * @var Mcache
1014 */
1115 private $ mcache ;
1216
@@ -15,15 +19,15 @@ class Couchbase implements \Zend\Session\SaveHandler\SaveHandlerInterface
1519 */
1620 private $ options ;
1721
18-
1922 /**
2023 * @param array $options
24+ * @throws \Exception
2125 */
2226 public function __construct (array $ options )
2327 {
24- $ this ->options = $ options ;
25- $ this ->mcache = \ G4 \ Mcache \ McacheFactory::createInstance (
26- \ G4 \ Mcache \ McacheFactory::DRIVER_COUCHBASE ,
28+ $ this ->options = $ options ;
29+ $ this ->mcache = McacheFactory::createInstance (
30+ McacheFactory::DRIVER_COUCHBASE ,
2731 $ this ->options ,
2832 __CLASS__
2933 );
@@ -32,15 +36,15 @@ public function __construct(array $options)
3236 /**
3337 * Unnecessary for couchbase
3438 */
35- public function open ($ savePath , $ name )
39+ public function open ($ savePath , $ name ): bool
3640 {
3741 return true ;
3842 }
3943
4044 /**
4145 * Unnecessary for couchbase
4246 */
43- public function close ()
47+ public function close (): bool
4448 {
4549 return true ;
4650 }
@@ -49,7 +53,7 @@ public function close()
4953 * @param string $id
5054 * @return string
5155 */
52- public function read ($ id )
56+ public function read ($ id ): string
5357 {
5458 return $ this ->mcache
5559 ->key ($ id )
@@ -61,21 +65,22 @@ public function read($id)
6165 * @param string $data
6266 * @return bool
6367 */
64- public function write ($ id , $ data )
68+ public function write ($ id , $ data ): bool
6569 {
6670 $ result = $ this ->mcache
6771 ->key ($ id )
6872 ->value ($ data )
6973 ->expiration ($ this ->getLifetime ())
7074 ->set ();
75+
7176 return !empty ($ result );
7277 }
7378
7479 /**
7580 * @param string $id
7681 * @return bool
7782 */
78- public function destroy ($ id )
83+ public function destroy ($ id ): bool
7984 {
8085 return $ this ->mcache
8186 ->key ($ id )
@@ -85,18 +90,18 @@ public function destroy($id)
8590 /**
8691 * Unnecessary for couchbase
8792 */
88- public function gc ($ maxlifetime )
93+ public function gc ($ maxlifetime ): bool
8994 {
9095 return true ;
9196 }
9297
9398 /**
9499 * @return int
95100 */
96- private function getLifetime ()
101+ private function getLifetime (): int
97102 {
98103 return isset ($ this ->options ['lifetime ' ])
99104 ? (int ) $ this ->options ['lifetime ' ]
100105 : 0 ;
101106 }
102- }
107+ }
0 commit comments