@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | parent::__construct($config, $logger); |
47 | 47 | $this->tablename = isset($config['table']) ? $config['table'] : 'tiqruser'; |
48 | 48 | try { |
49 | - $this->handle = new PDO($config['dsn'],$config['username'],$config['password']); |
|
49 | + $this->handle = new PDO($config['dsn'], $config['username'], $config['password']); |
|
50 | 50 | } catch (PDOException $e) { |
51 | 51 | $this->logger->error( |
52 | 52 | sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage()) |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | } else { |
62 | 62 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
63 | 63 | } |
64 | - if ($sth->execute(array($displayName,$userId))){ |
|
64 | + if ($sth->execute(array($displayName, $userId))) { |
|
65 | 65 | return $this->userExists($userId); |
66 | 66 | } |
67 | 67 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function setNotificationType($userId, $type) |
107 | 107 | { |
108 | 108 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET notificationtype = ? WHERE userid = ?"); |
109 | - if (!$sth->execute(array($type,$userId))) { |
|
109 | + if (!$sth->execute(array($type, $userId))) { |
|
110 | 110 | throw new ReadWriteException('Unable to set the notification type in user storage for a given user (PDO)'); |
111 | 111 | } |
112 | 112 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | public function setNotificationAddress($userId, $address) |
124 | 124 | { |
125 | 125 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET notificationaddress = ? WHERE userid = ?"); |
126 | - if (!$sth->execute(array($address,$userId))) { |
|
126 | + if (!$sth->execute(array($address, $userId))) { |
|
127 | 127 | throw new ReadWriteException('Unable to set the notification address in user storage for a given user (PDO)'); |
128 | 128 | |
129 | 129 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function setLoginAttempts($userId, $amount) |
142 | 142 | { |
143 | 143 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET loginattempts = ? WHERE userid = ?"); |
144 | - if (!$sth->execute(array($amount,$userId))) { |
|
144 | + if (!$sth->execute(array($amount, $userId))) { |
|
145 | 145 | throw new ReadWriteException('Unable to set login attempts in user storage for a given user (PDO)'); |
146 | 146 | } |
147 | 147 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | public function setTemporaryBlockAttempts($userId, $amount) { |
176 | 176 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET tmpblockattempts = ? WHERE userid = ?"); |
177 | - if (!$sth->execute(array($amount,$userId))) { |
|
177 | + if (!$sth->execute(array($amount, $userId))) { |
|
178 | 178 | throw new ReadWriteException('Unable to set temp login attempts in user storage for a given user (PDO)'); |
179 | 179 | } |
180 | 180 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | public function setTemporaryBlockTimestamp($userId, $timestamp) |
200 | 200 | { |
201 | 201 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET tmpblocktimestamp = ? WHERE userid = ?"); |
202 | - if (!$sth->execute(array($timestamp,$userId))) { |
|
202 | + if (!$sth->execute(array($timestamp, $userId))) { |
|
203 | 203 | throw new ReadWriteException('Unable to update temp lock timestamp in user storage for a given user (PDO)'); |
204 | 204 | } |
205 | 205 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param int $expire The expiration (in seconds) of the data |
25 | 25 | * @throws ReadWriteException |
26 | 26 | */ |
27 | - public function setValue($key, $value, $expire=0); |
|
27 | + public function setValue($key, $value, $expire = 0); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Remove a value from the state storage |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | private function cleanExpired() { |
75 | 75 | $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
76 | 76 | $result = $sth->execute(array(time())); |
77 | - if (!$result || $sth->rowCount() === 0){ |
|
77 | + if (!$result || $sth->rowCount() === 0) { |
|
78 | 78 | // No exception is thrown here. The application can continue with expired state for now. |
79 | 79 | $this->logger->error('Unable to remove expired keys from the pdo state storage'); |
80 | 80 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * (non-PHPdoc) |
85 | 85 | * @see library/tiqr/Tiqr/StateStorage/Tiqr_StateStorage_Abstract::setValue() |
86 | 86 | */ |
87 | - public function setValue($key, $value, $expire=0) |
|
87 | + public function setValue($key, $value, $expire = 0) |
|
88 | 88 | { |
89 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
89 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
90 | 90 | $this->cleanExpired(); |
91 | 91 | } |
92 | 92 | if ($this->keyExists($key)) { |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | } |
97 | 97 | // $expire == 0 means never expire |
98 | 98 | if ($expire != 0) { |
99 | - $expire+=time(); // Store unix timestamp after which the expires |
|
99 | + $expire += time(); // Store unix timestamp after which the expires |
|
100 | 100 | } |
101 | - if (!$sth->execute(array(serialize($value),$expire,$key))) { |
|
101 | + if (!$sth->execute(array(serialize($value), $expire, $key))) { |
|
102 | 102 | throw new ReadWriteException(sprintf('Unable to store "%s" state to the PDO', $key)); |
103 | 103 | } |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function unsetValue($key) |
111 | 111 | { |
112 | 112 | if ($this->keyExists($key)) { |
113 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
113 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
114 | 114 | $result = $sth->execute(array($key)); |
115 | 115 | if (!$result || $sth->rowCount() === 0) { |
116 | 116 | throw new ReadWriteException( |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->logger->error('Unable to prepare the get key statement'); |
138 | 138 | return NULL; |
139 | 139 | } |
140 | - if (false === $sth->execute(array($key, time())) ) { |
|
140 | + if (false === $sth->execute(array($key, time()))) { |
|
141 | 141 | $this->logger->error('Unable to get key from the pdo state storage'); |
142 | 142 | return NULL; |
143 | 143 | } |
@@ -1,102 +1,102 @@ |
||
1 | 1 | <?php |
2 | 2 | class Tiqr_AutoLoader { |
3 | 3 | |
4 | - protected static $instance; |
|
5 | - |
|
6 | - protected $tiqrPath; |
|
7 | - protected $qrcodePath; |
|
8 | - protected $zendPath; |
|
9 | - |
|
10 | - protected function __construct($options) { |
|
11 | - if ($options !== NULL) { |
|
12 | - $this->setOptions($options); |
|
13 | - } |
|
14 | - spl_autoload_register(array(__CLASS__, 'autoload')); |
|
15 | - } |
|
16 | - |
|
17 | - public static function getInstance($options = NULL) { |
|
18 | - if (null === self::$instance) { |
|
19 | - self::$instance = new self($options); |
|
20 | - } |
|
21 | - |
|
22 | - return self::$instance; |
|
23 | - } |
|
24 | - |
|
25 | - public static function autoload($className) { |
|
26 | - if($className === NULL) { |
|
27 | - return; |
|
28 | - } |
|
29 | - |
|
30 | - $self = self::getInstance(); |
|
31 | - |
|
32 | - $substr5 = substr($className, 0, 5); |
|
33 | - |
|
34 | - if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') { |
|
35 | - $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
36 | - } elseif ($className === 'QRcode') { |
|
37 | - $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php'; |
|
38 | - } elseif ($substr5 === 'Zend_') { |
|
39 | - $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
4 | + protected static $instance; |
|
5 | + |
|
6 | + protected $tiqrPath; |
|
7 | + protected $qrcodePath; |
|
8 | + protected $zendPath; |
|
9 | + |
|
10 | + protected function __construct($options) { |
|
11 | + if ($options !== NULL) { |
|
12 | + $this->setOptions($options); |
|
13 | + } |
|
14 | + spl_autoload_register(array(__CLASS__, 'autoload')); |
|
15 | + } |
|
16 | + |
|
17 | + public static function getInstance($options = NULL) { |
|
18 | + if (null === self::$instance) { |
|
19 | + self::$instance = new self($options); |
|
20 | + } |
|
21 | + |
|
22 | + return self::$instance; |
|
23 | + } |
|
24 | + |
|
25 | + public static function autoload($className) { |
|
26 | + if($className === NULL) { |
|
27 | + return; |
|
28 | + } |
|
29 | + |
|
30 | + $self = self::getInstance(); |
|
31 | + |
|
32 | + $substr5 = substr($className, 0, 5); |
|
33 | + |
|
34 | + if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') { |
|
35 | + $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
36 | + } elseif ($className === 'QRcode') { |
|
37 | + $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php'; |
|
38 | + } elseif ($substr5 === 'Zend_') { |
|
39 | + $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
40 | 40 | } elseif ($className === 'ReadWriteException') { |
41 | 41 | $file = $self->tiqrPath . DIRECTORY_SEPARATOR . 'Tiqr/Exception/ReadWriteException.php'; |
42 | - } else { |
|
43 | - return; |
|
44 | - } |
|
45 | - |
|
46 | - if (file_exists($file)) { |
|
47 | - require_once($file); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function setOptions($options) { |
|
52 | - if (isset($options["tiqr.path"])) { |
|
53 | - $tiqr_dir = $options["tiqr.path"]; |
|
54 | - $tiqr_path = realpath($tiqr_dir); |
|
55 | - } else { |
|
56 | - $tiqr_dir = dirname(__FILE__); |
|
57 | - $tiqr_path = $tiqr_dir; |
|
58 | - } |
|
59 | - if (is_dir($tiqr_path)) { |
|
60 | - $this->tiqrPath = $tiqr_path; |
|
61 | - } else { |
|
62 | - throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE)); |
|
63 | - } |
|
64 | - |
|
65 | - if (isset($options["phpqrcode.path"])) { |
|
66 | - $qrcode_dir = $options["phpqrcode.path"]; |
|
67 | - $qrcode_path = realpath($qrcode_dir); |
|
68 | - } else { |
|
69 | - $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode'; |
|
70 | - $qrcode_path = $qrcode_dir; |
|
71 | - } |
|
72 | - |
|
73 | - if (is_dir($qrcode_path)) { |
|
74 | - $this->qrcodePath = $qrcode_path; |
|
75 | - } else { |
|
76 | - throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE)); |
|
77 | - } |
|
78 | - |
|
79 | - if (isset($options["zend.path"])) { |
|
80 | - $zend_dir = $options["zend.path"]; |
|
81 | - $zend_path = realpath($zend_dir); |
|
82 | - } else { |
|
83 | - $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend"; |
|
84 | - $zend_path = $zend_dir; |
|
85 | - } |
|
86 | - if (is_dir($zend_path)) { |
|
87 | - $this->zendPath = $zend_path; |
|
88 | - } else { |
|
89 | - throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE)); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - public function setIncludePath() { |
|
95 | - set_include_path(implode(PATH_SEPARATOR, array( |
|
96 | - $this->tiqrPath, |
|
97 | - $this->zendPath, |
|
98 | - $this->qrcodePath, |
|
99 | - get_include_path(), |
|
100 | - ))); |
|
101 | - } |
|
42 | + } else { |
|
43 | + return; |
|
44 | + } |
|
45 | + |
|
46 | + if (file_exists($file)) { |
|
47 | + require_once($file); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function setOptions($options) { |
|
52 | + if (isset($options["tiqr.path"])) { |
|
53 | + $tiqr_dir = $options["tiqr.path"]; |
|
54 | + $tiqr_path = realpath($tiqr_dir); |
|
55 | + } else { |
|
56 | + $tiqr_dir = dirname(__FILE__); |
|
57 | + $tiqr_path = $tiqr_dir; |
|
58 | + } |
|
59 | + if (is_dir($tiqr_path)) { |
|
60 | + $this->tiqrPath = $tiqr_path; |
|
61 | + } else { |
|
62 | + throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE)); |
|
63 | + } |
|
64 | + |
|
65 | + if (isset($options["phpqrcode.path"])) { |
|
66 | + $qrcode_dir = $options["phpqrcode.path"]; |
|
67 | + $qrcode_path = realpath($qrcode_dir); |
|
68 | + } else { |
|
69 | + $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode'; |
|
70 | + $qrcode_path = $qrcode_dir; |
|
71 | + } |
|
72 | + |
|
73 | + if (is_dir($qrcode_path)) { |
|
74 | + $this->qrcodePath = $qrcode_path; |
|
75 | + } else { |
|
76 | + throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE)); |
|
77 | + } |
|
78 | + |
|
79 | + if (isset($options["zend.path"])) { |
|
80 | + $zend_dir = $options["zend.path"]; |
|
81 | + $zend_path = realpath($zend_dir); |
|
82 | + } else { |
|
83 | + $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend"; |
|
84 | + $zend_path = $zend_dir; |
|
85 | + } |
|
86 | + if (is_dir($zend_path)) { |
|
87 | + $this->zendPath = $zend_path; |
|
88 | + } else { |
|
89 | + throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE)); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + public function setIncludePath() { |
|
95 | + set_include_path(implode(PATH_SEPARATOR, array( |
|
96 | + $this->tiqrPath, |
|
97 | + $this->zendPath, |
|
98 | + $this->qrcodePath, |
|
99 | + get_include_path(), |
|
100 | + ))); |
|
101 | + } |
|
102 | 102 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function autoload($className) { |
26 | - if($className === NULL) { |
|
26 | + if ($className === NULL) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | $substr5 = substr($className, 0, 5); |
33 | 33 | |
34 | 34 | if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') { |
35 | - $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
35 | + $file = $self->tiqrPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; |
|
36 | 36 | } elseif ($className === 'QRcode') { |
37 | - $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php'; |
|
37 | + $file = $self->qrcodePath.DIRECTORY_SEPARATOR.'qrlib.php'; |
|
38 | 38 | } elseif ($substr5 === 'Zend_') { |
39 | - $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
39 | + $file = $self->zendPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; |
|
40 | 40 | } elseif ($className === 'ReadWriteException') { |
41 | - $file = $self->tiqrPath . DIRECTORY_SEPARATOR . 'Tiqr/Exception/ReadWriteException.php'; |
|
41 | + $file = $self->tiqrPath.DIRECTORY_SEPARATOR.'Tiqr/Exception/ReadWriteException.php'; |
|
42 | 42 | } else { |
43 | 43 | return; |
44 | 44 | } |
@@ -59,34 +59,34 @@ discard block |
||
59 | 59 | if (is_dir($tiqr_path)) { |
60 | 60 | $this->tiqrPath = $tiqr_path; |
61 | 61 | } else { |
62 | - throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE)); |
|
62 | + throw new Exception('Directory not found: '.var_export($tiqr_dir, TRUE)); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | if (isset($options["phpqrcode.path"])) { |
66 | 66 | $qrcode_dir = $options["phpqrcode.path"]; |
67 | 67 | $qrcode_path = realpath($qrcode_dir); |
68 | 68 | } else { |
69 | - $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode'; |
|
69 | + $qrcode_dir = dirname(dirname(dirname(__FILE__))).'/phpqrcode'; |
|
70 | 70 | $qrcode_path = $qrcode_dir; |
71 | 71 | } |
72 | 72 | |
73 | 73 | if (is_dir($qrcode_path)) { |
74 | 74 | $this->qrcodePath = $qrcode_path; |
75 | 75 | } else { |
76 | - throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE)); |
|
76 | + throw new Exception('Directory not found: '.var_export($qrcode_dir, TRUE)); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | if (isset($options["zend.path"])) { |
80 | 80 | $zend_dir = $options["zend.path"]; |
81 | 81 | $zend_path = realpath($zend_dir); |
82 | 82 | } else { |
83 | - $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend"; |
|
83 | + $zend_dir = dirname(dirname(dirname(__FILE__)))."/zend"; |
|
84 | 84 | $zend_path = $zend_dir; |
85 | 85 | } |
86 | 86 | if (is_dir($zend_path)) { |
87 | 87 | $this->zendPath = $zend_path; |
88 | 88 | } else { |
89 | - throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE)); |
|
89 | + throw new Exception('Directory not found: '.var_export($zend_dir, TRUE)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 |