@@ -24,20 +24,20 @@ |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - public function testFunctionGetConfigKeyNotExist(){ |
|
| 27 | + public function testFunctionGetConfigKeyNotExist() { |
|
| 28 | 28 | $key = 'foo'; |
| 29 | 29 | $cfg = get_config($key); |
| 30 | 30 | $this->assertNull($cfg); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){ |
|
| 33 | + public function testFunctionGetConfigKeyNotExistUsingDefaultValue() { |
|
| 34 | 34 | $key = 'foo'; |
| 35 | 35 | $expected = 'bar'; |
| 36 | 36 | $cfg = get_config($key, $expected); |
| 37 | 37 | $this->assertEquals($cfg, $expected); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function testFunctionGetConfigAfterSet(){ |
|
| 40 | + public function testFunctionGetConfigAfterSet() { |
|
| 41 | 41 | $key = 'foo'; |
| 42 | 42 | $expected = 'bar'; |
| 43 | 43 | $c = new Config(); |
@@ -1,50 +1,50 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class CommonTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class CommonTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - public function testFunctionGetConfigKeyNotExist(){ |
|
| 28 | - $key = 'foo'; |
|
| 29 | - $cfg = get_config($key); |
|
| 30 | - $this->assertNull($cfg); |
|
| 31 | - } |
|
| 27 | + public function testFunctionGetConfigKeyNotExist(){ |
|
| 28 | + $key = 'foo'; |
|
| 29 | + $cfg = get_config($key); |
|
| 30 | + $this->assertNull($cfg); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){ |
|
| 34 | - $key = 'foo'; |
|
| 35 | - $expected = 'bar'; |
|
| 36 | - $cfg = get_config($key, $expected); |
|
| 37 | - $this->assertEquals($cfg, $expected); |
|
| 38 | - } |
|
| 33 | + public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){ |
|
| 34 | + $key = 'foo'; |
|
| 35 | + $expected = 'bar'; |
|
| 36 | + $cfg = get_config($key, $expected); |
|
| 37 | + $this->assertEquals($cfg, $expected); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function testFunctionGetConfigAfterSet(){ |
|
| 41 | - $key = 'foo'; |
|
| 42 | - $expected = 'bar'; |
|
| 43 | - $c = new Config(); |
|
| 44 | - $c->init(); |
|
| 45 | - $c->set($key, $expected); |
|
| 46 | - $cfg = get_config($key); |
|
| 47 | - $this->assertEquals($cfg, $expected); |
|
| 48 | - } |
|
| 40 | + public function testFunctionGetConfigAfterSet(){ |
|
| 41 | + $key = 'foo'; |
|
| 42 | + $expected = 'bar'; |
|
| 43 | + $c = new Config(); |
|
| 44 | + $c->init(); |
|
| 45 | + $c->set($key, $expected); |
|
| 46 | + $cfg = get_config($key); |
|
| 47 | + $this->assertEquals($cfg, $expected); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - } |
|
| 51 | 50 | \ No newline at end of file |
| 51 | + } |
|
| 52 | 52 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -43,8 +43,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -1,215 +1,215 @@ |
||
| 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 | + } |
|
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * Class for Benchmark |
| 29 | 29 | */ |
| 30 | - class Benchmark{ |
|
| 30 | + class Benchmark { |
|
| 31 | 31 | /** |
| 32 | 32 | * The markers for excution time |
| 33 | 33 | * @var array |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * This method is used to mark one point for benchmark (execution time and memory usage) |
| 45 | 45 | * @param string $name the marker name |
| 46 | 46 | */ |
| 47 | - public function mark($name){ |
|
| 47 | + public function mark($name) { |
|
| 48 | 48 | //Marker for execution time |
| 49 | 49 | $this->markersTime[$name] = microtime(true); |
| 50 | 50 | //Marker for memory usage |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | * @param integer $decimalCount the number of decimal |
| 59 | 59 | * @return string the total execution time |
| 60 | 60 | */ |
| 61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
| 62 | + if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) { |
|
| 63 | 63 | return 0; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
| 66 | + if (!isset($this->markersTime[$endMarkerName])) { |
|
| 67 | 67 | $this->markersTime[$endMarkerName] = microtime(true); |
| 68 | 68 | } |
| 69 | 69 | return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | * @param integer $decimalCount the number of decimal |
| 77 | 77 | * @return string the total memory usage |
| 78 | 78 | */ |
| 79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
| 80 | + if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) { |
|
| 81 | 81 | return 0; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 84 | + if (!isset($this->markersMemory[$endMarkerName])) { |
|
| 85 | 85 | $this->markersMemory[$endMarkerName] = microtime(true); |
| 86 | 86 | } |
| 87 | 87 | return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
@@ -1,89 +1,89 @@ |
||
| 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 | - /** |
|
| 28 | - * Class for Benchmark |
|
| 29 | - */ |
|
| 30 | - class Benchmark{ |
|
| 31 | - /** |
|
| 32 | - * The markers for excution time |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $markersTime = array(); |
|
| 27 | + /** |
|
| 28 | + * Class for Benchmark |
|
| 29 | + */ |
|
| 30 | + class Benchmark{ |
|
| 31 | + /** |
|
| 32 | + * The markers for excution time |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $markersTime = array(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * The markers for memory usage |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $markersMemory = array(); |
|
| 37 | + /** |
|
| 38 | + * The markers for memory usage |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $markersMemory = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | - * @param string $name the marker name |
|
| 46 | - */ |
|
| 47 | - public function mark($name){ |
|
| 48 | - //Marker for execution time |
|
| 49 | - $this->markersTime[$name] = microtime(true); |
|
| 50 | - //Marker for memory usage |
|
| 51 | - $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | + * @param string $name the marker name |
|
| 46 | + */ |
|
| 47 | + public function mark($name){ |
|
| 48 | + //Marker for execution time |
|
| 49 | + $this->markersTime[$name] = microtime(true); |
|
| 50 | + //Marker for memory usage |
|
| 51 | + $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * This method is used to get the total excution time in second between two markers |
|
| 56 | - * @param string $startMarkerName the marker for start point |
|
| 57 | - * @param string $endMarkerName the marker for end point |
|
| 58 | - * @param integer $decimalCount the number of decimal |
|
| 59 | - * @return string the total execution time |
|
| 60 | - */ |
|
| 61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | - return 0; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * This method is used to get the total excution time in second between two markers |
|
| 56 | + * @param string $startMarkerName the marker for start point |
|
| 57 | + * @param string $endMarkerName the marker for end point |
|
| 58 | + * @param integer $decimalCount the number of decimal |
|
| 59 | + * @return string the total execution time |
|
| 60 | + */ |
|
| 61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | + if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | + return 0; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | - $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | - } |
|
| 69 | - return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | - } |
|
| 66 | + if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | + $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | + } |
|
| 69 | + return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * This method is used to get the total memory usage in byte between two markers |
|
| 74 | - * @param string $startMarkerName the marker for start point |
|
| 75 | - * @param string $endMarkerName the marker for end point |
|
| 76 | - * @param integer $decimalCount the number of decimal |
|
| 77 | - * @return string the total memory usage |
|
| 78 | - */ |
|
| 79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | - return 0; |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * This method is used to get the total memory usage in byte between two markers |
|
| 74 | + * @param string $startMarkerName the marker for start point |
|
| 75 | + * @param string $endMarkerName the marker for end point |
|
| 76 | + * @param integer $decimalCount the number of decimal |
|
| 77 | + * @return string the total memory usage |
|
| 78 | + */ |
|
| 79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | + if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | + return 0; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | - $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | - } |
|
| 87 | - return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | - } |
|
| 89 | - } |
|
| 84 | + if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | + $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | + } |
|
| 87 | + return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | + } |
|
| 89 | + } |
|
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * This class represent the event detail to dispatch to correspond listener |
| 29 | 29 | */ |
| 30 | - class EventInfo{ |
|
| 30 | + class EventInfo { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public $stop; |
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
| 58 | 58 | $this->name = $name; |
| 59 | 59 | $this->payload = $payload; |
| 60 | 60 | $this->returnBack = $returnBack; |
@@ -1,63 +1,63 @@ |
||
| 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 | - /** |
|
| 28 | - * This class represent the event detail to dispatch to correspond listener |
|
| 29 | - */ |
|
| 30 | - class EventInfo{ |
|
| 27 | + /** |
|
| 28 | + * This class represent the event detail to dispatch to correspond listener |
|
| 29 | + */ |
|
| 30 | + class EventInfo{ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The event name |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $name; |
|
| 32 | + /** |
|
| 33 | + * The event name |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $name; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The event data to send to the listeners |
|
| 40 | - * @var mixed |
|
| 41 | - */ |
|
| 42 | - public $payload; |
|
| 38 | + /** |
|
| 39 | + * The event data to send to the listeners |
|
| 40 | + * @var mixed |
|
| 41 | + */ |
|
| 42 | + public $payload; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * If the listeners need return the event after treatment or not, false means no need |
|
| 46 | - * return true need return the event. |
|
| 47 | - * @var boolean |
|
| 48 | - */ |
|
| 49 | - public $returnBack; |
|
| 44 | + /** |
|
| 45 | + * If the listeners need return the event after treatment or not, false means no need |
|
| 46 | + * return true need return the event. |
|
| 47 | + * @var boolean |
|
| 48 | + */ |
|
| 49 | + public $returnBack; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * This variable indicates if need stop the event propagation |
|
| 53 | - * @var boolean |
|
| 54 | - */ |
|
| 55 | - public $stop; |
|
| 51 | + /** |
|
| 52 | + * This variable indicates if need stop the event propagation |
|
| 53 | + * @var boolean |
|
| 54 | + */ |
|
| 55 | + public $stop; |
|
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 58 | - $this->name = $name; |
|
| 59 | - $this->payload = $payload; |
|
| 60 | - $this->returnBack = $returnBack; |
|
| 61 | - $this->stop = $stop; |
|
| 62 | - } |
|
| 63 | - } |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 58 | + $this->name = $name; |
|
| 59 | + $this->payload = $payload; |
|
| 60 | + $this->returnBack = $returnBack; |
|
| 61 | + $this->stop = $stop; |
|
| 62 | + } |
|
| 63 | + } |
|
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * also to dispatch the event |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | - class EventDispatcher{ |
|
| 32 | + class EventDispatcher { |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The list of the registered listeners |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | private $logger; |
| 46 | 46 | |
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 47 | + public function __construct() { |
|
| 48 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 49 | 49 | $this->logger->setLogger('Library::EventDispatcher'); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | * @param string $eventName the name of the event to register for |
| 55 | 55 | * @param callable $listener the function or class method to receive the event information after dispatch |
| 56 | 56 | */ |
| 57 | - public function addListener($eventName, callable $listener){ |
|
| 58 | - $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | - if(! isset($this->listeners[$eventName])){ |
|
| 57 | + public function addListener($eventName, callable $listener) { |
|
| 58 | + $this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
| 59 | + if (!isset($this->listeners[$eventName])) { |
|
| 60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | 62 | } |
| 63 | - else{ |
|
| 63 | + else { |
|
| 64 | 64 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 65 | } |
| 66 | 66 | $this->listeners[$eventName][] = $listener; |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | * @param string $eventName the event name |
| 72 | 72 | * @param callable $listener the listener callback |
| 73 | 73 | */ |
| 74 | - public function removeListener($eventName, callable $listener){ |
|
| 75 | - $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | - if(isset($this->listeners[$eventName])){ |
|
| 74 | + public function removeListener($eventName, callable $listener) { |
|
| 75 | + $this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
| 76 | + if (isset($this->listeners[$eventName])) { |
|
| 77 | 77 | $this->logger->info('This event have the listeners, check if this listener exists'); |
| 78 | - if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | - $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 78 | + if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) { |
|
| 79 | + $this->logger->info('Found the listener at index [' . $index . '] remove it'); |
|
| 80 | 80 | unset($this->listeners[$eventName][$index]); |
| 81 | 81 | } |
| 82 | - else{ |
|
| 82 | + else { |
|
| 83 | 83 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | - else{ |
|
| 86 | + else { |
|
| 87 | 87 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | * remove all listeners for this event |
| 94 | 94 | * @param string $eventName the event name |
| 95 | 95 | */ |
| 96 | - public function removeAllListener($eventName = null){ |
|
| 97 | - $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | - if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 96 | + public function removeAllListener($eventName = null) { |
|
| 97 | + $this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']'); |
|
| 98 | + if ($eventName !== null && isset($this->listeners[$eventName])) { |
|
| 99 | 99 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 100 | unset($this->listeners[$eventName]); |
| 101 | 101 | } |
| 102 | - else{ |
|
| 102 | + else { |
|
| 103 | 103 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 104 | $this->listeners = array(); |
| 105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $eventName the event name |
| 111 | 111 | * @return array the listeners for this event or empty array if this event does not contain any listener |
| 112 | 112 | */ |
| 113 | - public function getListeners($eventName){ |
|
| 113 | + public function getListeners($eventName) { |
|
| 114 | 114 | return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | * @param mixed|object $event the event information |
| 120 | 120 | * @return void|object if event need return, will return the final EventInfo object. |
| 121 | 121 | */ |
| 122 | - public function dispatch($event){ |
|
| 123 | - if(! $event || !$event instanceof EventInfo){ |
|
| 122 | + public function dispatch($event) { |
|
| 123 | + if (!$event || !$event instanceof EventInfo) { |
|
| 124 | 124 | $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
| 125 | 125 | $event = new EventInfo((string) $event); |
| 126 | 126 | } |
| 127 | - $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | - if(isset($event->stop) && $event->stop){ |
|
| 127 | + $this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']'); |
|
| 128 | + if (isset($event->stop) && $event->stop) { |
|
| 129 | 129 | $this->logger->info('This event need stopped, no need call any listener'); |
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | - if($event->returnBack){ |
|
| 132 | + if ($event->returnBack) { |
|
| 133 | 133 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 134 | return $this->dispatchToListerners($event); |
| 135 | 135 | } |
| 136 | - else{ |
|
| 136 | + else { |
|
| 137 | 137 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 138 | $this->dispatchToListerners($event); |
| 139 | 139 | } |
@@ -144,38 +144,38 @@ discard block |
||
| 144 | 144 | * @param object EventInfo $event the event information |
| 145 | 145 | * @return void|object if event need return, will return the final EventInfo instance. |
| 146 | 146 | */ |
| 147 | - private function dispatchToListerners(EventInfo $event){ |
|
| 147 | + private function dispatchToListerners(EventInfo $event) { |
|
| 148 | 148 | $eBackup = $event; |
| 149 | 149 | $list = $this->getListeners($event->name); |
| 150 | - if(empty($list)){ |
|
| 151 | - $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | - if($event->returnBack){ |
|
| 150 | + if (empty($list)) { |
|
| 151 | + $this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.'); |
|
| 152 | + if ($event->returnBack) { |
|
| 153 | 153 | return $event; |
| 154 | 154 | } |
| 155 | 155 | return; |
| 156 | 156 | } |
| 157 | - else{ |
|
| 158 | - $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 157 | + else { |
|
| 158 | + $this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list)); |
|
| 159 | 159 | } |
| 160 | - foreach($list as $listener){ |
|
| 161 | - if($eBackup->returnBack){ |
|
| 160 | + foreach ($list as $listener) { |
|
| 161 | + if ($eBackup->returnBack) { |
|
| 162 | 162 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | - if($returnedEvent instanceof EventInfo){ |
|
| 163 | + if ($returnedEvent instanceof EventInfo) { |
|
| 164 | 164 | $event = $returnedEvent; |
| 165 | 165 | } |
| 166 | - else{ |
|
| 167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 166 | + else { |
|
| 167 | + show_error('This event [' . $event->name . '] need you return the event object after processing'); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | - else{ |
|
| 170 | + else { |
|
| 171 | 171 | call_user_func_array($listener, array($event)); |
| 172 | 172 | } |
| 173 | - if($event->stop){ |
|
| 173 | + if ($event->stop) { |
|
| 174 | 174 | break; |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | //only test for original event may be during the flow some listeners change this parameter |
| 178 | - if($eBackup->returnBack){ |
|
| 178 | + if ($eBackup->returnBack) { |
|
| 179 | 179 | return $event; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -59,8 +59,7 @@ discard block |
||
| 59 | 59 | if(! isset($this->listeners[$eventName])){ |
| 60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | - } |
|
| 63 | - else{ |
|
| 62 | + } else{ |
|
| 64 | 63 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 64 | } |
| 66 | 65 | $this->listeners[$eventName][] = $listener; |
@@ -78,12 +77,10 @@ discard block |
||
| 78 | 77 | if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
| 79 | 78 | $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
| 80 | 79 | unset($this->listeners[$eventName][$index]); |
| 81 | - } |
|
| 82 | - else{ |
|
| 80 | + } else{ |
|
| 83 | 81 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 82 | } |
| 85 | - } |
|
| 86 | - else{ |
|
| 83 | + } else{ |
|
| 87 | 84 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 85 | } |
| 89 | 86 | } |
@@ -98,8 +95,7 @@ discard block |
||
| 98 | 95 | if($eventName !== null && isset($this->listeners[$eventName])){ |
| 99 | 96 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 97 | unset($this->listeners[$eventName]); |
| 101 | - } |
|
| 102 | - else{ |
|
| 98 | + } else{ |
|
| 103 | 99 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 100 | $this->listeners = array(); |
| 105 | 101 | } |
@@ -132,8 +128,7 @@ discard block |
||
| 132 | 128 | if($event->returnBack){ |
| 133 | 129 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 130 | return $this->dispatchToListerners($event); |
| 135 | - } |
|
| 136 | - else{ |
|
| 131 | + } else{ |
|
| 137 | 132 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 133 | $this->dispatchToListerners($event); |
| 139 | 134 | } |
@@ -153,8 +148,7 @@ discard block |
||
| 153 | 148 | return $event; |
| 154 | 149 | } |
| 155 | 150 | return; |
| 156 | - } |
|
| 157 | - else{ |
|
| 151 | + } else{ |
|
| 158 | 152 | $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
| 159 | 153 | } |
| 160 | 154 | foreach($list as $listener){ |
@@ -162,12 +156,10 @@ discard block |
||
| 162 | 156 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | 157 | if($returnedEvent instanceof EventInfo){ |
| 164 | 158 | $event = $returnedEvent; |
| 165 | - } |
|
| 166 | - else{ |
|
| 159 | + } else{ |
|
| 167 | 160 | show_error('This event [' .$event->name. '] need you return the event object after processing'); |
| 168 | 161 | } |
| 169 | - } |
|
| 170 | - else{ |
|
| 162 | + } else{ |
|
| 171 | 163 | call_user_func_array($listener, array($event)); |
| 172 | 164 | } |
| 173 | 165 | if($event->stop){ |
@@ -1,182 +1,182 @@ |
||
| 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 | - /** |
|
| 28 | - * This class represent the event dispatcher management, permit to record the listener and |
|
| 29 | - * also to dispatch the event |
|
| 30 | - */ |
|
| 27 | + /** |
|
| 28 | + * This class represent the event dispatcher management, permit to record the listener and |
|
| 29 | + * also to dispatch the event |
|
| 30 | + */ |
|
| 31 | 31 | |
| 32 | - class EventDispatcher{ |
|
| 32 | + class EventDispatcher{ |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The list of the registered listeners |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private $listeners = array(); |
|
| 34 | + /** |
|
| 35 | + * The list of the registered listeners |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private $listeners = array(); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The logger instance |
|
| 43 | - * @var Log |
|
| 44 | - */ |
|
| 45 | - private $logger; |
|
| 41 | + /** |
|
| 42 | + * The logger instance |
|
| 43 | + * @var Log |
|
| 44 | + */ |
|
| 45 | + private $logger; |
|
| 46 | 46 | |
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | - $this->logger->setLogger('Library::EventDispatcher'); |
|
| 50 | - } |
|
| 47 | + public function __construct(){ |
|
| 48 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | + $this->logger->setLogger('Library::EventDispatcher'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Register new listener |
|
| 54 | - * @param string $eventName the name of the event to register for |
|
| 55 | - * @param callable $listener the function or class method to receive the event information after dispatch |
|
| 56 | - */ |
|
| 57 | - public function addListener($eventName, callable $listener){ |
|
| 58 | - $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | - if(! isset($this->listeners[$eventName])){ |
|
| 60 | - $this->logger->info('This event does not have the registered event listener before, adding new one'); |
|
| 61 | - $this->listeners[$eventName] = array(); |
|
| 62 | - } |
|
| 63 | - else{ |
|
| 64 | - $this->logger->info('This event already have the registered listener, add this listener to the list'); |
|
| 65 | - } |
|
| 66 | - $this->listeners[$eventName][] = $listener; |
|
| 67 | - } |
|
| 52 | + /** |
|
| 53 | + * Register new listener |
|
| 54 | + * @param string $eventName the name of the event to register for |
|
| 55 | + * @param callable $listener the function or class method to receive the event information after dispatch |
|
| 56 | + */ |
|
| 57 | + public function addListener($eventName, callable $listener){ |
|
| 58 | + $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | + if(! isset($this->listeners[$eventName])){ |
|
| 60 | + $this->logger->info('This event does not have the registered event listener before, adding new one'); |
|
| 61 | + $this->listeners[$eventName] = array(); |
|
| 62 | + } |
|
| 63 | + else{ |
|
| 64 | + $this->logger->info('This event already have the registered listener, add this listener to the list'); |
|
| 65 | + } |
|
| 66 | + $this->listeners[$eventName][] = $listener; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Remove the event listener from list |
|
| 71 | - * @param string $eventName the event name |
|
| 72 | - * @param callable $listener the listener callback |
|
| 73 | - */ |
|
| 74 | - public function removeListener($eventName, callable $listener){ |
|
| 75 | - $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | - if(isset($this->listeners[$eventName])){ |
|
| 77 | - $this->logger->info('This event have the listeners, check if this listener exists'); |
|
| 78 | - if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | - $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 80 | - unset($this->listeners[$eventName][$index]); |
|
| 81 | - } |
|
| 82 | - else{ |
|
| 83 | - $this->logger->info('Cannot found this listener in the event listener list'); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - else{ |
|
| 87 | - $this->logger->info('This event does not have this listener ignore remove'); |
|
| 88 | - } |
|
| 89 | - } |
|
| 69 | + /** |
|
| 70 | + * Remove the event listener from list |
|
| 71 | + * @param string $eventName the event name |
|
| 72 | + * @param callable $listener the listener callback |
|
| 73 | + */ |
|
| 74 | + public function removeListener($eventName, callable $listener){ |
|
| 75 | + $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | + if(isset($this->listeners[$eventName])){ |
|
| 77 | + $this->logger->info('This event have the listeners, check if this listener exists'); |
|
| 78 | + if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | + $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 80 | + unset($this->listeners[$eventName][$index]); |
|
| 81 | + } |
|
| 82 | + else{ |
|
| 83 | + $this->logger->info('Cannot found this listener in the event listener list'); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + else{ |
|
| 87 | + $this->logger->info('This event does not have this listener ignore remove'); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Remove all the event listener. If event name is null will remove all listeners, else will just |
|
| 93 | - * remove all listeners for this event |
|
| 94 | - * @param string $eventName the event name |
|
| 95 | - */ |
|
| 96 | - public function removeAllListener($eventName = null){ |
|
| 97 | - $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | - if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 99 | - $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
|
| 100 | - unset($this->listeners[$eventName]); |
|
| 101 | - } |
|
| 102 | - else{ |
|
| 103 | - $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
|
| 104 | - $this->listeners = array(); |
|
| 105 | - } |
|
| 106 | - } |
|
| 91 | + /** |
|
| 92 | + * Remove all the event listener. If event name is null will remove all listeners, else will just |
|
| 93 | + * remove all listeners for this event |
|
| 94 | + * @param string $eventName the event name |
|
| 95 | + */ |
|
| 96 | + public function removeAllListener($eventName = null){ |
|
| 97 | + $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | + if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 99 | + $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
|
| 100 | + unset($this->listeners[$eventName]); |
|
| 101 | + } |
|
| 102 | + else{ |
|
| 103 | + $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
|
| 104 | + $this->listeners = array(); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Get the list of listener for this event |
|
| 110 | - * @param string $eventName the event name |
|
| 111 | - * @return array the listeners for this event or empty array if this event does not contain any listener |
|
| 112 | - */ |
|
| 113 | - public function getListeners($eventName){ |
|
| 114 | - return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * Get the list of listener for this event |
|
| 110 | + * @param string $eventName the event name |
|
| 111 | + * @return array the listeners for this event or empty array if this event does not contain any listener |
|
| 112 | + */ |
|
| 113 | + public function getListeners($eventName){ |
|
| 114 | + return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Dispatch the event to the registered listeners. |
|
| 119 | - * @param mixed|object $event the event information |
|
| 120 | - * @return void|object if event need return, will return the final EventInfo object. |
|
| 121 | - */ |
|
| 122 | - public function dispatch($event){ |
|
| 123 | - if(! $event || !$event instanceof EventInfo){ |
|
| 124 | - $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
|
| 125 | - $event = new EventInfo((string) $event); |
|
| 126 | - } |
|
| 127 | - $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | - if(isset($event->stop) && $event->stop){ |
|
| 129 | - $this->logger->info('This event need stopped, no need call any listener'); |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - if($event->returnBack){ |
|
| 133 | - $this->logger->info('This event need return back, return the result for future use'); |
|
| 134 | - return $this->dispatchToListerners($event); |
|
| 135 | - } |
|
| 136 | - else{ |
|
| 137 | - $this->logger->info('This event no need return back the result, just dispatch it'); |
|
| 138 | - $this->dispatchToListerners($event); |
|
| 139 | - } |
|
| 140 | - } |
|
| 117 | + /** |
|
| 118 | + * Dispatch the event to the registered listeners. |
|
| 119 | + * @param mixed|object $event the event information |
|
| 120 | + * @return void|object if event need return, will return the final EventInfo object. |
|
| 121 | + */ |
|
| 122 | + public function dispatch($event){ |
|
| 123 | + if(! $event || !$event instanceof EventInfo){ |
|
| 124 | + $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
|
| 125 | + $event = new EventInfo((string) $event); |
|
| 126 | + } |
|
| 127 | + $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | + if(isset($event->stop) && $event->stop){ |
|
| 129 | + $this->logger->info('This event need stopped, no need call any listener'); |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + if($event->returnBack){ |
|
| 133 | + $this->logger->info('This event need return back, return the result for future use'); |
|
| 134 | + return $this->dispatchToListerners($event); |
|
| 135 | + } |
|
| 136 | + else{ |
|
| 137 | + $this->logger->info('This event no need return back the result, just dispatch it'); |
|
| 138 | + $this->dispatchToListerners($event); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Dispatch the event to the registered listeners. |
|
| 144 | - * @param object EventInfo $event the event information |
|
| 145 | - * @return void|object if event need return, will return the final EventInfo instance. |
|
| 146 | - */ |
|
| 147 | - private function dispatchToListerners(EventInfo $event){ |
|
| 148 | - $eBackup = $event; |
|
| 149 | - $list = $this->getListeners($event->name); |
|
| 150 | - if(empty($list)){ |
|
| 151 | - $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | - if($event->returnBack){ |
|
| 153 | - return $event; |
|
| 154 | - } |
|
| 155 | - return; |
|
| 156 | - } |
|
| 157 | - else{ |
|
| 158 | - $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 159 | - } |
|
| 160 | - foreach($list as $listener){ |
|
| 161 | - if($eBackup->returnBack){ |
|
| 162 | - $returnedEvent = call_user_func_array($listener, array($event)); |
|
| 163 | - if($returnedEvent instanceof EventInfo){ |
|
| 164 | - $event = $returnedEvent; |
|
| 165 | - } |
|
| 166 | - else{ |
|
| 167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - else{ |
|
| 171 | - call_user_func_array($listener, array($event)); |
|
| 172 | - } |
|
| 173 | - if($event->stop){ |
|
| 174 | - break; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - //only test for original event may be during the flow some listeners change this parameter |
|
| 178 | - if($eBackup->returnBack){ |
|
| 179 | - return $event; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 142 | + /** |
|
| 143 | + * Dispatch the event to the registered listeners. |
|
| 144 | + * @param object EventInfo $event the event information |
|
| 145 | + * @return void|object if event need return, will return the final EventInfo instance. |
|
| 146 | + */ |
|
| 147 | + private function dispatchToListerners(EventInfo $event){ |
|
| 148 | + $eBackup = $event; |
|
| 149 | + $list = $this->getListeners($event->name); |
|
| 150 | + if(empty($list)){ |
|
| 151 | + $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | + if($event->returnBack){ |
|
| 153 | + return $event; |
|
| 154 | + } |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | + else{ |
|
| 158 | + $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 159 | + } |
|
| 160 | + foreach($list as $listener){ |
|
| 161 | + if($eBackup->returnBack){ |
|
| 162 | + $returnedEvent = call_user_func_array($listener, array($event)); |
|
| 163 | + if($returnedEvent instanceof EventInfo){ |
|
| 164 | + $event = $returnedEvent; |
|
| 165 | + } |
|
| 166 | + else{ |
|
| 167 | + show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + else{ |
|
| 171 | + call_user_func_array($listener, array($event)); |
|
| 172 | + } |
|
| 173 | + if($event->stop){ |
|
| 174 | + break; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + //only test for original event may be during the flow some listeners change this parameter |
|
| 178 | + if($eBackup->returnBack){ |
|
| 179 | + return $event; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
@@ -115,8 +115,7 @@ |
||
| 115 | 115 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 116 | 116 | if($logger !== null){ |
| 117 | 117 | $this->logger = $logger; |
| 118 | - } |
|
| 119 | - else{ |
|
| 118 | + } else{ |
|
| 120 | 119 | $this->logger =& class_loader('Log', 'classes'); |
| 121 | 120 | $this->logger->setLogger('MainController'); |
| 122 | 121 | } |
@@ -1,146 +1,146 @@ |
||
| 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 Controller{ |
|
| 27 | + class Controller{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The name of the module if this controller belong to an module |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - public $moduleName = null; |
|
| 29 | + /** |
|
| 30 | + * The name of the module if this controller belong to an module |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + public $moduleName = null; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The singleton of the super object |
|
| 37 | - * @var Controller |
|
| 38 | - */ |
|
| 39 | - private static $instance; |
|
| 35 | + /** |
|
| 36 | + * The singleton of the super object |
|
| 37 | + * @var Controller |
|
| 38 | + */ |
|
| 39 | + private static $instance; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The logger instance |
|
| 43 | - * @var Log |
|
| 44 | - */ |
|
| 45 | - protected $logger; |
|
| 41 | + /** |
|
| 42 | + * The logger instance |
|
| 43 | + * @var Log |
|
| 44 | + */ |
|
| 45 | + protected $logger; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class constructor |
|
| 49 | - * @param object $logger the Log instance to use if is null will create one |
|
| 50 | - */ |
|
| 51 | - public function __construct(Log $logger = null){ |
|
| 52 | - //setting the Log instance |
|
| 53 | - $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 47 | + /** |
|
| 48 | + * Class constructor |
|
| 49 | + * @param object $logger the Log instance to use if is null will create one |
|
| 50 | + */ |
|
| 51 | + public function __construct(Log $logger = null){ |
|
| 52 | + //setting the Log instance |
|
| 53 | + $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 54 | 54 | |
| 55 | - //instance of the super object |
|
| 56 | - self::$instance = & $this; |
|
| 55 | + //instance of the super object |
|
| 56 | + self::$instance = & $this; |
|
| 57 | 57 | |
| 58 | - //Load the resources loaded during the application bootstrap |
|
| 59 | - $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 60 | - foreach (class_loaded() as $var => $class){ |
|
| 61 | - $this->$var =& class_loader($class); |
|
| 62 | - } |
|
| 58 | + //Load the resources loaded during the application bootstrap |
|
| 59 | + $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 60 | + foreach (class_loaded() as $var => $class){ |
|
| 61 | + $this->$var =& class_loader($class); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //set module using the router |
|
| 65 | - $this->setModuleNameFromRouter(); |
|
| 64 | + //set module using the router |
|
| 65 | + $this->setModuleNameFromRouter(); |
|
| 66 | 66 | |
| 67 | - //load the required resources |
|
| 68 | - $this->loadRequiredResources(); |
|
| 67 | + //load the required resources |
|
| 68 | + $this->loadRequiredResources(); |
|
| 69 | 69 | |
| 70 | - //set the cache using the configuration |
|
| 71 | - $this->setCacheFromParamOrConfig(null); |
|
| 70 | + //set the cache using the configuration |
|
| 71 | + $this->setCacheFromParamOrConfig(null); |
|
| 72 | 72 | |
| 73 | - //set application session configuration |
|
| 74 | - $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | - set_session_config(); |
|
| 73 | + //set application session configuration |
|
| 74 | + $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | + set_session_config(); |
|
| 76 | 76 | |
| 77 | - //dispatch the loaded instance of super controller event |
|
| 78 | - $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | - } |
|
| 77 | + //dispatch the loaded instance of super controller event |
|
| 78 | + $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * This is a very useful method it's used to get the super object instance |
|
| 84 | - * @return Controller the super object instance |
|
| 85 | - */ |
|
| 86 | - public static function &get_instance(){ |
|
| 87 | - return self::$instance; |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * This is a very useful method it's used to get the super object instance |
|
| 84 | + * @return Controller the super object instance |
|
| 85 | + */ |
|
| 86 | + public static function &get_instance(){ |
|
| 87 | + return self::$instance; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * This method is used to set the module name |
|
| 92 | - */ |
|
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 94 | - //set the module using the router instance |
|
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | - $this->moduleName = $this->router->getModule(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * This method is used to set the module name |
|
| 92 | + */ |
|
| 93 | + protected function setModuleNameFromRouter(){ |
|
| 94 | + //set the module using the router instance |
|
| 95 | + if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | + $this->moduleName = $this->router->getModule(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Set the cache using the argument otherwise will use the configuration |
|
| 102 | - * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | - */ |
|
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | - $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | - //set cache handler instance |
|
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 109 | - $this->cache = $cache; |
|
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | - $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | - unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 100 | + /** |
|
| 101 | + * Set the cache using the argument otherwise will use the configuration |
|
| 102 | + * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | + */ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | + $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | + //set cache handler instance |
|
| 107 | + if(get_config('cache_enable', false)){ |
|
| 108 | + if ($cache !== null){ |
|
| 109 | + $this->cache = $cache; |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | + $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | + unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Set the Log instance using argument or create new instance |
|
| 119 | - * @param object $logger the Log instance if not null |
|
| 120 | - */ |
|
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 123 | - $this->logger = $logger; |
|
| 124 | - } |
|
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | - $this->logger->setLogger('MainController'); |
|
| 128 | - } |
|
| 129 | - } |
|
| 117 | + /** |
|
| 118 | + * Set the Log instance using argument or create new instance |
|
| 119 | + * @param object $logger the Log instance if not null |
|
| 120 | + */ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | + if($logger !== null){ |
|
| 123 | + $this->logger = $logger; |
|
| 124 | + } |
|
| 125 | + else{ |
|
| 126 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | + $this->logger->setLogger('MainController'); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * This method is used to load the required resources for framework to work |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - private function loadRequiredResources(){ |
|
| 136 | - $this->logger->debug('Loading the required classes into super instance'); |
|
| 137 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | - $this->request =& class_loader('Request', 'classes'); |
|
| 141 | - //dispatch the request instance created event |
|
| 142 | - $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | - } |
|
| 131 | + /** |
|
| 132 | + * This method is used to load the required resources for framework to work |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + private function loadRequiredResources(){ |
|
| 136 | + $this->logger->debug('Loading the required classes into super instance'); |
|
| 137 | + $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | + $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | + $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | + $this->request =& class_loader('Request', 'classes'); |
|
| 141 | + //dispatch the request instance created event |
|
| 142 | + $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | + $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - } |
|
| 146 | + } |
|
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Controller{ |
|
| 27 | + class Controller { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The name of the module if this controller belong to an module |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * Class constructor |
| 49 | 49 | * @param object $logger the Log instance to use if is null will create one |
| 50 | 50 | */ |
| 51 | - public function __construct(Log $logger = null){ |
|
| 51 | + public function __construct(Log $logger = null) { |
|
| 52 | 52 | //setting the Log instance |
| 53 | 53 | $this->setLoggerFromParamOrCreateNewInstance($logger); |
| 54 | 54 | |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | //Load the resources loaded during the application bootstrap |
| 59 | 59 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 60 | - foreach (class_loaded() as $var => $class){ |
|
| 61 | - $this->$var =& class_loader($class); |
|
| 60 | + foreach (class_loaded() as $var => $class) { |
|
| 61 | + $this->$var = & class_loader($class); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | //set module using the router |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * This method is used to set the module name |
| 92 | 92 | */ |
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 93 | + protected function setModuleNameFromRouter() { |
|
| 94 | 94 | //set the module using the router instance |
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 95 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 96 | 96 | $this->moduleName = $this->router->getModule(); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * Set the cache using the argument otherwise will use the configuration |
| 102 | 102 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
| 103 | 103 | */ |
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
| 105 | 105 | $this->logger->debug('Setting the cache handler instance'); |
| 106 | 106 | //set cache handler instance |
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 107 | + if (get_config('cache_enable', false)) { |
|
| 108 | + if ($cache !== null) { |
|
| 109 | 109 | $this->cache = $cache; |
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 111 | 111 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 112 | 112 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 113 | 113 | } |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | * Set the Log instance using argument or create new instance |
| 119 | 119 | * @param object $logger the Log instance if not null |
| 120 | 120 | */ |
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 122 | + if ($logger !== null) { |
|
| 123 | 123 | $this->logger = $logger; |
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 125 | + else { |
|
| 126 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 127 | 127 | $this->logger->setLogger('MainController'); |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * This method is used to load the required resources for framework to work |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - private function loadRequiredResources(){ |
|
| 135 | + private function loadRequiredResources() { |
|
| 136 | 136 | $this->logger->debug('Loading the required classes into super instance'); |
| 137 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | - $this->request =& class_loader('Request', 'classes'); |
|
| 137 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 138 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 139 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 140 | + $this->request = & class_loader('Request', 'classes'); |
|
| 141 | 141 | //dispatch the request instance created event |
| 142 | 142 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 143 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 28 | + public function testDefaultValue() { |
|
| 29 | 29 | $e = new EventInfo('foo'); |
| 30 | 30 | $this->assertSame($e->name, 'foo'); |
| 31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->assertFalse($e->stop); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function testPayloadValueIsSet(){ |
|
| 36 | + public function testPayloadValueIsSet() { |
|
| 37 | 37 | $e = new EventInfo('foo', array('bar')); |
| 38 | 38 | $this->assertSame($e->name, 'foo'); |
| 39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->assertFalse($e->stop); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 44 | + public function testReturnBackValueIsSetToTrue() { |
|
| 45 | 45 | $e = new EventInfo('foo', array('bar'), true); |
| 46 | 46 | $this->assertSame($e->name, 'foo'); |
| 47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->assertFalse($e->stop); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 52 | + public function testStopValueIsSetToTue() { |
|
| 53 | 53 | $e = new EventInfo('foo', array('bar'), true, true); |
| 54 | 54 | $this->assertSame($e->name, 'foo'); |
| 55 | 55 | $this->assertSame($e->payload, array('bar')); |
@@ -1,59 +1,59 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class EventInfoTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class EventInfoTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 29 | - $e = new EventInfo('foo'); |
|
| 30 | - $this->assertSame($e->name, 'foo'); |
|
| 31 | - $this->assertSame($e->payload, array()); |
|
| 32 | - $this->assertFalse($e->returnBack); |
|
| 33 | - $this->assertFalse($e->stop); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function testPayloadValueIsSet(){ |
|
| 37 | - $e = new EventInfo('foo', array('bar')); |
|
| 38 | - $this->assertSame($e->name, 'foo'); |
|
| 39 | - $this->assertSame($e->payload, array('bar')); |
|
| 40 | - $this->assertFalse($e->returnBack); |
|
| 41 | - $this->assertFalse($e->stop); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 45 | - $e = new EventInfo('foo', array('bar'), true); |
|
| 46 | - $this->assertSame($e->name, 'foo'); |
|
| 47 | - $this->assertSame($e->payload, array('bar')); |
|
| 48 | - $this->assertTrue($e->returnBack); |
|
| 49 | - $this->assertFalse($e->stop); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 53 | - $e = new EventInfo('foo', array('bar'), true, true); |
|
| 54 | - $this->assertSame($e->name, 'foo'); |
|
| 55 | - $this->assertSame($e->payload, array('bar')); |
|
| 56 | - $this->assertTrue($e->returnBack); |
|
| 57 | - $this->assertTrue($e->stop); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | 28 | \ No newline at end of file |
| 29 | + public function testDefaultValue(){ |
|
| 30 | + $e = new EventInfo('foo'); |
|
| 31 | + $this->assertSame($e->name, 'foo'); |
|
| 32 | + $this->assertSame($e->payload, array()); |
|
| 33 | + $this->assertFalse($e->returnBack); |
|
| 34 | + $this->assertFalse($e->stop); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function testPayloadValueIsSet(){ |
|
| 38 | + $e = new EventInfo('foo', array('bar')); |
|
| 39 | + $this->assertSame($e->name, 'foo'); |
|
| 40 | + $this->assertSame($e->payload, array('bar')); |
|
| 41 | + $this->assertFalse($e->returnBack); |
|
| 42 | + $this->assertFalse($e->stop); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function testReturnBackValueIsSetToTrue(){ |
|
| 46 | + $e = new EventInfo('foo', array('bar'), true); |
|
| 47 | + $this->assertSame($e->name, 'foo'); |
|
| 48 | + $this->assertSame($e->payload, array('bar')); |
|
| 49 | + $this->assertTrue($e->returnBack); |
|
| 50 | + $this->assertFalse($e->stop); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function testStopValueIsSetToTue(){ |
|
| 54 | + $e = new EventInfo('foo', array('bar'), true, true); |
|
| 55 | + $this->assertSame($e->name, 'foo'); |
|
| 56 | + $this->assertSame($e->payload, array('bar')); |
|
| 57 | + $this->assertTrue($e->returnBack); |
|
| 58 | + $this->assertTrue($e->stop); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
| 3 | 3 | |
| 4 | 4 | protected $_table = 'ses'; |
| 5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 17 | + public function deleteByTime($time) { |
|
| 18 | 18 | $this->getQueryBuilder()->from($this->_table) |
| 19 | 19 | ->where('s_time', '<', $time); |
| 20 | 20 | $this->_database->delete(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 24 | + public function getKeyValue() { |
|
| 25 | 25 | $user_id = 0; |
| 26 | 26 | return $user_id; |
| 27 | 27 | } |
@@ -1,28 +1,28 @@ |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel{ |
|
| 3 | 3 | |
| 4 | - protected $_table = 'ses'; |
|
| 5 | - protected $primary_key = 's_id'; |
|
| 4 | + protected $_table = 'ses'; |
|
| 5 | + protected $primary_key = 's_id'; |
|
| 6 | 6 | |
| 7 | - protected $sessionTableColumns = array( |
|
| 8 | - 'sid' => 's_id', //VARCHAR(255) |
|
| 9 | - 'sdata' => 's_data', //TEXT |
|
| 10 | - 'stime' => 's_time', //unix timestamp (INT|BIGINT) |
|
| 11 | - 'shost' => 's_host', //VARCHAR(255) |
|
| 12 | - 'sip' => 's_ip', //VARCHAR(255) |
|
| 13 | - 'sbrowser' => 's_browser', //VARCHAR(255) |
|
| 14 | - 'skey' => 'test_id' //VARCHAR(255) |
|
| 15 | - ); |
|
| 7 | + protected $sessionTableColumns = array( |
|
| 8 | + 'sid' => 's_id', //VARCHAR(255) |
|
| 9 | + 'sdata' => 's_data', //TEXT |
|
| 10 | + 'stime' => 's_time', //unix timestamp (INT|BIGINT) |
|
| 11 | + 'shost' => 's_host', //VARCHAR(255) |
|
| 12 | + 'sip' => 's_ip', //VARCHAR(255) |
|
| 13 | + 'sbrowser' => 's_browser', //VARCHAR(255) |
|
| 14 | + 'skey' => 'test_id' //VARCHAR(255) |
|
| 15 | + ); |
|
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 18 | - $this->getQueryBuilder()->from($this->_table) |
|
| 19 | - ->where('s_time', '<', $time); |
|
| 20 | - $this->_database->delete(); |
|
| 21 | - } |
|
| 17 | + public function deleteByTime($time){ |
|
| 18 | + $this->getQueryBuilder()->from($this->_table) |
|
| 19 | + ->where('s_time', '<', $time); |
|
| 20 | + $this->_database->delete(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 25 | - $user_id = 0; |
|
| 26 | - return $user_id; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | 24 | \ No newline at end of file |
| 25 | + public function getKeyValue(){ |
|
| 26 | + $user_id = 0; |
|
| 27 | + return $user_id; |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //Autoload function |
| 3 | - function tests_autoload($class){ |
|
| 3 | + function tests_autoload($class) { |
|
| 4 | 4 | $classesMap = array( |
| 5 | 5 | //Caches |
| 6 | 6 | 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
| 41 | 41 | 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
| 42 | 42 | ); |
| 43 | - if(isset($classesMap[$class])){ |
|
| 44 | - if(file_exists($classesMap[$class])){ |
|
| 43 | + if (isset($classesMap[$class])) { |
|
| 44 | + if (file_exists($classesMap[$class])) { |
|
| 45 | 45 | require_once $classesMap[$class]; |
| 46 | 46 | } |
| 47 | - else{ |
|
| 47 | + else { |
|
| 48 | 48 | echo 'File for class ' . $class . ' not found'; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -43,8 +43,7 @@ |
||
| 43 | 43 | if(isset($classesMap[$class])){ |
| 44 | 44 | if(file_exists($classesMap[$class])){ |
| 45 | 45 | require_once $classesMap[$class]; |
| 46 | - } |
|
| 47 | - else{ |
|
| 46 | + } else{ |
|
| 48 | 47 | echo 'File for class ' . $class . ' not found'; |
| 49 | 48 | } |
| 50 | 49 | } |
@@ -1,54 +1,54 @@ |
||
| 1 | 1 | <?php |
| 2 | - //Autoload function |
|
| 3 | - function tests_autoload($class){ |
|
| 4 | - $classesMap = array( |
|
| 5 | - //Caches |
|
| 6 | - 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
|
| 7 | - 'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php', |
|
| 8 | - 'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php', |
|
| 9 | - //models |
|
| 10 | - 'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php', |
|
| 11 | - 'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php', |
|
| 12 | - //Core classes |
|
| 13 | - 'Config' => CORE_CLASSES_PATH . 'Config.php', |
|
| 14 | - 'Controller' => CORE_CLASSES_PATH . 'Controller.php', |
|
| 15 | - 'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php', |
|
| 16 | - 'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php', |
|
| 17 | - 'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php', |
|
| 18 | - 'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php', |
|
| 19 | - 'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php', |
|
| 20 | - 'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php', |
|
| 21 | - 'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php', |
|
| 22 | - 'Lang' => CORE_CLASSES_PATH . 'Lang.php', |
|
| 23 | - 'Loader' => CORE_CLASSES_PATH . 'Loader.php', |
|
| 24 | - 'Log' => CORE_CLASSES_PATH . 'Log.php', |
|
| 25 | - 'Module' => CORE_CLASSES_PATH . 'Module.php', |
|
| 26 | - 'Request' => CORE_CLASSES_PATH . 'Request.php', |
|
| 27 | - 'Response' => CORE_CLASSES_PATH . 'Response.php', |
|
| 28 | - 'Router' => CORE_CLASSES_PATH . 'Router.php', |
|
| 29 | - 'Security' => CORE_CLASSES_PATH . 'Security.php', |
|
| 30 | - 'Session' => CORE_CLASSES_PATH . 'Session.php', |
|
| 31 | - 'Url' => CORE_CLASSES_PATH . 'Url.php', |
|
| 32 | - //Core libraries |
|
| 33 | - 'Assets' => CORE_LIBRARY_PATH . 'Assets.php', |
|
| 34 | - 'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php', |
|
| 35 | - 'Browser' => CORE_LIBRARY_PATH . 'Browser.php', |
|
| 36 | - 'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php', |
|
| 37 | - 'Email' => CORE_LIBRARY_PATH . 'Email.php', |
|
| 38 | - 'Form' => CORE_LIBRARY_PATH . 'Form.php', |
|
| 39 | - 'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php', |
|
| 40 | - 'Html' => CORE_LIBRARY_PATH . 'Html.php', |
|
| 41 | - 'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php', |
|
| 42 | - 'PDF' => CORE_LIBRARY_PATH . 'PDF.php', |
|
| 43 | - 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
|
| 44 | - 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
|
| 45 | - ); |
|
| 46 | - if(isset($classesMap[$class])){ |
|
| 47 | - if(file_exists($classesMap[$class])){ |
|
| 48 | - require_once $classesMap[$class]; |
|
| 49 | - } |
|
| 50 | - else{ |
|
| 51 | - echo 'File for class ' . $class . ' not found'; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | 2 | \ No newline at end of file |
| 3 | + //Autoload function |
|
| 4 | + function tests_autoload($class){ |
|
| 5 | + $classesMap = array( |
|
| 6 | + //Caches |
|
| 7 | + 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
|
| 8 | + 'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php', |
|
| 9 | + 'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php', |
|
| 10 | + //models |
|
| 11 | + 'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php', |
|
| 12 | + 'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php', |
|
| 13 | + //Core classes |
|
| 14 | + 'Config' => CORE_CLASSES_PATH . 'Config.php', |
|
| 15 | + 'Controller' => CORE_CLASSES_PATH . 'Controller.php', |
|
| 16 | + 'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php', |
|
| 17 | + 'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php', |
|
| 18 | + 'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php', |
|
| 19 | + 'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php', |
|
| 20 | + 'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php', |
|
| 21 | + 'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php', |
|
| 22 | + 'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php', |
|
| 23 | + 'Lang' => CORE_CLASSES_PATH . 'Lang.php', |
|
| 24 | + 'Loader' => CORE_CLASSES_PATH . 'Loader.php', |
|
| 25 | + 'Log' => CORE_CLASSES_PATH . 'Log.php', |
|
| 26 | + 'Module' => CORE_CLASSES_PATH . 'Module.php', |
|
| 27 | + 'Request' => CORE_CLASSES_PATH . 'Request.php', |
|
| 28 | + 'Response' => CORE_CLASSES_PATH . 'Response.php', |
|
| 29 | + 'Router' => CORE_CLASSES_PATH . 'Router.php', |
|
| 30 | + 'Security' => CORE_CLASSES_PATH . 'Security.php', |
|
| 31 | + 'Session' => CORE_CLASSES_PATH . 'Session.php', |
|
| 32 | + 'Url' => CORE_CLASSES_PATH . 'Url.php', |
|
| 33 | + //Core libraries |
|
| 34 | + 'Assets' => CORE_LIBRARY_PATH . 'Assets.php', |
|
| 35 | + 'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php', |
|
| 36 | + 'Browser' => CORE_LIBRARY_PATH . 'Browser.php', |
|
| 37 | + 'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php', |
|
| 38 | + 'Email' => CORE_LIBRARY_PATH . 'Email.php', |
|
| 39 | + 'Form' => CORE_LIBRARY_PATH . 'Form.php', |
|
| 40 | + 'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php', |
|
| 41 | + 'Html' => CORE_LIBRARY_PATH . 'Html.php', |
|
| 42 | + 'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php', |
|
| 43 | + 'PDF' => CORE_LIBRARY_PATH . 'PDF.php', |
|
| 44 | + 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
|
| 45 | + 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
|
| 46 | + ); |
|
| 47 | + if(isset($classesMap[$class])){ |
|
| 48 | + if(file_exists($classesMap[$class])){ |
|
| 49 | + require_once $classesMap[$class]; |
|
| 50 | + } |
|
| 51 | + else{ |
|
| 52 | + echo 'File for class ' . $class . ' not found'; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | \ No newline at end of file |