[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache\driver; 15 16 abstract class base implements \phpbb\cache\driver\driver_interface 17 { 18 var $vars = array(); 19 var $is_modified = false; 20 21 var $sql_rowset = array(); 22 var $sql_row_pointer = array(); 23 var $cache_dir = ''; 24 25 /** 26 * {@inheritDoc} 27 */ 28 function purge() 29 { 30 // Purge all phpbb cache files 31 try 32 { 33 $iterator = new \DirectoryIterator($this->cache_dir); 34 } 35 catch (\Exception $e) 36 { 37 return; 38 } 39 40 foreach ($iterator as $fileInfo) 41 { 42 if ($fileInfo->isDot()) 43 { 44 continue; 45 } 46 $filename = $fileInfo->getFilename(); 47 if ($fileInfo->isDir()) 48 { 49 $this->remove_dir($fileInfo->getPathname()); 50 } 51 else if (strpos($filename, 'container_') === 0 || 52 strpos($filename, 'autoload_') === 0 || 53 strpos($filename, 'url_matcher') === 0 || 54 strpos($filename, 'url_generator') === 0 || 55 strpos($filename, 'sql_') === 0 || 56 strpos($filename, 'data_') === 0) 57 { 58 $this->remove_file($fileInfo->getPathname()); 59 } 60 } 61 62 unset($this->vars); 63 unset($this->sql_rowset); 64 unset($this->sql_row_pointer); 65 66 if (function_exists('opcache_reset')) 67 { 68 @opcache_reset(); 69 } 70 71 $this->vars = array(); 72 $this->sql_rowset = array(); 73 $this->sql_row_pointer = array(); 74 75 $this->is_modified = false; 76 } 77 78 /** 79 * {@inheritDoc} 80 */ 81 function unload() 82 { 83 $this->save(); 84 unset($this->vars); 85 unset($this->sql_rowset); 86 unset($this->sql_row_pointer); 87 88 $this->vars = array(); 89 $this->sql_rowset = array(); 90 $this->sql_row_pointer = array(); 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 function sql_load($query) 97 { 98 // Remove extra spaces and tabs 99 $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); 100 $query_id = md5($query); 101 102 if (($result = $this->_read('sql_' . $query_id)) === false) 103 { 104 return false; 105 } 106 107 $this->sql_rowset[$query_id] = $result; 108 $this->sql_row_pointer[$query_id] = 0; 109 110 return $query_id; 111 } 112 113 /** 114 * {@inheritDoc} 115 */ 116 function sql_exists($query_id) 117 { 118 $query_id = $this->clean_query_id($query_id); 119 return isset($this->sql_rowset[$query_id]); 120 } 121 122 /** 123 * {@inheritDoc} 124 */ 125 function sql_fetchrow($query_id) 126 { 127 $query_id = $this->clean_query_id($query_id); 128 if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id])) 129 { 130 return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; 131 } 132 133 return false; 134 } 135 136 /** 137 * {@inheritDoc} 138 */ 139 function sql_fetchfield($query_id, $field) 140 { 141 $query_id = $this->clean_query_id($query_id); 142 if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id])) 143 { 144 return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false; 145 } 146 147 return false; 148 } 149 150 /** 151 * {@inheritDoc} 152 */ 153 function sql_rowseek($rownum, $query_id) 154 { 155 $query_id = $this->clean_query_id($query_id); 156 if ($rownum >= count($this->sql_rowset[$query_id])) 157 { 158 return false; 159 } 160 161 $this->sql_row_pointer[$query_id] = $rownum; 162 return true; 163 } 164 165 /** 166 * {@inheritDoc} 167 */ 168 function sql_freeresult($query_id) 169 { 170 $query_id = $this->clean_query_id($query_id); 171 if (!isset($this->sql_rowset[$query_id])) 172 { 173 return false; 174 } 175 176 unset($this->sql_rowset[$query_id]); 177 unset($this->sql_row_pointer[$query_id]); 178 179 return true; 180 } 181 182 /** 183 * Removes/unlinks file 184 * 185 * @param string $filename Filename to remove 186 * @param bool $check Check file permissions 187 * @return bool True if the file was successfully removed, otherwise false 188 */ 189 function remove_file($filename, $check = false) 190 { 191 global $phpbb_filesystem; 192 193 if ($check && !$phpbb_filesystem->is_writable($this->cache_dir)) 194 { 195 // E_USER_ERROR - not using language entry - intended. 196 trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); 197 } 198 199 return @unlink($filename); 200 } 201 202 /** 203 * Remove directory 204 * 205 * @param string $dir Directory to remove 206 * 207 * @return null 208 */ 209 protected function remove_dir($dir) 210 { 211 try 212 { 213 $iterator = new \DirectoryIterator($dir); 214 } 215 catch (\Exception $e) 216 { 217 return; 218 } 219 220 foreach ($iterator as $fileInfo) 221 { 222 if ($fileInfo->isDot()) 223 { 224 continue; 225 } 226 227 if ($fileInfo->isDir()) 228 { 229 $this->remove_dir($fileInfo->getPathname()); 230 } 231 else 232 { 233 $this->remove_file($fileInfo->getPathname()); 234 } 235 } 236 237 @rmdir($dir); 238 } 239 240 /** 241 * {@inheritDoc} 242 */ 243 public function clean_query_id($query_id) 244 { 245 // Some DBMS functions accept/return objects and/or resources instead of integer identifier 246 // Attempting to cast object to int will throw error, hence correctly handle all cases 247 if (is_resource($query_id)) 248 { 249 return function_exists('get_resource_id') ? get_resource_id($query_id) : (int) $query_id; 250 } 251 else 252 { 253 return is_object($query_id) ? spl_object_id($query_id) : $query_id; 254 } 255 } 256 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |