Passed
Push — 1.0.0-dev ( 9c9ab7...066288 )
by nguereza
02:38
created
core/libraries/StringHash.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class StringHash{
27
+	class StringHash {
28 28
 		 
29 29
 		 //blowfish
30 30
 		private static $algo = '$2a';
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@
 block discarded – undo
1 1
 <?php 
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class StringHash{
27
+    class StringHash{
28 28
 		 
29
-		 //blowfish
30
-		private static $algo = '$2a';
29
+            //blowfish
30
+        private static $algo = '$2a';
31 31
 		
32
-		//cost parameter
33
-		private static $cost = '$10';
32
+        //cost parameter
33
+        private static $cost = '$10';
34 34
 
35
-		/**
36
-		 * Get the unique salt for the string hash
37
-		 * @return string the unique generated salt
38
-		 */
39
-		private static function uniqueSalt() {
40
-			return substr(sha1(mt_rand()), 0, 22);
41
-		}
35
+        /**
36
+         * Get the unique salt for the string hash
37
+         * @return string the unique generated salt
38
+         */
39
+        private static function uniqueSalt() {
40
+            return substr(sha1(mt_rand()), 0, 22);
41
+        }
42 42
 
43
-		/**
44
-		 * Hash the given string
45
-		 * @param  string $value the plain string text to be hashed
46
-		 * @return string           the hashed string
47
-		 */
48
-		public static function hash($value) {
49
-			return crypt($value, self::$algo .
50
-					self::$cost .
51
-					'$' . self::uniqueSalt());
52
-		}
43
+        /**
44
+         * Hash the given string
45
+         * @param  string $value the plain string text to be hashed
46
+         * @return string           the hashed string
47
+         */
48
+        public static function hash($value) {
49
+            return crypt($value, self::$algo .
50
+                    self::$cost .
51
+                    '$' . self::uniqueSalt());
52
+        }
53 53
 
54
-		/**
55
-		 * Check if the hash and plain string is valid
56
-		 * @param  string $hash     the hashed string
57
-		 * @param  string $plain the plain text
58
-		 * @return boolean  true if is valid or false if not
59
-		 */
60
-		public static function check($hash, $plain) {
61
-			$full_salt = substr($hash, 0, 29);
62
-			$new_hash = crypt($plain, $full_salt);
63
-			return ($hash === $new_hash);
64
-		}	
65
-	}
66 54
\ No newline at end of file
55
+        /**
56
+         * Check if the hash and plain string is valid
57
+         * @param  string $hash     the hashed string
58
+         * @param  string $plain the plain text
59
+         * @return boolean  true if is valid or false if not
60
+         */
61
+        public static function check($hash, $plain) {
62
+            $full_salt = substr($hash, 0, 29);
63
+            $new_hash = crypt($plain, $full_salt);
64
+            return ($hash === $new_hash);
65
+        }	
66
+    }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/Browser.php 3 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -921,20 +921,15 @@
 block discarded – undo
921 921
                     if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){
922 922
                         if($aresult[1] == '3.1'){
923 923
                             $this->setVersion('7.0');
924
-                        }
925
-                        else if($aresult[1] == '4.0'){
924
+                        } else if($aresult[1] == '4.0'){
926 925
                             $this->setVersion('8.0');
927
-                        }
928
-                        else if($aresult[1] == '5.0'){
926
+                        } else if($aresult[1] == '5.0'){
929 927
                             $this->setVersion('9.0');
930
-                        }
931
-                        else if($aresult[1] == '6.0'){
928
+                        } else if($aresult[1] == '6.0'){
932 929
                             $this->setVersion('10.0');
933
-                        }
934
-                        else if($aresult[1] == '7.0'){
930
+                        } else if($aresult[1] == '7.0'){
935 931
                             $this->setVersion('11.0');
936
-                        }
937
-                        else if($aresult[1] == '8.0'){
932
+                        } else if($aresult[1] == '8.0'){
938 933
                             $this->setVersion('11.0');
939 934
                         }
940 935
                     }
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1669,34 +1669,34 @@
 block discarded – undo
1669 1669
         protected function checkPlatform()
1670 1670
         {
1671 1671
             $platformMaps = array(
1672
-              'windows' => self::PLATFORM_WINDOWS,
1673
-              'iPad' => self::PLATFORM_IPAD,
1674
-              'iPod' => self::PLATFORM_IPOD,
1675
-              'iPhone' => self::PLATFORM_IPHONE,
1676
-              'mac' => self::PLATFORM_APPLE,
1677
-              'android' => self::PLATFORM_ANDROID,
1678
-              'Silk' => self::PLATFORM_FIRE_OS,
1679
-              'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV,
1680
-              'linux' => self::PLATFORM_LINUX,
1681
-              'Nokia' => self::PLATFORM_NOKIA,
1682
-              'BlackBerry' => self::PLATFORM_BLACKBERRY,
1683
-              'FreeBSD' => self::PLATFORM_FREEBSD,
1684
-              'OpenBSD' => self::PLATFORM_OPENBSD,
1685
-              'NetBSD' => self::PLATFORM_NETBSD,
1686
-              'OpenSolaris' => self::PLATFORM_OPENSOLARIS,
1687
-              'SunOS' => self::PLATFORM_SUNOS,
1688
-              'OS\/2' => self::PLATFORM_OS2,
1689
-              'BeOS' => self::PLATFORM_BEOS,
1690
-              'win' => self::PLATFORM_WINDOWS,
1691
-              'Playstation' => self::PLATFORM_PLAYSTATION,
1692
-              'Roku' => self::PLATFORM_ROKU,
1693
-              'iOS' => self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD,
1694
-              'tvOS' => self::PLATFORM_APPLE_TV,
1695
-              'curl' => self::PLATFORM_TERMINAL,
1696
-              'CrOS' => self::PLATFORM_CHROME_OS,
1697
-              'okhttp' => self::PLATFORM_JAVA_ANDROID,
1698
-              'PostmanRuntime' => self::PLATFORM_POSTMAN,
1699
-              'Iframely' => self::PLATFORM_I_FRAME
1672
+                'windows' => self::PLATFORM_WINDOWS,
1673
+                'iPad' => self::PLATFORM_IPAD,
1674
+                'iPod' => self::PLATFORM_IPOD,
1675
+                'iPhone' => self::PLATFORM_IPHONE,
1676
+                'mac' => self::PLATFORM_APPLE,
1677
+                'android' => self::PLATFORM_ANDROID,
1678
+                'Silk' => self::PLATFORM_FIRE_OS,
1679
+                'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV,
1680
+                'linux' => self::PLATFORM_LINUX,
1681
+                'Nokia' => self::PLATFORM_NOKIA,
1682
+                'BlackBerry' => self::PLATFORM_BLACKBERRY,
1683
+                'FreeBSD' => self::PLATFORM_FREEBSD,
1684
+                'OpenBSD' => self::PLATFORM_OPENBSD,
1685
+                'NetBSD' => self::PLATFORM_NETBSD,
1686
+                'OpenSolaris' => self::PLATFORM_OPENSOLARIS,
1687
+                'SunOS' => self::PLATFORM_SUNOS,
1688
+                'OS\/2' => self::PLATFORM_OS2,
1689
+                'BeOS' => self::PLATFORM_BEOS,
1690
+                'win' => self::PLATFORM_WINDOWS,
1691
+                'Playstation' => self::PLATFORM_PLAYSTATION,
1692
+                'Roku' => self::PLATFORM_ROKU,
1693
+                'iOS' => self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD,
1694
+                'tvOS' => self::PLATFORM_APPLE_TV,
1695
+                'curl' => self::PLATFORM_TERMINAL,
1696
+                'CrOS' => self::PLATFORM_CHROME_OS,
1697
+                'okhttp' => self::PLATFORM_JAVA_ANDROID,
1698
+                'PostmanRuntime' => self::PLATFORM_POSTMAN,
1699
+                'Iframely' => self::PLATFORM_I_FRAME
1700 1700
             );
1701 1701
 
1702 1702
             foreach ($platformMaps as $name => $value) {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -916,27 +916,27 @@  discard block
 block discarded – undo
916 916
                 if (isset($aresult[1])) {
917 917
                     $this->setBrowser(self::BROWSER_IE);
918 918
                     $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
919
-                    if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){
920
-                        if($aresult[1] == '3.1'){
919
+                    if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) {
920
+                        if ($aresult[1] == '3.1') {
921 921
                             $this->setVersion('7.0');
922 922
                         }
923
-                        else if($aresult[1] == '4.0'){
923
+                        else if ($aresult[1] == '4.0') {
924 924
                             $this->setVersion('8.0');
925 925
                         }
926
-                        else if($aresult[1] == '5.0'){
926
+                        else if ($aresult[1] == '5.0') {
927 927
                             $this->setVersion('9.0');
928 928
                         }
929
-                        else if($aresult[1] == '6.0'){
929
+                        else if ($aresult[1] == '6.0') {
930 930
                             $this->setVersion('10.0');
931 931
                         }
932
-                        else if($aresult[1] == '7.0'){
932
+                        else if ($aresult[1] == '7.0') {
933 933
                             $this->setVersion('11.0');
934 934
                         }
935
-                        else if($aresult[1] == '8.0'){
935
+                        else if ($aresult[1] == '8.0') {
936 936
                             $this->setVersion('11.0');
937 937
                         }
938 938
                     }
939
-                    if(stripos($this->_agent, 'IEMobile') !== false) {
939
+                    if (stripos($this->_agent, 'IEMobile') !== false) {
940 940
                         $this->setBrowser(self::BROWSER_POCKET_IE);
941 941
                         $this->setMobile(true);
942 942
                     }
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
               'mac' => self::PLATFORM_APPLE,
1677 1677
               'android' => self::PLATFORM_ANDROID,
1678 1678
               'Silk' => self::PLATFORM_FIRE_OS,
1679
-              'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV,
1679
+              'linux_smarttv' => self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV,
1680 1680
               'linux' => self::PLATFORM_LINUX,
1681 1681
               'Nokia' => self::PLATFORM_NOKIA,
1682 1682
               'BlackBerry' => self::PLATFORM_BLACKBERRY,
@@ -1700,9 +1700,9 @@  discard block
 block discarded – undo
1700 1700
             );
1701 1701
 
1702 1702
             foreach ($platformMaps as $name => $value) {
1703
-                if($name == 'linux_smarttv' 
1703
+                if ($name == 'linux_smarttv' 
1704 1704
                     && stripos($this->_agent, 'linux') !== false 
1705
-                    && stripos($this->_agent, 'SMART-TV') !== false ){
1705
+                    && stripos($this->_agent, 'SMART-TV') !== false) {
1706 1706
                         $this->_platform = $value;
1707 1707
                         break;
1708 1708
                 } elseif (stripos($this->_agent, $name) !== false) {
Please login to merge, or discard this patch.
core/functions/function_lang.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	if(! function_exists('__')){
27
+	if (!function_exists('__')) {
28 28
 		/**
29 29
 		 * function for the shortcut to Lang::get()
30 30
 		 * @param  string $key the language key to retrieve
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
 		 * for the given key
33 33
 		 * @return string  the language value
34 34
 		 */
35
-		function __($key, $default = 'LANGUAGE_ERROR'){
35
+		function __($key, $default = 'LANGUAGE_ERROR') {
36 36
 			return get_instance()->lang->get($key, $default);
37 37
 		}
38 38
 
39 39
 	}
40 40
 
41 41
 
42
-	if(! function_exists('get_languages')){
42
+	if (!function_exists('get_languages')) {
43 43
 		/**
44 44
 		 * function for the shortcut to Lang::getSupported()
45 45
 		 * 
46 46
 		 * @return array all the supported languages
47 47
 		 */
48
-		function get_languages(){
48
+		function get_languages() {
49 49
 			return get_instance()->lang->getSupported();
50 50
 		}
51 51
 
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -1,52 +1,52 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	if(! function_exists('__')){
28
-		/**
29
-		 * function for the shortcut to Lang::get()
30
-		 * @param  string $key the language key to retrieve
31
-		 * @param mixed $default the default value to return if can not find the value
32
-		 * for the given key
33
-		 * @return string  the language value
34
-		 */
35
-		function __($key, $default = 'LANGUAGE_ERROR'){
36
-			return get_instance()->lang->get($key, $default);
37
-		}
27
+    if(! function_exists('__')){
28
+        /**
29
+         * function for the shortcut to Lang::get()
30
+         * @param  string $key the language key to retrieve
31
+         * @param mixed $default the default value to return if can not find the value
32
+         * for the given key
33
+         * @return string  the language value
34
+         */
35
+        function __($key, $default = 'LANGUAGE_ERROR'){
36
+            return get_instance()->lang->get($key, $default);
37
+        }
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 
42
-	if(! function_exists('get_languages')){
43
-		/**
44
-		 * function for the shortcut to Lang::getSupported()
45
-		 * 
46
-		 * @return array all the supported languages
47
-		 */
48
-		function get_languages(){
49
-			return get_instance()->lang->getSupported();
50
-		}
42
+    if(! function_exists('get_languages')){
43
+        /**
44
+         * function for the shortcut to Lang::getSupported()
45
+         * 
46
+         * @return array all the supported languages
47
+         */
48
+        function get_languages(){
49
+            return get_instance()->lang->getSupported();
50
+        }
51 51
 
52
-	}
53 52
\ No newline at end of file
53
+    }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.
core/views/errors.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
     <meta name="viewport" content="width=device-width, initial-scale=1">
7 7
     <meta name="description" content="">
8 8
     <meta name="author" content="Tony NGUEREZA">
9
-    <title><?php echo $title;?></title>
9
+    <title><?php echo $title; ?></title>
10 10
 	<style type = 'text/css'>
11 11
 	/* reset */
12 12
 		*{
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
   <body>
65 65
 	<div class="container">
66 66
 		<div class = "title">
67
-			<h2><?php echo $title;?></h2>
67
+			<h2><?php echo $title; ?></h2>
68 68
 		</div>
69 69
 		<div class = "body">
70
-			<p><?php echo $error;?></p>
70
+			<p><?php echo $error; ?></p>
71 71
 		</div>
72 72
 	</div> <!-- ./container-->
73 73
    </body>
Please login to merge, or discard this patch.
core/lang/en/lang_form_validation.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -3,11 +3,11 @@  discard block
 block discarded – undo
3 3
  	/**
4 4
  	 * Form validation language message (English) 
5 5
  	 */
6
- 	$lang['fv_required']     		= 'Field %1 is required.';
6
+ 	$lang['fv_required'] = 'Field %1 is required.';
7 7
     $lang['fv_min_length']   		= 'Field %1 must contain at least %2 characters.';
8 8
     $lang['fv_max_length']   		= 'Field %1 must contain at most %2 characters.';
9 9
     $lang['fv_exact_length'] 		= 'Field %1 must contain exactly %2 characters.';
10
-    $lang['fv_less_than'] 		    = 'Field %1 must less than %2.';
10
+    $lang['fv_less_than'] = 'Field %1 must less than %2.';
11 11
     $lang['fv_greater_than'] 		= 'Field %1 must greater than %2.';
12 12
     $lang['fv_matches']      		= 'Field %1 must be identical to field %2.';
13 13
     $lang['fv_valid_email']  		= 'Field %1 must contain a valid E-mail address.';
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     $lang['fv_depends']      		= 'Field %1 depends on field %2 which is not valid.';
17 17
 	$lang['fv_is_unique']	   		= 'The value of field %1 already exists.';
18 18
 	$lang['fv_is_unique_update']	= 'The value of field %1 already exists for another record.';
19
-    $lang['fv_exists']	   			= 'The value of the field %1 does not exist.';
19
+    $lang['fv_exists'] = 'The value of the field %1 does not exist.';
20 20
     $lang['fv_regex']	   			= 'The value of the field %1 does not use the correct format.';
21 21
     $lang['fv_in_list']	   			= 'The value of field %1 must be one of the list (%2).';
22 22
     $lang['fv_numeric']	   			= 'The value of field %1 must be a number.';
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php 
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
- 	/**
4
- 	 * Form validation language message (English) 
5
- 	 */
6
- 	$lang['fv_required']     		= 'Field %1 is required.';
3
+        /**
4
+         * Form validation language message (English) 
5
+         */
6
+        $lang['fv_required']     		= 'Field %1 is required.';
7 7
     $lang['fv_min_length']   		= 'Field %1 must contain at least %2 characters.';
8 8
     $lang['fv_max_length']   		= 'Field %1 must contain at most %2 characters.';
9 9
     $lang['fv_exact_length'] 		= 'Field %1 must contain exactly %2 characters.';
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
     $lang['fv_not_equal_post_key']  = 'Field %1 must not be the same as field %2.';
15 15
     $lang['fv_not_equal_string']    = 'Field %1 must not contain the value %2.';
16 16
     $lang['fv_depends']      		= 'Field %1 depends on field %2 which is not valid.';
17
-	$lang['fv_is_unique']	   		= 'The value of field %1 already exists.';
18
-	$lang['fv_is_unique_update']	= 'The value of field %1 already exists for another record.';
17
+    $lang['fv_is_unique']	   		= 'The value of field %1 already exists.';
18
+    $lang['fv_is_unique_update']	= 'The value of field %1 already exists for another record.';
19 19
     $lang['fv_exists']	   			= 'The value of the field %1 does not exist.';
20 20
     $lang['fv_regex']	   			= 'The value of the field %1 does not use the correct format.';
21 21
     $lang['fv_in_list']	   			= 'The value of field %1 must be one of the list (%2).';
Please login to merge, or discard this patch.
core/lang/en/lang_file_upload.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@
 block discarded – undo
6 6
  	$lang['fu_upload_err_ini_size']     = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
7 7
     $lang['fu_upload_err_form_size']   	= 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
8 8
     $lang['fu_upload_err_partial']   	= 'The uploaded file was only partially uploaded.';
9
-    $lang['fu_upload_err_no_file'] 		= 'No file was choosed. Please select one.';
9
+    $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.';
10 10
     $lang['fu_upload_err_no_tmp_dir']   = 'Missing a temporary folder.';
11
-    $lang['fu_upload_err_cant_write'] 	= 'Failed to write file to disk.';
11
+    $lang['fu_upload_err_cant_write'] = 'Failed to write file to disk.';
12 12
     $lang['fu_upload_err_extension']    = 'A PHP extension stopped the file upload.';
13
-    $lang['fu_accept_file_types']  		= 'Filetype not allowed';
13
+    $lang['fu_accept_file_types'] = 'Filetype not allowed';
14 14
     $lang['fu_file_uploads_disabled']   = 'File uploading option is disabled in php.ini';
15 15
     $lang['fu_max_file_size']           = 'The uploaded file size is too big max size is %s';
16 16
     $lang['fu_overwritten_not_allowed'] = 'You don\'t allow overwriting existing file';
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php 
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
- 	/**
4
- 	 * File upload language messages (English) 
5
- 	 */
6
- 	$lang['fu_upload_err_ini_size']     = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
3
+        /**
4
+         * File upload language messages (English) 
5
+         */
6
+        $lang['fu_upload_err_ini_size']     = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
7 7
     $lang['fu_upload_err_form_size']   	= 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
8 8
     $lang['fu_upload_err_partial']   	= 'The uploaded file was only partially uploaded.';
9 9
     $lang['fu_upload_err_no_file'] 		= 'No file was choosed. Please select one.';
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 3 patches
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
 	         */
88 88
 	        if(is_object($logger)){
89 89
 	          $this->setLogger($logger);
90
-	        }
91
-	        else{
90
+	        } else{
92 91
 	            $this->logger =& class_loader('Log', 'classes');
93 92
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 93
 	        }
@@ -197,8 +196,7 @@  discard block
 block discarded – undo
197 196
 			if($this->getLoader()){
198 197
 				$this->getLoader()->functions('user_agent'); 
199 198
 				$this->getLoader()->library('Browser'); 
200
-			}
201
-			else{
199
+			} else{
202 200
             	Loader::functions('user_agent');
203 201
             	Loader::library('Browser');
204 202
             }
@@ -237,8 +235,7 @@  discard block
 block discarded – undo
237 235
 			if($this->getLoader()){
238 236
 				$this->getLoader()->functions('user_agent'); 
239 237
 				$this->getLoader()->library('Browser'); 
240
-			}
241
-			else{
238
+			} else{
242 239
             	Loader::functions('user_agent');
243 240
             	Loader::library('Browser');
244 241
             }
@@ -264,8 +261,7 @@  discard block
 block discarded – undo
264 261
 				//update
265 262
 				unset($params[$columns['sid']]);
266 263
 				$instance->update($sid, $params);
267
-			}
268
-			else{
264
+			} else{
269 265
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 266
 				$instance->insert($params);
271 267
 			}
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
84
+		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) {
85 85
 			/**
86 86
 	         * instance of the Log class
87 87
 	         */
88
-	        if(is_object($logger)){
88
+	        if (is_object($logger)) {
89 89
 	          $this->setLogger($logger);
90 90
 	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
91
+	        else {
92
+	            $this->logger = & class_loader('Log', 'classes');
93 93
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 94
 	        }
95 95
 
96
-	        if(is_object($loader)){
96
+	        if (is_object($loader)) {
97 97
 	          $this->setLoader($loader);
98 98
 	        }
99 99
 		    $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
102
+			if (is_object($modelInstance)) {
103 103
 				$this->setModelInstance($modelInstance);
104 104
 			}
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		 * Set the session secret used to encrypt the data in database 
109 109
 		 * @param string $secret the base64 string secret
110 110
 		 */
111
-		public function setSessionSecret($secret){
111
+		public function setSessionSecret($secret) {
112 112
 			$this->sessionSecret = $secret;
113 113
 			return $this;
114 114
 		}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Return the session secret
118 118
 		 * @return string 
119 119
 		 */
120
-		public function getSessionSecret(){
120
+		public function getSessionSecret() {
121 121
 			return $this->sessionSecret;
122 122
 		}
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * Set the initializer vector for openssl 
127 127
 		 * @param string $key the session secret used
128 128
 		 */
129
-		public function setInitializerVector($key){
129
+		public function setInitializerVector($key) {
130 130
 			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131 131
 			$key = base64_decode($key);
132 132
 			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * Return the initializer vector
138 138
 		 * @return string 
139 139
 		 */
140
-		public function getInitializerVector(){
140
+		public function getInitializerVector() {
141 141
 			return $this->iv;
142 142
 		}
143 143
 
@@ -147,17 +147,17 @@  discard block
 block discarded – undo
147 147
 		 * @param  string $sessionName the session name
148 148
 		 * @return boolean 
149 149
 		 */
150
-		public function open($savePath, $sessionName){
150
+		public function open($savePath, $sessionName) {
151 151
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152 152
 			//try to check if session secret is set before
153 153
 			$secret = $this->getSessionSecret();
154
-			if(empty($secret)){
154
+			if (empty($secret)) {
155 155
 				$secret = get_config('session_secret', null);
156 156
 				$this->setSessionSecret($secret);
157 157
 			}
158 158
 			$this->logger->info('Session secret: ' . $secret);
159 159
 
160
-			if(! $this->getModelInstance()){
160
+			if (!$this->getModelInstance()) {
161 161
 				$this->setModelInstanceFromConfig();
162 162
 			}
163 163
 			$this->setInitializerVector($secret);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 			//set session tables columns
166 166
 			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167 167
 
168
-			if(empty($this->sessionTableColumns)){
168
+			if (empty($this->sessionTableColumns)) {
169 169
 				show_error('The session handler is "database" but the table columns not set');
170 170
 			}
171 171
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 * Close the session
182 182
 		 * @return boolean
183 183
 		 */
184
-		public function close(){
184
+		public function close() {
185 185
 			$this->logger->debug('Closing database session handler');
186 186
 			return true;
187 187
 		}
@@ -191,28 +191,28 @@  discard block
 block discarded – undo
191 191
 		 * @param  string $sid the session id to use
192 192
 		 * @return string      the session data in serialiaze format
193 193
 		 */
194
-		public function read($sid){
194
+		public function read($sid) {
195 195
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
196 196
 			$instance = $this->getModelInstance();
197 197
 			$columns = $this->sessionTableColumns;
198
-			if($this->getLoader()){
198
+			if ($this->getLoader()) {
199 199
 				$this->getLoader()->functions('user_agent'); 
200 200
 				$this->getLoader()->library('Browser'); 
201 201
 			}
202
-			else{
202
+			else {
203 203
             	Loader::functions('user_agent');
204 204
             	Loader::library('Browser');
205 205
             }
206 206
 			
207 207
 			$ip = get_ip();
208 208
 			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
209
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
210 210
 			
211 211
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
212
+			if ($data && isset($data->{$columns['sdata']})) {
213 213
 				//checking inactivity 
214 214
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
215
+				if ($data->{$columns['stime']} < $timeInactivity) {
216 216
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217 217
 					$this->destroy($sid);
218 218
 					return null;
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 		 * @param  mixed $data the session data to save in serialize format
230 230
 		 * @return boolean 
231 231
 		 */
232
-		public function write($sid, $data){
232
+		public function write($sid, $data) {
233 233
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234 234
 			$instance = $this->getModelInstance();
235 235
 			$columns = $this->sessionTableColumns;
236 236
 
237
-			if($this->getLoader()){
237
+			if ($this->getLoader()) {
238 238
 				$this->getLoader()->functions('user_agent'); 
239 239
 				$this->getLoader()->library('Browser'); 
240 240
 			}
241
-			else{
241
+			else {
242 242
             	Loader::functions('user_agent');
243 243
             	Loader::library('Browser');
244 244
             }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			$ip = get_ip();
247 247
 			$keyValue = $instance->getKeyValue();
248 248
 			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
249
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
250 250
 			$data = $this->encode($data);
251 251
 			$params = array(
252 252
 							$columns['sid'] => $sid,
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 						);
260 260
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261 261
 			$exists = $instance->get($sid);
262
-			if($exists){
262
+			if ($exists) {
263 263
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264 264
 				//update
265 265
 				unset($params[$columns['sid']]);
266 266
 				$instance->update($sid, $params);
267 267
 			}
268
-			else{
268
+			else {
269 269
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 270
 				$instance->insert($params);
271 271
 			}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		 * @param  string $sid the session id value
279 279
 		 * @return boolean
280 280
 		 */
281
-		public function destroy($sid){
281
+		public function destroy($sid) {
282 282
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283 283
 			$instance = $this->modelInstanceName;
284 284
 			$instance->delete($sid);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		 * @param  integer $maxLifetime the max lifetime
291 291
 		 * @return boolean
292 292
 		 */
293
-		public function gc($maxLifetime){
293
+		public function gc($maxLifetime) {
294 294
 			$instance = $this->modelInstanceName;
295 295
 			$time = time() - $maxLifetime;
296 296
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 		 * @param  mixed $data the session data to encode
304 304
 		 * @return mixed the encoded session data
305 305
 		 */
306
-		public function encode($data){
306
+		public function encode($data) {
307 307
 			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
308
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309 309
 			$output = base64_encode($dataEncrypted);
310 310
 			return $output;
311 311
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		 * @param  mixed $data the data to decode
317 317
 		 * @return mixed       the decoded data
318 318
 		 */
319
-		public function decode($data){
319
+		public function decode($data) {
320 320
 			$key = base64_decode($this->sessionSecret);
321 321
 			$data = base64_decode($data);
322 322
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
          * Return the loader instance
329 329
          * @return object Loader the loader instance
330 330
          */
331
-        public function getLoader(){
331
+        public function getLoader() {
332 332
             return $this->loader;
333 333
         }
334 334
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param object Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+         public function setLoader($loader) {
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
          * Return the model instance
346 346
          * @return object DBSessionHandlerModel the model instance
347 347
          */
348
-        public function getModelInstance(){
348
+        public function getModelInstance() {
349 349
             return $this->modelInstanceName;
350 350
         }
351 351
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	     * Return the Log instance
363 363
 	     * @return Log
364 364
 	     */
365
-	    public function getLogger(){
365
+	    public function getLogger() {
366 366
 	      return $this->logger;
367 367
 	    }
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	     * Set the log instance
371 371
 	     * @param Log $logger the log object
372 372
 	     */
373
-	    public function setLogger(Log $logger){
373
+	    public function setLogger(Log $logger) {
374 374
 	      $this->logger = $logger;
375 375
 	      return $this;
376 376
 	    }
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
 	    /**
379 379
 	     * Set the model instance using the configuration for session
380 380
 	     */
381
-	    private function setModelInstanceFromConfig(){
381
+	    private function setModelInstanceFromConfig() {
382 382
 	    	$modelName = get_config('session_save_path');
383 383
 			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
384
+			if ($this->getLoader()) {
385 385
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386 386
 			}
387 387
 			//@codeCoverageIgnoreStart
388
-			else{
388
+			else {
389 389
             	Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
391
+            if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) {
392
+				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
393 393
 			}  
394 394
 			//@codeCoverageIgnoreEnd
395 395
 			
Please login to merge, or discard this patch.
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -1,330 +1,330 @@  discard block
 block discarded – undo
1 1
 <?php 
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	/**
28
-	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
-	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
31
-		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
-	}
33
-
34
-	class DBSessionHandler implements SessionHandlerInterface{
27
+    /**
28
+     * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
+     */
30
+    if( !interface_exists('SessionHandlerInterface')){
31
+        show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
+    }
33
+
34
+    class DBSessionHandler implements SessionHandlerInterface{
35 35
 		
36
-		/**
37
-		 * The encryption method to use to encrypt session data in database
38
-		 * @const string
39
-		 */
40
-		const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
36
+        /**
37
+         * The encryption method to use to encrypt session data in database
38
+         * @const string
39
+         */
40
+        const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
41 41
 		
42
-		/**
43
-		 * Super global instance
44
-		 * @var object
45
-		 */
46
-		protected $OBJ = null;
47
-
48
-		/**
49
-		 * Session secret to use 
50
-		 * @var string
51
-		 */
52
-		private $sessionSecret = null;
53
-
54
-		/**
55
-		 * The initialisation vector to use for openssl
56
-		 * @var string
57
-		 */
58
-		private $iv = null;
59
-
60
-		/**
61
-		 * The model instance name to use after load model
62
-		 * @var object
63
-		 */
64
-		private $modelInstanceName = null;
65
-
66
-		/**
67
-		 * The columns of the table to use to store session data
68
-		 * @var array
69
-		 */
70
-		private $sessionTableColumns = array();
71
-
72
-		/**
73
-		 * The instance of the Log 
74
-		 * @var Log
75
-		 */
76
-		private $logger;
77
-
78
-		/**
42
+        /**
43
+         * Super global instance
44
+         * @var object
45
+         */
46
+        protected $OBJ = null;
47
+
48
+        /**
49
+         * Session secret to use 
50
+         * @var string
51
+         */
52
+        private $sessionSecret = null;
53
+
54
+        /**
55
+         * The initialisation vector to use for openssl
56
+         * @var string
57
+         */
58
+        private $iv = null;
59
+
60
+        /**
61
+         * The model instance name to use after load model
62
+         * @var object
63
+         */
64
+        private $modelInstanceName = null;
65
+
66
+        /**
67
+         * The columns of the table to use to store session data
68
+         * @var array
69
+         */
70
+        private $sessionTableColumns = array();
71
+
72
+        /**
73
+         * The instance of the Log 
74
+         * @var Log
75
+         */
76
+        private $logger;
77
+
78
+        /**
79 79
          * Instance of the Loader class
80 80
          * @var Loader
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
85
-			/**
86
-	         * instance of the Log class
87
-	         */
88
-	        if(is_object($logger)){
89
-	          $this->setLogger($logger);
90
-	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
93
-	            $this->logger->setLogger('Library::DBSessionHandler');
94
-	        }
95
-
96
-	        if(is_object($loader)){
97
-	          $this->setLoader($loader);
98
-	        }
99
-		    $this->OBJ = & get_instance();
84
+        public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
85
+            /**
86
+             * instance of the Log class
87
+             */
88
+            if(is_object($logger)){
89
+                $this->setLogger($logger);
90
+            }
91
+            else{
92
+                $this->logger =& class_loader('Log', 'classes');
93
+                $this->logger->setLogger('Library::DBSessionHandler');
94
+            }
95
+
96
+            if(is_object($loader)){
97
+                $this->setLoader($loader);
98
+            }
99
+            $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
103
-				$this->setModelInstance($modelInstance);
104
-			}
105
-		}
106
-
107
-		/**
108
-		 * Set the session secret used to encrypt the data in database 
109
-		 * @param string $secret the base64 string secret
110
-		 */
111
-		public function setSessionSecret($secret){
112
-			$this->sessionSecret = $secret;
113
-			return $this;
114
-		}
115
-
116
-		/**
117
-		 * Return the session secret
118
-		 * @return string 
119
-		 */
120
-		public function getSessionSecret(){
121
-			return $this->sessionSecret;
122
-		}
123
-
124
-
125
-		/**
126
-		 * Set the initializer vector for openssl 
127
-		 * @param string $key the session secret used
128
-		 */
129
-		public function setInitializerVector($key){
130
-			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131
-			$key = base64_decode($key);
132
-			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
133
-			return $this;
134
-		}
135
-
136
-		/**
137
-		 * Return the initializer vector
138
-		 * @return string 
139
-		 */
140
-		public function getInitializerVector(){
141
-			return $this->iv;
142
-		}
143
-
144
-		/**
145
-		 * Open the database session handler, here nothing to do just return true
146
-		 * @param  string $savePath    the session save path
147
-		 * @param  string $sessionName the session name
148
-		 * @return boolean 
149
-		 */
150
-		public function open($savePath, $sessionName){
151
-			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152
-			//try to check if session secret is set before
153
-			$secret = $this->getSessionSecret();
154
-			if(empty($secret)){
155
-				$secret = get_config('session_secret', null);
156
-				$this->setSessionSecret($secret);
157
-			}
158
-			$this->logger->info('Session secret: ' . $secret);
159
-
160
-			if(! $this->getModelInstance()){
161
-				$this->setModelInstanceFromConfig();
162
-			}
163
-			$this->setInitializerVector($secret);
164
-
165
-			//set session tables columns
166
-			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167
-
168
-			if(empty($this->sessionTableColumns)){
169
-				show_error('The session handler is "database" but the table columns not set');
170
-			}
171
-			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
102
+            if(is_object($modelInstance)){
103
+                $this->setModelInstance($modelInstance);
104
+            }
105
+        }
106
+
107
+        /**
108
+         * Set the session secret used to encrypt the data in database 
109
+         * @param string $secret the base64 string secret
110
+         */
111
+        public function setSessionSecret($secret){
112
+            $this->sessionSecret = $secret;
113
+            return $this;
114
+        }
115
+
116
+        /**
117
+         * Return the session secret
118
+         * @return string 
119
+         */
120
+        public function getSessionSecret(){
121
+            return $this->sessionSecret;
122
+        }
123
+
124
+
125
+        /**
126
+         * Set the initializer vector for openssl 
127
+         * @param string $key the session secret used
128
+         */
129
+        public function setInitializerVector($key){
130
+            $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131
+            $key = base64_decode($key);
132
+            $this->iv = substr(hash('sha256', $key), 0, $iv_length);
133
+            return $this;
134
+        }
135
+
136
+        /**
137
+         * Return the initializer vector
138
+         * @return string 
139
+         */
140
+        public function getInitializerVector(){
141
+            return $this->iv;
142
+        }
143
+
144
+        /**
145
+         * Open the database session handler, here nothing to do just return true
146
+         * @param  string $savePath    the session save path
147
+         * @param  string $sessionName the session name
148
+         * @return boolean 
149
+         */
150
+        public function open($savePath, $sessionName){
151
+            $this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152
+            //try to check if session secret is set before
153
+            $secret = $this->getSessionSecret();
154
+            if(empty($secret)){
155
+                $secret = get_config('session_secret', null);
156
+                $this->setSessionSecret($secret);
157
+            }
158
+            $this->logger->info('Session secret: ' . $secret);
159
+
160
+            if(! $this->getModelInstance()){
161
+                $this->setModelInstanceFromConfig();
162
+            }
163
+            $this->setInitializerVector($secret);
164
+
165
+            //set session tables columns
166
+            $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167
+
168
+            if(empty($this->sessionTableColumns)){
169
+                show_error('The session handler is "database" but the table columns not set');
170
+            }
171
+            $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
172 172
 			
173
-			//delete the expired session
174
-			$timeActivity = get_config('session_inactivity_time', 100);
175
-			$this->gc($timeActivity);
173
+            //delete the expired session
174
+            $timeActivity = get_config('session_inactivity_time', 100);
175
+            $this->gc($timeActivity);
176 176
 			
177
-			return true;
178
-		}
179
-
180
-		/**
181
-		 * Close the session
182
-		 * @return boolean
183
-		 */
184
-		public function close(){
185
-			$this->logger->debug('Closing database session handler');
186
-			return true;
187
-		}
188
-
189
-		/**
190
-		 * Get the session value for the given session id
191
-		 * @param  string $sid the session id to use
192
-		 * @return string      the session data in serialiaze format
193
-		 */
194
-		public function read($sid){
195
-			$this->logger->debug('Reading database session data for SID: ' . $sid);
196
-			$instance = $this->getModelInstance();
197
-			$columns = $this->sessionTableColumns;
198
-			if($this->getLoader()){
199
-				$this->getLoader()->functions('user_agent'); 
200
-				$this->getLoader()->library('Browser'); 
201
-			}
202
-			else{
203
-            	Loader::functions('user_agent');
204
-            	Loader::library('Browser');
177
+            return true;
178
+        }
179
+
180
+        /**
181
+         * Close the session
182
+         * @return boolean
183
+         */
184
+        public function close(){
185
+            $this->logger->debug('Closing database session handler');
186
+            return true;
187
+        }
188
+
189
+        /**
190
+         * Get the session value for the given session id
191
+         * @param  string $sid the session id to use
192
+         * @return string      the session data in serialiaze format
193
+         */
194
+        public function read($sid){
195
+            $this->logger->debug('Reading database session data for SID: ' . $sid);
196
+            $instance = $this->getModelInstance();
197
+            $columns = $this->sessionTableColumns;
198
+            if($this->getLoader()){
199
+                $this->getLoader()->functions('user_agent'); 
200
+                $this->getLoader()->library('Browser'); 
201
+            }
202
+            else{
203
+                Loader::functions('user_agent');
204
+                Loader::library('Browser');
205 205
             }
206 206
 			
207
-			$ip = get_ip();
208
-			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
207
+            $ip = get_ip();
208
+            $host = @gethostbyaddr($ip) or null;
209
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
210 210
 			
211
-			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
213
-				//checking inactivity 
214
-				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
216
-					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217
-					$this->destroy($sid);
218
-					return null;
219
-				}
220
-				return $this->decode($data->{$columns['sdata']});
221
-			}
222
-			$this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
223
-			return null;
224
-		}
225
-
226
-		/**
227
-		 * Save the session data
228
-		 * @param  string $sid  the session ID
229
-		 * @param  mixed $data the session data to save in serialize format
230
-		 * @return boolean 
231
-		 */
232
-		public function write($sid, $data){
233
-			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234
-			$instance = $this->getModelInstance();
235
-			$columns = $this->sessionTableColumns;
236
-
237
-			if($this->getLoader()){
238
-				$this->getLoader()->functions('user_agent'); 
239
-				$this->getLoader()->library('Browser'); 
240
-			}
241
-			else{
242
-            	Loader::functions('user_agent');
243
-            	Loader::library('Browser');
211
+            $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
+            if($data && isset($data->{$columns['sdata']})){
213
+                //checking inactivity 
214
+                $timeInactivity = time() - get_config('session_inactivity_time', 100);
215
+                if($data->{$columns['stime']} < $timeInactivity){
216
+                    $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217
+                    $this->destroy($sid);
218
+                    return null;
219
+                }
220
+                return $this->decode($data->{$columns['sdata']});
221
+            }
222
+            $this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
223
+            return null;
224
+        }
225
+
226
+        /**
227
+         * Save the session data
228
+         * @param  string $sid  the session ID
229
+         * @param  mixed $data the session data to save in serialize format
230
+         * @return boolean 
231
+         */
232
+        public function write($sid, $data){
233
+            $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234
+            $instance = $this->getModelInstance();
235
+            $columns = $this->sessionTableColumns;
236
+
237
+            if($this->getLoader()){
238
+                $this->getLoader()->functions('user_agent'); 
239
+                $this->getLoader()->library('Browser'); 
240
+            }
241
+            else{
242
+                Loader::functions('user_agent');
243
+                Loader::library('Browser');
244
+            }
245
+
246
+            $ip = get_ip();
247
+            $keyValue = $instance->getKeyValue();
248
+            $host = @gethostbyaddr($ip) or null;
249
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
250
+            $data = $this->encode($data);
251
+            $params = array(
252
+                            $columns['sid'] => $sid,
253
+                            $columns['sdata'] => $data,
254
+                            $columns['stime'] => time(),
255
+                            $columns['shost'] => $host,
256
+                            $columns['sbrowser'] => $browser,
257
+                            $columns['sip'] => $ip,
258
+                            $columns['skey'] => $keyValue
259
+                        );
260
+            $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261
+            $exists = $instance->get($sid);
262
+            if($exists){
263
+                $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264
+                //update
265
+                unset($params[$columns['sid']]);
266
+                $instance->update($sid, $params);
244 267
             }
268
+            else{
269
+                $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270
+                $instance->insert($params);
271
+            }
272
+            return true;
273
+        }
274
+
275
+
276
+        /**
277
+         * Destroy the session data for the given session id
278
+         * @param  string $sid the session id value
279
+         * @return boolean
280
+         */
281
+        public function destroy($sid){
282
+            $this->logger->debug('Destroy of session data for SID: ' . $sid);
283
+            $instance = $this->modelInstanceName;
284
+            $instance->delete($sid);
285
+            return true;
286
+        }
245 287
 
246
-			$ip = get_ip();
247
-			$keyValue = $instance->getKeyValue();
248
-			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
250
-			$data = $this->encode($data);
251
-			$params = array(
252
-							$columns['sid'] => $sid,
253
-							$columns['sdata'] => $data,
254
-							$columns['stime'] => time(),
255
-							$columns['shost'] => $host,
256
-							$columns['sbrowser'] => $browser,
257
-							$columns['sip'] => $ip,
258
-							$columns['skey'] => $keyValue
259
-						);
260
-			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261
-			$exists = $instance->get($sid);
262
-			if($exists){
263
-				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264
-				//update
265
-				unset($params[$columns['sid']]);
266
-				$instance->update($sid, $params);
267
-			}
268
-			else{
269
-				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270
-				$instance->insert($params);
271
-			}
272
-			return true;
273
-		}
274
-
275
-
276
-		/**
277
-		 * Destroy the session data for the given session id
278
-		 * @param  string $sid the session id value
279
-		 * @return boolean
280
-		 */
281
-		public function destroy($sid){
282
-			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283
-			$instance = $this->modelInstanceName;
284
-			$instance->delete($sid);
285
-			return true;
286
-		}
287
-
288
-		/**
289
-		 * Clean the expire session data to save espace
290
-		 * @param  integer $maxLifetime the max lifetime
291
-		 * @return boolean
292
-		 */
293
-		public function gc($maxLifetime){
294
-			$instance = $this->modelInstanceName;
295
-			$time = time() - $maxLifetime;
296
-			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
297
-			$instance->deleteByTime($time);
298
-			return true;
299
-		}
300
-
301
-		/**
302
-		 * Encode the session data using the openssl
303
-		 * @param  mixed $data the session data to encode
304
-		 * @return mixed the encoded session data
305
-		 */
306
-		public function encode($data){
307
-			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309
-			$output = base64_encode($dataEncrypted);
310
-			return $output;
311
-		}
312
-
313
-
314
-		/**
315
-		 * Decode the session data using the openssl
316
-		 * @param  mixed $data the data to decode
317
-		 * @return mixed       the decoded data
318
-		 */
319
-		public function decode($data){
320
-			$key = base64_decode($this->sessionSecret);
321
-			$data = base64_decode($data);
322
-			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
323
-			return $data;
324
-		}
288
+        /**
289
+         * Clean the expire session data to save espace
290
+         * @param  integer $maxLifetime the max lifetime
291
+         * @return boolean
292
+         */
293
+        public function gc($maxLifetime){
294
+            $instance = $this->modelInstanceName;
295
+            $time = time() - $maxLifetime;
296
+            $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
297
+            $instance->deleteByTime($time);
298
+            return true;
299
+        }
300
+
301
+        /**
302
+         * Encode the session data using the openssl
303
+         * @param  mixed $data the session data to encode
304
+         * @return mixed the encoded session data
305
+         */
306
+        public function encode($data){
307
+            $key = base64_decode($this->sessionSecret);
308
+            $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309
+            $output = base64_encode($dataEncrypted);
310
+            return $output;
311
+        }
312
+
313
+
314
+        /**
315
+         * Decode the session data using the openssl
316
+         * @param  mixed $data the data to decode
317
+         * @return mixed       the decoded data
318
+         */
319
+        public function decode($data){
320
+            $key = base64_decode($this->sessionSecret);
321
+            $data = base64_decode($data);
322
+            $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
323
+            return $data;
324
+        }
325 325
 
326 326
 		
327
-		/**
327
+        /**
328 328
          * Return the loader instance
329 329
          * @return object Loader the loader instance
330 330
          */
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param object Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+            public function setLoader($loader){
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -353,47 +353,47 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+            public function setModelInstance(DBSessionHandlerModel $modelInstance){
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
360 360
 
361 361
         /**
362
-	     * Return the Log instance
363
-	     * @return Log
364
-	     */
365
-	    public function getLogger(){
366
-	      return $this->logger;
367
-	    }
368
-
369
-	    /**
370
-	     * Set the log instance
371
-	     * @param Log $logger the log object
372
-	     */
373
-	    public function setLogger(Log $logger){
374
-	      $this->logger = $logger;
375
-	      return $this;
376
-	    }
377
-
378
-	    /**
379
-	     * Set the model instance using the configuration for session
380
-	     */
381
-	    private function setModelInstanceFromConfig(){
382
-	    	$modelName = get_config('session_save_path');
383
-			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
385
-				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386
-			}
387
-			//@codeCoverageIgnoreStart
388
-			else{
389
-            	Loader::model($modelName, 'dbsessionhandlerinstance'); 
362
+         * Return the Log instance
363
+         * @return Log
364
+         */
365
+        public function getLogger(){
366
+            return $this->logger;
367
+        }
368
+
369
+        /**
370
+         * Set the log instance
371
+         * @param Log $logger the log object
372
+         */
373
+        public function setLogger(Log $logger){
374
+            $this->logger = $logger;
375
+            return $this;
376
+        }
377
+
378
+        /**
379
+         * Set the model instance using the configuration for session
380
+         */
381
+        private function setModelInstanceFromConfig(){
382
+            $modelName = get_config('session_save_path');
383
+            $this->logger->info('The database session model: ' . $modelName);
384
+            if($this->getLoader()){
385
+                $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386
+            }
387
+            //@codeCoverageIgnoreStart
388
+            else{
389
+                Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391 391
             if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
393
-			}  
394
-			//@codeCoverageIgnoreEnd
392
+                show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
393
+            }  
394
+            //@codeCoverageIgnoreEnd
395 395
 			
396
-			//set model instance
397
-			$this->setModelInstance($this->OBJ->dbsessionhandlerinstance);
398
-	    }
399
-	}
396
+            //set model instance
397
+            $this->setModelInstance($this->OBJ->dbsessionhandlerinstance);
398
+        }
399
+    }
Please login to merge, or discard this patch.
core/classes/model/DBSessionHandlerModel.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		 */
46 46
 		protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(Database $db = null){
48
+		public function __construct(Database $db = null) {
49 49
 			parent::__construct($db);
50 50
 		}
51 51
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		 * Return the session database table columns
54 54
 		 * @return array 
55 55
 		 */
56
-		public function getSessionTableColumns(){
56
+		public function getSessionTableColumns() {
57 57
 			return $this->sessionTableColumns;
58 58
 		}
59 59
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		 * Set the session database table columns
62 62
 		 * @param array $columns the columns definition
63 63
 		 */
64
-		public function setSessionTableColumns(array $columns){
64
+		public function setSessionTableColumns(array $columns) {
65 65
 			$this->sessionTableColumns = $columns;
66 66
 			return $this;
67 67
 		}
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	/**
28
-	 * DB session handler class
29
-	 */
30
- 	abstract class DBSessionHandlerModel extends Model {
27
+    /**
28
+     * DB session handler class
29
+     */
30
+        abstract class DBSessionHandlerModel extends Model {
31 31
 		
32
-		/**
33
-		 * The session table columns to use
34
-		 * @var array
35
-		 * @example
36
-		 * 	array(
32
+        /**
33
+         * The session table columns to use
34
+         * @var array
35
+         * @example
36
+         * 	array(
37 37
 				'sid' => '', //VARCHAR(255) Note: this a primary key
38 38
 				'sdata' => '', //TEXT
39 39
 				'stime' => '', //unix timestamp (INT|BIGINT)
@@ -42,41 +42,41 @@  discard block
 block discarded – undo
42 42
 				'sbrowser' => '', //VARCHAR(255) 
43 43
 				'skey' => '' //VARCHAR(255) 
44 44
 			);
45
-		 */
46
-		protected $sessionTableColumns = array();
45
+         */
46
+        protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(Database $db = null){
49
-			parent::__construct($db);
50
-		}
48
+        public function __construct(Database $db = null){
49
+            parent::__construct($db);
50
+        }
51 51
 
52
-		/**
53
-		 * Return the session database table columns
54
-		 * @return array 
55
-		 */
56
-		public function getSessionTableColumns(){
57
-			return $this->sessionTableColumns;
58
-		}
52
+        /**
53
+         * Return the session database table columns
54
+         * @return array 
55
+         */
56
+        public function getSessionTableColumns(){
57
+            return $this->sessionTableColumns;
58
+        }
59 59
 
60
-		/**
61
-		 * Set the session database table columns
62
-		 * @param array $columns the columns definition
63
-		 */
64
-		public function setSessionTableColumns(array $columns){
65
-			$this->sessionTableColumns = $columns;
66
-			return $this;
67
-		}
60
+        /**
61
+         * Set the session database table columns
62
+         * @param array $columns the columns definition
63
+         */
64
+        public function setSessionTableColumns(array $columns){
65
+            $this->sessionTableColumns = $columns;
66
+            return $this;
67
+        }
68 68
 
69
-		/**
70
-		 * Delete the expire session
71
-		 * @param  int $time the unix timestamp
72
-		 * @return int       affected rows
73
-		 */
74
-		abstract public function deleteByTime($time);
69
+        /**
70
+         * Delete the expire session
71
+         * @param  int $time the unix timestamp
72
+         * @return int       affected rows
73
+         */
74
+        abstract public function deleteByTime($time);
75 75
 
76 76
 		
77
-		/**
78
-		 * How to get the value of the table column key. Generally is the session key
79
-		 * @return mixed the key value like used to identify the data
80
-		 */
81
-		abstract public function getKeyValue();
82
-	}
77
+        /**
78
+         * How to get the value of the table column key. Generally is the session key
79
+         * @return mixed the key value like used to identify the data
80
+         */
81
+        abstract public function getKeyValue();
82
+    }
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 3 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 	
27
-	class ApcCache implements CacheInterface{
27
+	class ApcCache implements CacheInterface {
28 28
 
29 29
 		/**
30 30
 		 * The logger instance
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
 		private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
36
+		public function __construct(Log $logger = null) {
37
+			if (!$this->isSupported()) {
38 38
 				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39 39
 			}
40 40
 
41 41
 			/**
42 42
 	         * instance of the Log class
43 43
 	         */
44
-	        if(is_object($logger)){
44
+	        if (is_object($logger)) {
45 45
 	          $this->logger = $logger;
46 46
 	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
47
+	        else {
48
+	            $this->logger = & class_loader('Log', 'classes');
49 49
 	            $this->logger->setLogger('Library::ApcCache');
50 50
 	        }
51 51
 		}
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 		 * @param  string $key the key to identify the cache data
56 56
 		 * @return mixed      the cache data if exists else return false
57 57
 		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
58
+		public function get($key) {
59
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
60 60
 			$success = false;
61 61
 			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
62
+			if ($success === false) {
63
+				$this->logger->info('No cache found for the key [' . $key . '], return false');
64 64
 				return false;
65 65
 			}
66
-			else{
66
+			else {
67 67
 				$cacheInfo = $this->_getCacheInfo($key);
68 68
 				$expire = time();
69
-				if($cacheInfo){
69
+				if ($cacheInfo) {
70 70
 					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71 71
 				}
72
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
72
+				$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73 73
 				return $data;
74 74
 			}
75 75
 		}
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 		 * @param integer $ttl  the cache life time
83 83
 		 * @return boolean true if success otherwise will return false
84 84
 		 */
85
-		public function set($key, $data, $ttl = 0){
85
+		public function set($key, $data, $ttl = 0) {
86 86
 			$expire = time() + $ttl;
87
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
87
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88 88
 			$result = apc_store($key, $data, $ttl);
89
-			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
89
+			if ($result === false) {
90
+		    	$this->logger->error('Can not write cache data for the key [' . $key . '], return false');
91 91
 		    	return false;
92 92
 		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
93
+		    else {
94
+		    	$this->logger->info('Cache data saved for the key [' . $key . ']');
95 95
 		    	return true;
96 96
 		    }
97 97
 		}
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 		 * @return boolean      true if the cache is deleted, false if can't delete 
104 104
 		 * the cache or the cache with the given key not exist
105 105
 		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
106
+		public function delete($key) {
107
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
108 108
 			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
109
+			if ($cacheInfo === false) {
110 110
 				$this->logger->info('This cache data does not exists skipping');
111 111
 				return false;
112 112
 			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
113
+			else {
114
+				$this->logger->info('Found cache data for the key [' . $key . '] remove it');
115 115
 	      		return apc_delete($key) === true;
116 116
 			}
117 117
 		}
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
 		 * 'expire' => expiration time of the cache (Unix timestamp),
125 125
 		 * 'ttl' => the time to live of the cache in second
126 126
 		 */
127
-		public function getInfo($key){
128
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
127
+		public function getInfo($key) {
128
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
129 129
 			$cacheInfos = $this->_getCacheInfo($key);
130
-			if($cacheInfos){
130
+			if ($cacheInfos) {
131 131
 				$data = array(
132 132
 							'mtime' => $cacheInfos['creation_time'],
133 133
 							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 							);
136 136
 				return $data;
137 137
 			}
138
-			else{
138
+			else {
139 139
 				$this->logger->info('This cache does not exists skipping');
140 140
 				return false;
141 141
 			}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		/**
146 146
 		 * Used to delete expired cache data
147 147
 		 */
148
-		public function deleteExpiredCache(){
148
+		public function deleteExpiredCache() {
149 149
 			//for APC[u] is done automatically
150 150
 			return true;
151 151
 		}
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 		/**
154 154
 		 * Remove all cache data
155 155
 		 */
156
-		public function clean(){
156
+		public function clean() {
157 157
 			$this->logger->debug('Deleting of all cache data');
158 158
 			$cacheInfos = apc_cache_info('user');
159
-			if(empty($cacheInfos['cache_list'])){
159
+			if (empty($cacheInfos['cache_list'])) {
160 160
 				$this->logger->info('No cache data were found skipping');
161 161
 				return false;
162 162
 			}
163
-			else{
163
+			else {
164 164
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165 165
 				return apc_clear_cache('user');
166 166
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		 *
173 173
 		 * @return bool
174 174
 		 */
175
-		public function isSupported(){
175
+		public function isSupported() {
176 176
 			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177 177
 		}
178 178
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	     * Return the Log instance
181 181
 	     * @return Log
182 182
 	     */
183
-	    public function getLogger(){
183
+	    public function getLogger() {
184 184
 	      return $this->logger;
185 185
 	    }
186 186
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	     * Set the log instance
189 189
 	     * @param Log $logger the log object
190 190
 	     */
191
-	    public function setLogger(Log $logger){
191
+	    public function setLogger(Log $logger) {
192 192
 	      $this->logger = $logger;
193 193
 	      return $this;
194 194
 	    }
@@ -199,12 +199,12 @@  discard block
 block discarded – undo
199 199
 		* @param string $key the cache key to get the cache information 
200 200
 		* @return boolean|array
201 201
 		*/
202
-		private function _getCacheInfo($key){
202
+		private function _getCacheInfo($key) {
203 203
 			$caches = apc_cache_info('user');
204
-			if(! empty($caches['cache_list'])){
204
+			if (!empty($caches['cache_list'])) {
205 205
 				$cacheLists = $caches['cache_list'];
206
-				foreach ($cacheLists as $c){
207
-					if(isset($c['info']) && $c['info'] === $key){
206
+				foreach ($cacheLists as $c) {
207
+					if (isset($c['info']) && $c['info'] === $key) {
208 208
 						return $c;
209 209
 					}
210 210
 				}
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@  discard block
 block discarded – undo
43 43
 	         */
44 44
 	        if(is_object($logger)){
45 45
 	          $this->logger = $logger;
46
-	        }
47
-	        else{
46
+	        } else{
48 47
 	            $this->logger =& class_loader('Log', 'classes');
49 48
 	            $this->logger->setLogger('Library::ApcCache');
50 49
 	        }
@@ -62,8 +61,7 @@  discard block
 block discarded – undo
62 61
 			if($success === false){
63 62
 				$this->logger->info('No cache found for the key ['. $key .'], return false');
64 63
 				return false;
65
-			}
66
-			else{
64
+			} else{
67 65
 				$cacheInfo = $this->_getCacheInfo($key);
68 66
 				$expire = time();
69 67
 				if($cacheInfo){
@@ -89,8 +87,7 @@  discard block
 block discarded – undo
89 87
 			if($result === false){
90 88
 		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91 89
 		    	return false;
92
-		    }
93
-		    else{
90
+		    } else{
94 91
 		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95 92
 		    	return true;
96 93
 		    }
@@ -109,8 +106,7 @@  discard block
 block discarded – undo
109 106
 			if($cacheInfo === false){
110 107
 				$this->logger->info('This cache data does not exists skipping');
111 108
 				return false;
112
-			}
113
-			else{
109
+			} else{
114 110
 				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115 111
 	      		return apc_delete($key) === true;
116 112
 			}
@@ -134,8 +130,7 @@  discard block
 block discarded – undo
134 130
 							'ttl' => $cacheInfos['ttl']
135 131
 							);
136 132
 				return $data;
137
-			}
138
-			else{
133
+			} else{
139 134
 				$this->logger->info('This cache does not exists skipping');
140 135
 				return false;
141 136
 			}
@@ -159,8 +154,7 @@  discard block
 block discarded – undo
159 154
 			if(empty($cacheInfos['cache_list'])){
160 155
 				$this->logger->info('No cache data were found skipping');
161 156
 				return false;
162
-			}
163
-			else{
157
+			} else{
164 158
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165 159
 				return apc_clear_cache('user');
166 160
 			}
Please login to merge, or discard this patch.
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -1,215 +1,215 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	class ApcCache implements CacheInterface{
27
+    class ApcCache implements CacheInterface{
28 28
 
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
38
-				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
-			}
36
+        public function __construct(Log $logger = null){
37
+            if(! $this->isSupported()){
38
+                show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
+            }
40 40
 
41
-			/**
42
-	         * instance of the Log class
43
-	         */
44
-	        if(is_object($logger)){
45
-	          $this->logger = $logger;
46
-	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
49
-	            $this->logger->setLogger('Library::ApcCache');
50
-	        }
51
-		}
41
+            /**
42
+             * instance of the Log class
43
+             */
44
+            if(is_object($logger)){
45
+                $this->logger = $logger;
46
+            }
47
+            else{
48
+                $this->logger =& class_loader('Log', 'classes');
49
+                $this->logger->setLogger('Library::ApcCache');
50
+            }
51
+        }
52 52
 
53
-		/**
54
-		 * This is used to get the cache data using the key
55
-		 * @param  string $key the key to identify the cache data
56
-		 * @return mixed      the cache data if exists else return false
57
-		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
60
-			$success = false;
61
-			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
64
-				return false;
65
-			}
66
-			else{
67
-				$cacheInfo = $this->_getCacheInfo($key);
68
-				$expire = time();
69
-				if($cacheInfo){
70
-					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71
-				}
72
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73
-				return $data;
74
-			}
75
-		}
53
+        /**
54
+         * This is used to get the cache data using the key
55
+         * @param  string $key the key to identify the cache data
56
+         * @return mixed      the cache data if exists else return false
57
+         */
58
+        public function get($key){
59
+            $this->logger->debug('Getting cache data for key ['. $key .']');
60
+            $success = false;
61
+            $data = apc_fetch($key, $success);
62
+            if($success === false){
63
+                $this->logger->info('No cache found for the key ['. $key .'], return false');
64
+                return false;
65
+            }
66
+            else{
67
+                $cacheInfo = $this->_getCacheInfo($key);
68
+                $expire = time();
69
+                if($cacheInfo){
70
+                    $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71
+                }
72
+                $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73
+                return $data;
74
+            }
75
+        }
76 76
 
77 77
 
78
-		/**
79
-		 * Save data to the cache
80
-		 * @param string  $key  the key to identify this cache data
81
-		 * @param mixed  $data the cache data to be saved
82
-		 * @param integer $ttl  the cache life time
83
-		 * @return boolean true if success otherwise will return false
84
-		 */
85
-		public function set($key, $data, $ttl = 0){
86
-			$expire = time() + $ttl;
87
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88
-			$result = apc_store($key, $data, $ttl);
89
-			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
-		    	return false;
92
-		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95
-		    	return true;
96
-		    }
97
-		}
78
+        /**
79
+         * Save data to the cache
80
+         * @param string  $key  the key to identify this cache data
81
+         * @param mixed  $data the cache data to be saved
82
+         * @param integer $ttl  the cache life time
83
+         * @return boolean true if success otherwise will return false
84
+         */
85
+        public function set($key, $data, $ttl = 0){
86
+            $expire = time() + $ttl;
87
+            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88
+            $result = apc_store($key, $data, $ttl);
89
+            if($result === false){
90
+                $this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
+                return false;
92
+            }
93
+            else{
94
+                $this->logger->info('Cache data saved for the key ['. $key .']');
95
+                return true;
96
+            }
97
+        }
98 98
 
99 99
 
100
-		/**
101
-		 * Delete the cache data for given key
102
-		 * @param  string $key the key for cache to be deleted
103
-		 * @return boolean      true if the cache is deleted, false if can't delete 
104
-		 * the cache or the cache with the given key not exist
105
-		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
-			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
110
-				$this->logger->info('This cache data does not exists skipping');
111
-				return false;
112
-			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
-	      		return apc_delete($key) === true;
116
-			}
117
-		}
100
+        /**
101
+         * Delete the cache data for given key
102
+         * @param  string $key the key for cache to be deleted
103
+         * @return boolean      true if the cache is deleted, false if can't delete 
104
+         * the cache or the cache with the given key not exist
105
+         */
106
+        public function delete($key){
107
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
+            $cacheInfo = $this->_getCacheInfo($key);
109
+            if($cacheInfo === false){
110
+                $this->logger->info('This cache data does not exists skipping');
111
+                return false;
112
+            }
113
+            else{
114
+                $this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
+                    return apc_delete($key) === true;
116
+            }
117
+        }
118 118
 		
119
-		/**
120
-		 * Get the cache information for given key
121
-		 * @param  string $key the key for cache to get the information for
122
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
123
-		 * 'mtime' => creation time of the cache (Unix timestamp),
124
-		 * 'expire' => expiration time of the cache (Unix timestamp),
125
-		 * 'ttl' => the time to live of the cache in second
126
-		 */
127
-		public function getInfo($key){
128
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
129
-			$cacheInfos = $this->_getCacheInfo($key);
130
-			if($cacheInfos){
131
-				$data = array(
132
-							'mtime' => $cacheInfos['creation_time'],
133
-							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
-							'ttl' => $cacheInfos['ttl']
135
-							);
136
-				return $data;
137
-			}
138
-			else{
139
-				$this->logger->info('This cache does not exists skipping');
140
-				return false;
141
-			}
142
-		}
119
+        /**
120
+         * Get the cache information for given key
121
+         * @param  string $key the key for cache to get the information for
122
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
123
+         * 'mtime' => creation time of the cache (Unix timestamp),
124
+         * 'expire' => expiration time of the cache (Unix timestamp),
125
+         * 'ttl' => the time to live of the cache in second
126
+         */
127
+        public function getInfo($key){
128
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
129
+            $cacheInfos = $this->_getCacheInfo($key);
130
+            if($cacheInfos){
131
+                $data = array(
132
+                            'mtime' => $cacheInfos['creation_time'],
133
+                            'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
+                            'ttl' => $cacheInfos['ttl']
135
+                            );
136
+                return $data;
137
+            }
138
+            else{
139
+                $this->logger->info('This cache does not exists skipping');
140
+                return false;
141
+            }
142
+        }
143 143
 
144 144
 
145
-		/**
146
-		 * Used to delete expired cache data
147
-		 */
148
-		public function deleteExpiredCache(){
149
-			//for APC[u] is done automatically
150
-			return true;
151
-		}
145
+        /**
146
+         * Used to delete expired cache data
147
+         */
148
+        public function deleteExpiredCache(){
149
+            //for APC[u] is done automatically
150
+            return true;
151
+        }
152 152
 
153
-		/**
154
-		 * Remove all cache data
155
-		 */
156
-		public function clean(){
157
-			$this->logger->debug('Deleting of all cache data');
158
-			$cacheInfos = apc_cache_info('user');
159
-			if(empty($cacheInfos['cache_list'])){
160
-				$this->logger->info('No cache data were found skipping');
161
-				return false;
162
-			}
163
-			else{
164
-				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
-				return apc_clear_cache('user');
166
-			}
167
-		}
153
+        /**
154
+         * Remove all cache data
155
+         */
156
+        public function clean(){
157
+            $this->logger->debug('Deleting of all cache data');
158
+            $cacheInfos = apc_cache_info('user');
159
+            if(empty($cacheInfos['cache_list'])){
160
+                $this->logger->info('No cache data were found skipping');
161
+                return false;
162
+            }
163
+            else{
164
+                $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
+                return apc_clear_cache('user');
166
+            }
167
+        }
168 168
 		
169 169
 		
170
-		/**
171
-		 * Check whether the cache feature for the handle is supported
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function isSupported(){
176
-			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
-		}
170
+        /**
171
+         * Check whether the cache feature for the handle is supported
172
+         *
173
+         * @return bool
174
+         */
175
+        public function isSupported(){
176
+            return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
+        }
178 178
 
179
-		/**
180
-	     * Return the Log instance
181
-	     * @return Log
182
-	     */
183
-	    public function getLogger(){
184
-	      return $this->logger;
185
-	    }
179
+        /**
180
+         * Return the Log instance
181
+         * @return Log
182
+         */
183
+        public function getLogger(){
184
+            return $this->logger;
185
+        }
186 186
 
187
-	    /**
188
-	     * Set the log instance
189
-	     * @param Log $logger the log object
190
-	     */
191
-	    public function setLogger(Log $logger){
192
-	      $this->logger = $logger;
193
-	      return $this;
194
-	    }
187
+        /**
188
+         * Set the log instance
189
+         * @param Log $logger the log object
190
+         */
191
+        public function setLogger(Log $logger){
192
+            $this->logger = $logger;
193
+            return $this;
194
+        }
195 195
 		
196
-		/**
197
-		* Return the array of cache information
198
-		*
199
-		* @param string $key the cache key to get the cache information 
200
-		* @return boolean|array
201
-		*/
202
-		private function _getCacheInfo($key){
203
-			$caches = apc_cache_info('user');
204
-			if(! empty($caches['cache_list'])){
205
-				$cacheLists = $caches['cache_list'];
206
-				foreach ($cacheLists as $c){
207
-					if(isset($c['info']) && $c['info'] === $key){
208
-						return $c;
209
-					}
210
-				}
196
+        /**
197
+         * Return the array of cache information
198
+         *
199
+         * @param string $key the cache key to get the cache information 
200
+         * @return boolean|array
201
+         */
202
+        private function _getCacheInfo($key){
203
+            $caches = apc_cache_info('user');
204
+            if(! empty($caches['cache_list'])){
205
+                $cacheLists = $caches['cache_list'];
206
+                foreach ($cacheLists as $c){
207
+                    if(isset($c['info']) && $c['info'] === $key){
208
+                        return $c;
209
+                    }
210
+                }
211 211
 				
212
-			}
213
-			return false;
214
-		}
215
-	}
212
+            }
213
+            return false;
214
+        }
215
+    }
Please login to merge, or discard this patch.