From 58de88e1078ced3eb101fdc78a098472bc9d1edb Mon Sep 17 00:00:00 2001
From: Alorel
-
+ CRAP
-
+
@@ -86,8 +86,8 @@
-
- 37
+
+ 39
-
+
-
__construct
+ __construct
-
setID
+ setID
-
+
-
idExists
+ idExists
-
destroySafely
+ destroySafely
-
+
-
isActive
+ getLastActiveSession
-
+
+ getLastActiveSession
+ jsonSerialize
+
+
+
+ 2
+
+
+
+
+
isActive
-
start
+ start
-
identityCheck
+ identityCheck
-
getFingerprint
+ getFingerprint
-
handleIdentityCheckFailure
+ handleIdentityCheckFailure
-
close
+ close
-
destroy
+ destroy
-
gc
+ gc
-
open
+ open
-
offsetExists
+ offsetExists
-
sessionRequiredWarning
+ sessionRequiredWarning
-
__get
+ __get
-
__set
+ __set
-
offsetGet
+ offsetGet
-
offsetSet
+ offsetSet
-
offsetUnset
+ offsetUnset
-
__destruct
+ __destruct
-
shouldBeSaved
+ shouldBeSaved
-
+
+
@@ -95,7 +97,9 @@
-
+
+
@@ -141,7 +145,7 @@
-
idExists
+ read
-
+
+
-
read
+ write
+
- 4
+ 3
-
+
+
-
@@ -210,168 +222,1217 @@
write
+ idExists
+
- 3
+ 4
-
+
+
<?php
-
+ namespace AloFramework\Session;
+
+
+
+ namespace AloFramework\Session;
+
-
- use AloFramework\Session\SessionException as SEx;
- use PDO;
- use PDOException;
+ use Psr\Log\LoggerInterface;
+
+
+
+
+ use AloFramework\Session\SessionException as SEx;
+
+
+
+
+
+ use PDO;
+
+
+
+
+
+ use PDOException;
+
+
+
+
+ use Psr\Log\LoggerInterface;
+
-
- /**
- * MySQL-based session handler
- * @author Art <a.molcanovas@gmail.com>
- */
+ class MySQLSession extends AbstractSession {
+
+
+
+
+ /**
+
+
+
+
+
+ * MySQL-based session handler
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+ */
+
+
+
+
+ class MySQLSession extends AbstractSession {
+
+
-
- /**
- * The PDO instance
- * @var PDO
- */
+ protected $client;
+
+
+
+
+ /**
+
+
+
+
+
+ * The PDO instance
+
+
+
+
+
+ * @var PDO
+
+
+
+
+
+ */
+
+
+
+
+ protected $client;
+
-
- /**
- * Constructor
- * @author Art <a.molcanovas@gmail.com>
- *
- * @param PDO $pdo PDO instance to use
- * @param Config $cfg Your custom configuration
- * @param LoggerInterface $logger A logger object. If omitted, AloFramework\Log will be used.
- */
- function __construct(PDO $pdo, Config $cfg = null, LoggerInterface $logger = null) {
+ $this->client = $pdo;
+
+
+
+
+ /**
+
+
+
+
+
+ * Constructor
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @param PDO $pdo PDO instance to use
+
+
+
+
+
+
+ * @param Config $cfg Your custom configuration
+
+
+
+
+
+
+ * @param LoggerInterface $logger A logger object. If omitted, AloFramework\Log will be used.
+
+
+
+
+
+
+ */
+
+
+
+
+
+ function __construct(PDO $pdo, Config $cfg = null, LoggerInterface $logger = null) {
+
+
+
+
+ $this->client = $pdo;
+
-
- //Parent constructor must be called after $this->client is set
- parent::__construct($cfg, $logger);
+ }
+
+
+
+
+ //Parent constructor must be called after $this->client is set
+
+
+
+
+
+
+ parent::__construct($cfg, $logger);
+
+
+
+
+ }
+
-
- /**
- * Destroy a session
- * @author Art <a.molcanovas@gmail.com>
- * @link http://php.net/manual/en/sessionhandlerinterface.destroy.php
- *
- * @param string $sessionID The session ID being destroyed.
- *
- * @return bool The return value (usually TRUE on success, FALSE on failure). Note this value is returned
- * internally to PHP for processing.
- */
- function destroy($sessionID) {
- parent::destroy($sessionID);
- try {
- $sql = $this->client->prepare('DELETE FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 1');
+ $exec = $sql->execute([$sessionID]);
+
+
+
+
+ /**
+
+
+
+
+
+ * Destroy a session
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+
+ * @link http://php.net/manual/en/sessionhandlerinterface.destroy.php
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @param string $sessionID The session ID being destroyed.
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @return bool The return value (usually TRUE on success, FALSE on failure). Note this value is returned
+
+
+
+
+
+
+ * internally to PHP for processing.
+
+
+
+
+
+
+ */
+
+
+
+
+
+ function destroy($sessionID) {
+
+
+
+
+
+ parent::destroy($sessionID);
+
+
+
+
+
+ try {
+
+
+
+
+
+ $sql = $this->client->prepare('DELETE FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 1');
+
+
+
+
+ $exec = $sql->execute([$sessionID]);
+
-
- return $exec;
- //@codeCoverageIgnoreStart
- } catch (PDOException $e) {
+ $this->log->error('Failed to remove session ' . $sessionID . ' from database: ' . $e->getMessage());
+
+
+
+
+ return $exec;
+
+
+
+
+
+ //@codeCoverageIgnoreStart
+
+
+
+
+
+ } catch (PDOException $e) {
+
+
+
+
+ $this->log->error('Failed to remove session ' . $sessionID . ' from database: ' . $e->getMessage());
+
-
- return false;
- }
- //@codeCoverageIgnoreEnd
+ }
+
+
+
+
+ return false;
+
+
+
+
+
+ }
+
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
+
+
+ }
+
-
- /**
- * Check if the given session ID exists
- * @author Art <a.molcanovas@gmail.com>
- *
- * @param string $sessionID The session ID
- *
- * @return bool
- * @throws SEx On PDOException or general query failure
- */
- protected function idExists($sessionID) {
- try {
- $sql =
+ $this->client->prepare('SELECT COUNT(*) FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 0');
+
+
+
+
+ /**
+
+
+
+
+
+ * Read session data
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+
+ * @link http://php.net/manual/en/sessionhandlerinterface.read.php
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @param string $sessionID The session id to read data for.
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @return string Returns an encoded string of the read data. If nothing was read, it must return an empty
+
+
+
+
+
+
+ * string. Note this value is returned internally to PHP for processing.
+
+
+
+
+
+
+ */
+
+
+
+
+
+ function read($sessionID) {
+
+
+
+
+
+ try {
+
+
+
+
+ $sql = $this->client->prepare('SELECT `data` FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 1');
+
-
- //@codeCoverageIgnoreStart
- if (!$sql->execute([$sessionID])) {
- throw new SEx('Failed to check if the session ID ' . $sessionID .
- ' exists: $sql->execute() returned ' . 'false', Sex::E_SECURITY_ERROR);
- } else {
- //@codeCoverageIgnoreEnd
- $exec = $sql->fetchAll(PDO::FETCH_NUM);
-
- return empty($exec) ? false : $exec[0] != 0;
- }
- //@codeCoverageIgnoreStart
- } catch (PDOException $e) {
- throw new SEx('Failed to check if the session ID ' . $sessionID . ' exists: ' . $e->getMessage(),
- SEx::E_PDO_FORWARD,
- $e);
- }
- //@codeCoverageIgnoreEnd
- }
-
- /**
- * Read session data
- * @author Art <a.molcanovas@gmail.com>
- * @link http://php.net/manual/en/sessionhandlerinterface.read.php
- *
- * @param string $sessionID The session id to read data for.
- *
- * @return string Returns an encoded string of the read data. If nothing was read, it must return an empty
- * string. Note this value is returned internally to PHP for processing.
- */
- function read($sessionID) {
- try {
- $sql = $this->client->prepare('SELECT `data` FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 1');
-
- if ($sql->execute([$sessionID])) {
- $exec = $sql->fetchAll(PDO::FETCH_COLUMN, 0);
-
- //@codeCoverageIgnoreStart
- if (!empty($exec)) {
- return $exec[0];
- }
- //@codeCoverageIgnoreEnd
+ }
+
+
+
+
+ if ($sql->execute([$sessionID])) {
+
+
+
+
+
+ $exec = $sql->fetchAll(PDO::FETCH_COLUMN, 0);
+
+
+
+
+
+
+
+
+
+
+
+ //@codeCoverageIgnoreStart
+
+
+
+
+
+ if (!empty($exec)) {
+
+
+
+
+
+ return $exec[0];
+
+
+
+
+
+ }
+
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
+
+
+
+ }
+
+
+
+
+
+ //@codeCoverageIgnoreStart
+
+
+
+
+
+ } catch (PDOException $e) {
+
+
+
+
+
+ $this->log->error('Error while fetching session data for ' . $sessionID . ': ' . $e->getMessage());
+
+
+
+
+
+
+
+
+
+
+
+ return serialize('');
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
+
+
+
+
+
+
+
+
+
+ return '';
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ /**
+
+
+
+
+
+ * Write session data
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+
+ * @link http://php.net/manual/en/sessionhandlerinterface.write.php
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @param string $sessionID The session id.
+
+
+
+
+
+
+ * @param string $sessionData The encoded session data. This data is the result of the PHP internally
+
+
+
+
+
+
+ * encoding the $_SESSION superglobal to a serialized string and passing it as
+
+
+
+
+
+
+ * this parameter. Please note sessions use an alternative serialization method.
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @return bool The return value (usually TRUE on success, FALSE on failure). Note this value is returned
+
+
+
+
+
+
+ * internally to PHP for processing.
+
+
+
+
+
+
+ */
+
+
+
+
+
+ function write($sessionID, $sessionData) {
+
+
+
+
+
+ if ($this->shouldBeSaved()) {
+
+
+
+
+
+ try {
+
+
+
+
+
+ $sql =
+
+
+
+
+
+ $this->client->prepare('REPLACE INTO `' . $this->config->table . '`(`id`,`data`) VALUES(?,?)');
+
+
+
+
+
+ $exec = $sql->execute([$sessionID, $sessionData]);
+
+
+
+
+
+
+
+
+
+
+ return $exec;
+ //@codeCoverageIgnoreStart
- } catch (PDOException $e) {
+ $this->log->error('Error while fetching session data for ' . $sessionID . ': ' . $e->getMessage());
+
+
+
+ $this->log->error('Failed to write session data for ' . $sessionID . ': ' . $e->getMessage());
+
-
+ return '';
+
+
+
+ return false;
+
- }
-
- //@codeCoverageIgnoreEnd
-
- return '';
- }
-
- /**
- * Write session data
- * @author Art <a.molcanovas@gmail.com>
- * @link http://php.net/manual/en/sessionhandlerinterface.write.php
- *
- * @param string $sessionID The session id.
- * @param string $sessionData The encoded session data. This data is the result of the PHP internally
- * encoding the $_SESSION superglobal to a serialized string and passing it as
- * this parameter. Please note sessions use an alternative serialization method.
- *
- * @return bool The return value (usually TRUE on success, FALSE on failure). Note this value is returned
- * internally to PHP for processing.
- */
- function write($sessionID, $sessionData) {
- if ($this->shouldBeSaved()) {
- try {
- $sql =
- $this->client->prepare('REPLACE INTO `' . $this->config->table . '`(`id`,`data`) VALUES(?,?)');
- $exec = $sql->execute([$sessionID, $sessionData]);
-
- return $exec;
- //@codeCoverageIgnoreStart
- } catch (PDOException $e) {
- $this->log->error('Failed to write session data for ' . $sessionID . ': ' . $e->getMessage());
-
- return false;
- }
- }
-
- return false;
- }
+ //@codeCoverageIgnoreEnd
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ return true;
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ /**
+
+
+
+
+
+ * Check if the given session ID exists
+
+
+
+
+
+
+ * @author Art <a.molcanovas@gmail.com>
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @param string $sessionID The session ID
+
+
+
+
+
+
+ *
+
+
+
+
+
+ * @return bool
+
+
+
+
+
+ * @throws SEx On PDOException or general query failure
+
+
+
+
+
+
+ */
+
+
+
+
+
+ protected function idExists($sessionID) {
+
+
+
+
+
+ try {
+
+
+
+
+
+ $sql =
+
+
+
+
+
+ $this->client->prepare('SELECT COUNT(*) FROM `' . $this->config->table . '` WHERE `id`=? LIMIT 0');
+
+
+
+
+
+
+
+
+
+
+
+ //@codeCoverageIgnoreStart
+
+
+
+
+
+ if (!$sql->execute([$sessionID])) {
+
+
+
+
+
+ throw new SEx('Failed to check if the session ID ' . $sessionID .
+
+
+
+
+
+ ' exists: $sql->execute() returned ' . 'false', Sex::E_SECURITY_ERROR);
+
+
+
+
+
+
+ } else {
+
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
+
+
+
+ $exec = $sql->fetchAll(PDO::FETCH_NUM);
+
+
+
+
+
+
+
+
+
+
+
+ return empty($exec) ? false : $exec[0] != 0;
+
+
+
+
+
+ }
+
+
+
+
+
+ //@codeCoverageIgnoreStart
+
+
+
+
+
+ } catch (PDOException $e) {
+
+
+
+
+
+ throw new SEx('Failed to check if the session ID ' . $sessionID . ' exists: ' . $e->getMessage(),
+
+
+
+
+
+ SEx::E_PDO_FORWARD,
+
+
+
+
+
+ $e);
+
+
+
+
+
+ }
+
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
+
+
+
+ }
+
+
+
+
+ //@codeCoverageIgnoreEnd
+
+
-
+ }
+
@@ -384,7 +1445,10 @@
+
+
+ }
+ Legend
Dead Code
- Generated by PHP_CodeCoverage 3.0.2 using PHP 5.6.15 and PHPUnit 5.0.9 at Sat Nov 14 14:52:38 GMT 2015. + Generated by PHP_CodeCoverage + 3.1.1 using PHP 5.6.18 and PHPUnit + 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. +
diff --git a/coverage/RedisSession.php.html b/coverage/RedisSession.php.html index e9d1072..42ded66 100644 --- a/coverage/RedisSession.php.html +++ b/coverage/RedisSession.php.html @@ -66,7 +66,9 @@- Generated by PHP_CodeCoverage 3.0.2 using PHP 5.6.15 and PHPUnit 5.0.9 at Sat Nov 14 14:52:38 GMT 2015. + Generated by PHP_CodeCoverage + 3.1.1 using PHP 5.6.18 and PHPUnit + 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. +
diff --git a/coverage/SessionException.php.html b/coverage/SessionException.php.html index f040b8c..7d293cb 100644 --- a/coverage/SessionException.php.html +++ b/coverage/SessionException.php.html @@ -143,7 +143,10 @@- Generated by PHP_CodeCoverage 3.0.2 using PHP 5.6.15 and PHPUnit 5.0.9 at Sat Nov 14 14:52:38 GMT 2015. + Generated by PHP_CodeCoverage + 3.1.1 using PHP 5.6.18 and PHPUnit + 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. +
diff --git a/coverage/Token.php.html b/coverage/Token.php.html index 4d88751..2e85215 100644 --- a/coverage/Token.php.html +++ b/coverage/Token.php.html @@ -57,7 +57,9 @@