Skip to content

Commit 01989f8

Browse files
committed
multiple fixes to namespaces
fixes to interface-compatibility
1 parent 30be717 commit 01989f8

File tree

9 files changed

+41
-25
lines changed

9 files changed

+41
-25
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "idrinth/php-memcached-session",
2+
"name": "Yet-Another-Web-Stack/php-memcached-session",
33
"description": "Provides a sessionhandler for php and memcached",
44
"license": "MIT",
55
"type": "library",

src/Controller/Session.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
namespace YetAnotherWebStack\PhpMemcachedSession\Controller;
44

5-
class Session implements YetAnotherWebStack\PhpMemcachedSession\Interfaces\Controller {
5+
class Session implements \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Controller {
6+
7+
/**
8+
*
9+
* @var string
10+
*/
11+
protected static $model = 'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model';
612

713
/**
814
*
@@ -55,8 +61,7 @@ public function create_sid() {
5561
public function destroy($session_id) {
5662
$this->logger->debug("Destroying session");
5763
return \YetAnotherWebStack\PhpMemcachedSession\Service\DependencyInjector::get(
58-
'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model',
59-
[':sessionId' => $session_id])->delete();
64+
self::$model, [':sessionId' => $session_id])->delete();
6065
}
6166

6267
/**
@@ -88,8 +93,7 @@ public function open($save_path, $name) {
8893
public function read($session_id) {
8994
$this->logger->debug("Trying read session $session_id");
9095
return \YetAnotherWebStack\PhpMemcachedSession\Service\DependencyInjector::get(
91-
'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model',
92-
['sessionId' => $session_id])->load();
96+
self::$model, [':sessionId' => $session_id])->load();
9397
}
9498

9599
/**
@@ -101,8 +105,7 @@ public function read($session_id) {
101105
public function write($session_id, $session_data) {
102106
$this->logger->debug("Trying write to the session $session_id");
103107
return \YetAnotherWebStack\PhpMemcachedSession\Service\DependencyInjector::get(
104-
'YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model',
105-
['sessionId' => $session_id])->save($session_data);
108+
self::$model, [':sessionId' => $session_id])->save($session_data);
106109
}
107110

108111
}

src/Interfaces/Configuration.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ interface Configuration {
99
* @param string $key
1010
* @return mixed
1111
*/
12-
public function getGeneral(string $key);
12+
public function getGeneral($key);
1313

1414
/**
1515
*
1616
* @param string $key
1717
* @return mixed
1818
*/
19-
public function getSpecific(string $key);
19+
public function getSpecific($key);
2020

2121
/**
2222
*
2323
* @param string $key
2424
* @param mixed $value
2525
* @return mixed
2626
*/
27-
public function setGeneral(string $key, $value);
27+
public function setGeneral($key, $value);
2828

2929
/**
3030
*
3131
* @param string $key
3232
* @param mixed $value
3333
* @return mixed
3434
*/
35-
public function setSpecific(string $key, $value);
35+
public function setSpecific($key, $value);
3636
}

src/Interfaces/Model.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ interface Model {
99
* @param string $sessionId
1010
* @param \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository
1111
*/
12-
public function __construct(string $sessionId,
13-
\YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository);
12+
public function __construct($sessionId,
13+
\YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository,
14+
\Psr\Log\LoggerInterface $logger);
1415

1516
/**
1617
*
@@ -23,7 +24,7 @@ public function load();
2324
* @param string $data
2425
* @return boolean was it saved?
2526
*/
26-
public function save(string $data);
27+
public function save($data);
2728

2829
/**
2930
* deletes the current data and instance

src/Interfaces/Repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getByKey(array $params);
1717
* @param string $value
1818
* @return boolean
1919
*/
20-
public function setByKey(array $params, string $value);
20+
public function setByKey(array $params, $value);
2121

2222
/**
2323
*

src/Model/Session.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace YetAnotherWebStack\PhpMemcachedSession\Model;
44

5-
class Session implements YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model {
5+
class Session implements \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model {
66

77
/**
88
*
@@ -40,12 +40,18 @@ class Session implements YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model
4040
*/
4141
protected $logger;
4242

43+
/**
44+
*
45+
* @var boolean
46+
*/
47+
protected $wasStored = false;
48+
4349
/**
4450
*
4551
* @param string $sessionId
4652
* @param \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository
4753
*/
48-
protected function __construct($sessionId,
54+
public function __construct($sessionId,
4955
\YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository,
5056
\Psr\Log\LoggerInterface $logger) {
5157
$this->logger = $logger;
@@ -67,7 +73,7 @@ protected function getKeys() {
6773
/**
6874
* stores the sessionId
6975
*/
70-
protected function __destruct() {
76+
public function __destruct() {
7177
$this->save(serialize($_SESSION));
7278
$this->logger->debug("Saved session");
7379
}
@@ -77,7 +83,7 @@ protected function __destruct() {
7783
* @return string a serialized string
7884
*/
7985
public function load() {
80-
$this->original = $this->getByKey($this->getKeys()) . '';
86+
$this->original = $this->repository->getByKey($this->getKeys()) . '';
8187
$this->logger->debug("Loading session");
8288
return $this->original;
8389
}
@@ -88,12 +94,17 @@ public function load() {
8894
* @return boolean was it saved?
8995
*/
9096
public function save($data) {
97+
if ($this->wasStored) {
98+
$this->logger->debug("Already saved, nothing to store");
99+
return;
100+
}
101+
$this->wasStored;
91102
if ($data === $this->original) {
92103
$this->logger->debug("Session unchanged, nothing to store");
93104
return true; //nothing to change
94105
}
95106
$this->logger->debug("Session changed, storing");
96-
return $this->repository->updateByKey($this->getKeys(), $data);
107+
return $this->repository->setByKey($this->getKeys(), $data);
97108
}
98109

99110
/**

src/Repository/MemCacheRead.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function __construct(\Memcached $memcache,
5757
* add login data if provided
5858
*/
5959
protected function setMemcacheLogin() {
60-
if ($this->configuration->getSpecific('memcache_user') && $this->configuration->getSpecific('memcache_password')) {
60+
if ($this->configuration->getSpecific('memcache_user') &&
61+
$this->configuration->getSpecific('memcache_password')) {
6162
$this->memcache->setSaslAuthData(
6263
$this->configuration->getSpecific('memcache_user'),
6364
$this->configuration->getSpecific('memcache_password')

src/Service/Configuration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace YetAnotherWebStack\PhpMemcachedSession\Service;
44

5-
class Configuration {
5+
class Configuration implements \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Configuration {
66

77
/**
88
*
@@ -36,7 +36,7 @@ public function getGeneral($key) {
3636
*/
3737
public function getSpecific($key) {
3838
$value = ini_get(self::$iniPrefix . '.' . $key);
39-
if ($value === null && !isset(self::$defaults[$key])) {
39+
if (!$value && !isset(self::$defaults[$key])) {
4040
return null;
4141
}
4242
return self::$defaults[$key];

src/Service/DependencyInjector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DependencyInjector {
1414
* param string $interface
1515
* @return \stdClass
1616
*/
17-
public static function get($interface, $arguments) {
17+
public static function get($interface, $arguments = array()) {
1818
if (!self::$instance) {
1919
self::$instance = new \Auryn\Injector();
2020
}

0 commit comments

Comments
 (0)