@@ -485,6 +485,8 @@ |
||
| 485 | 485 | /** |
| 486 | 486 | * |
| 487 | 487 | * @access private |
| 488 | + * @param string $id |
|
| 489 | + * @param string $data |
|
| 488 | 490 | */ |
| 489 | 491 | function _memoryCacheAdd($id, $data) |
| 490 | 492 | { |
@@ -611,15 +611,15 @@ |
||
| 611 | 611 | function _hash($data, $controlType) |
| 612 | 612 | { |
| 613 | 613 | switch ($controlType) { |
| 614 | - case 'md5': |
|
| 615 | - return md5($data); |
|
| 616 | - case 'crc32': |
|
| 617 | - return sprintf('% 32d', crc32($data)); |
|
| 618 | - case 'strlen': |
|
| 619 | - return sprintf('% 32d', strlen($data)); |
|
| 620 | - default: |
|
| 621 | - $this->raiseError('Unknown controlType ! '. |
|
| 622 | - '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 614 | + case 'md5': |
|
| 615 | + return md5($data); |
|
| 616 | + case 'crc32': |
|
| 617 | + return sprintf('% 32d', crc32($data)); |
|
| 618 | + case 'strlen': |
|
| 619 | + return sprintf('% 32d', strlen($data)); |
|
| 620 | + default: |
|
| 621 | + $this->raiseError('Unknown controlType ! '. |
|
| 622 | + '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | |
@@ -46,575 +46,575 @@ |
||
| 46 | 46 | class TCache_Lite |
| 47 | 47 | { |
| 48 | 48 | |
| 49 | - // --- Private properties --- |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Directory where to put the cache files |
|
| 53 | - * (make sure to add a trailing slash) |
|
| 54 | - * |
|
| 55 | - * @var string $_cacheDir |
|
| 56 | - */ |
|
| 57 | - protected $_cacheDir = '/tmp/'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Enable / disable caching |
|
| 61 | - * |
|
| 62 | - * (can be very usefull for the debug of cached scripts) |
|
| 63 | - * |
|
| 64 | - * @var boolean $_caching |
|
| 65 | - */ |
|
| 66 | - protected $_caching = true; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Cache lifetime (in seconds) |
|
| 70 | - * |
|
| 71 | - * @var int $_lifeTime |
|
| 72 | - */ |
|
| 73 | - protected $_lifeTime = 3600; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Enable / disable fileLocking |
|
| 77 | - * |
|
| 78 | - * (can avoid cache corruption under bad circumstances) |
|
| 79 | - * |
|
| 80 | - * @var boolean $_fileLocking |
|
| 81 | - */ |
|
| 82 | - protected $_fileLocking = true; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Timestamp of the last valid cache |
|
| 86 | - * |
|
| 87 | - * @var int $_refreshTime |
|
| 88 | - */ |
|
| 89 | - protected $_refreshTime; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * File name (with path) |
|
| 93 | - * |
|
| 94 | - * @var string $_file |
|
| 95 | - */ |
|
| 96 | - protected $_file; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Enable / disable write control (the cache is read just after writing |
|
| 100 | - * to detect corrupt entries) |
|
| 101 | - * |
|
| 102 | - * Enable write control will lightly slow the cache writing but not the |
|
| 103 | - * cache reading. Write control can detect some corrupt cache files but |
|
| 104 | - * maybe it's not a perfect control |
|
| 105 | - * |
|
| 106 | - * @var boolean $_writeControl |
|
| 107 | - */ |
|
| 108 | - protected $_writeControl = true; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Enable / disable read control |
|
| 112 | - * |
|
| 113 | - * If enabled, a control key is embeded in cache file and this key is |
|
| 114 | - * compared with the one calculated after the reading. |
|
| 115 | - * |
|
| 116 | - * @var boolean $_writeControl |
|
| 117 | - */ |
|
| 118 | - protected $_readControl = true; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Type of read control (only if read control is enabled) |
|
| 122 | - * |
|
| 123 | - * Available values are : |
|
| 124 | - * 'md5' for a md5 hash control (best but slowest) |
|
| 125 | - * 'crc32' for a crc32 hash control (lightly less safe but faster, |
|
| 126 | - * better choice) |
|
| 127 | - * 'strlen' for a length only test (fastest) |
|
| 128 | - * |
|
| 129 | - * @var boolean $_readControlType |
|
| 130 | - */ |
|
| 131 | - protected $_readControlType = 'crc32'; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Current cache id |
|
| 135 | - * |
|
| 136 | - * @var string $_id |
|
| 137 | - */ |
|
| 138 | - protected $_id; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Current cache group |
|
| 142 | - * |
|
| 143 | - * @var string $_group |
|
| 144 | - */ |
|
| 145 | - protected $_group; |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Enable / Disable "Memory Caching" |
|
| 149 | - * |
|
| 150 | - * NB : There is no lifetime for memory caching ! |
|
| 151 | - * |
|
| 152 | - * @var boolean $_memoryCaching |
|
| 153 | - */ |
|
| 154 | - protected $_memoryCaching = false; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Enable / Disable "Only Memory Caching" |
|
| 158 | - * (be carefull, memory caching is "beta quality") |
|
| 159 | - * |
|
| 160 | - * @var boolean $_onlyMemoryCaching |
|
| 161 | - */ |
|
| 162 | - protected $_onlyMemoryCaching = false; |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Memory caching array |
|
| 166 | - * |
|
| 167 | - * @var array $_memoryCachingArray |
|
| 168 | - */ |
|
| 169 | - protected $_memoryCachingArray = array(); |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Memory caching counter |
|
| 173 | - * |
|
| 174 | - * @var int $memoryCachingCounter |
|
| 175 | - */ |
|
| 176 | - protected $_memoryCachingCounter = 0; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Memory caching limit |
|
| 180 | - * |
|
| 181 | - * @var int $memoryCachingLimit |
|
| 182 | - */ |
|
| 183 | - protected $_memoryCachingLimit = 1000; |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * File Name protection |
|
| 187 | - * |
|
| 188 | - * if set to true, you can use any cache id or group name |
|
| 189 | - * if set to false, it can be faster but cache ids and group names |
|
| 190 | - * will be used directly in cache file names so be carefull with |
|
| 191 | - * special characters... |
|
| 192 | - * |
|
| 193 | - * @var boolean $fileNameProtection |
|
| 194 | - */ |
|
| 195 | - protected $_fileNameProtection = true; |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Enable / disable automatic serialization |
|
| 199 | - * |
|
| 200 | - * it can be used to save directly datas which aren't strings |
|
| 201 | - * (but it's slower) |
|
| 202 | - * |
|
| 203 | - * @var boolean $_serialize |
|
| 204 | - */ |
|
| 205 | - protected $_automaticSerialization = false; |
|
| 206 | - |
|
| 207 | - // --- Public methods --- |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Constructor |
|
| 211 | - * |
|
| 212 | - * $options is an assoc. Available options are : |
|
| 213 | - * $options = array( |
|
| 214 | - * 'cacheDir' => directory where to put the cache files (string), |
|
| 215 | - * 'caching' => enable / disable caching (boolean), |
|
| 216 | - * 'lifeTime' => cache lifetime in seconds (int), |
|
| 217 | - * 'fileLocking' => enable / disable fileLocking (boolean), |
|
| 218 | - * 'writeControl' => enable / disable write control (boolean), |
|
| 219 | - * 'readControl' => enable / disable read control (boolean), |
|
| 220 | - * 'readControlType' => type of read control 'crc32', 'md5', 'strlen', |
|
| 221 | - * 'memoryCaching' => enable / disable memory caching (boolean), |
|
| 222 | - * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
| 223 | - * 'memoryCachingLimit' => max nbr of records in memory caching (int), |
|
| 224 | - * 'fileNameProtection' => enable / disable file name protection (boolean), |
|
| 225 | - * 'automaticSerialization' => enable / disable serialization (boolean) |
|
| 226 | - * ); |
|
| 227 | - * |
|
| 228 | - * @param array $options options |
|
| 229 | - * @access public |
|
| 230 | - */ |
|
| 231 | - function __construct($options = array(null)) |
|
| 232 | - { |
|
| 233 | - $availableOptions = array( 'automaticSerialization', |
|
| 234 | - 'fileNameProtection', |
|
| 235 | - 'memoryCaching', |
|
| 236 | - 'onlyMemoryCaching', |
|
| 237 | - 'memoryCachingLimit', |
|
| 238 | - 'cacheDir', |
|
| 239 | - 'caching', |
|
| 240 | - 'lifeTime', |
|
| 241 | - 'fileLocking', |
|
| 242 | - 'writeControl', |
|
| 243 | - 'readControl', |
|
| 244 | - 'readControlType'); |
|
| 245 | - foreach($options as $key => $value) { |
|
| 246 | - if(in_array($key, $availableOptions)) { |
|
| 247 | - $property = '_'.$key; |
|
| 248 | - $this->$property = $value; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
| 49 | + // --- Private properties --- |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Directory where to put the cache files |
|
| 53 | + * (make sure to add a trailing slash) |
|
| 54 | + * |
|
| 55 | + * @var string $_cacheDir |
|
| 56 | + */ |
|
| 57 | + protected $_cacheDir = '/tmp/'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Enable / disable caching |
|
| 61 | + * |
|
| 62 | + * (can be very usefull for the debug of cached scripts) |
|
| 63 | + * |
|
| 64 | + * @var boolean $_caching |
|
| 65 | + */ |
|
| 66 | + protected $_caching = true; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Cache lifetime (in seconds) |
|
| 70 | + * |
|
| 71 | + * @var int $_lifeTime |
|
| 72 | + */ |
|
| 73 | + protected $_lifeTime = 3600; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Enable / disable fileLocking |
|
| 77 | + * |
|
| 78 | + * (can avoid cache corruption under bad circumstances) |
|
| 79 | + * |
|
| 80 | + * @var boolean $_fileLocking |
|
| 81 | + */ |
|
| 82 | + protected $_fileLocking = true; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Timestamp of the last valid cache |
|
| 86 | + * |
|
| 87 | + * @var int $_refreshTime |
|
| 88 | + */ |
|
| 89 | + protected $_refreshTime; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * File name (with path) |
|
| 93 | + * |
|
| 94 | + * @var string $_file |
|
| 95 | + */ |
|
| 96 | + protected $_file; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Enable / disable write control (the cache is read just after writing |
|
| 100 | + * to detect corrupt entries) |
|
| 101 | + * |
|
| 102 | + * Enable write control will lightly slow the cache writing but not the |
|
| 103 | + * cache reading. Write control can detect some corrupt cache files but |
|
| 104 | + * maybe it's not a perfect control |
|
| 105 | + * |
|
| 106 | + * @var boolean $_writeControl |
|
| 107 | + */ |
|
| 108 | + protected $_writeControl = true; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Enable / disable read control |
|
| 112 | + * |
|
| 113 | + * If enabled, a control key is embeded in cache file and this key is |
|
| 114 | + * compared with the one calculated after the reading. |
|
| 115 | + * |
|
| 116 | + * @var boolean $_writeControl |
|
| 117 | + */ |
|
| 118 | + protected $_readControl = true; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Type of read control (only if read control is enabled) |
|
| 122 | + * |
|
| 123 | + * Available values are : |
|
| 124 | + * 'md5' for a md5 hash control (best but slowest) |
|
| 125 | + * 'crc32' for a crc32 hash control (lightly less safe but faster, |
|
| 126 | + * better choice) |
|
| 127 | + * 'strlen' for a length only test (fastest) |
|
| 128 | + * |
|
| 129 | + * @var boolean $_readControlType |
|
| 130 | + */ |
|
| 131 | + protected $_readControlType = 'crc32'; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Current cache id |
|
| 135 | + * |
|
| 136 | + * @var string $_id |
|
| 137 | + */ |
|
| 138 | + protected $_id; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Current cache group |
|
| 142 | + * |
|
| 143 | + * @var string $_group |
|
| 144 | + */ |
|
| 145 | + protected $_group; |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Enable / Disable "Memory Caching" |
|
| 149 | + * |
|
| 150 | + * NB : There is no lifetime for memory caching ! |
|
| 151 | + * |
|
| 152 | + * @var boolean $_memoryCaching |
|
| 153 | + */ |
|
| 154 | + protected $_memoryCaching = false; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Enable / Disable "Only Memory Caching" |
|
| 158 | + * (be carefull, memory caching is "beta quality") |
|
| 159 | + * |
|
| 160 | + * @var boolean $_onlyMemoryCaching |
|
| 161 | + */ |
|
| 162 | + protected $_onlyMemoryCaching = false; |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Memory caching array |
|
| 166 | + * |
|
| 167 | + * @var array $_memoryCachingArray |
|
| 168 | + */ |
|
| 169 | + protected $_memoryCachingArray = array(); |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Memory caching counter |
|
| 173 | + * |
|
| 174 | + * @var int $memoryCachingCounter |
|
| 175 | + */ |
|
| 176 | + protected $_memoryCachingCounter = 0; |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Memory caching limit |
|
| 180 | + * |
|
| 181 | + * @var int $memoryCachingLimit |
|
| 182 | + */ |
|
| 183 | + protected $_memoryCachingLimit = 1000; |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * File Name protection |
|
| 187 | + * |
|
| 188 | + * if set to true, you can use any cache id or group name |
|
| 189 | + * if set to false, it can be faster but cache ids and group names |
|
| 190 | + * will be used directly in cache file names so be carefull with |
|
| 191 | + * special characters... |
|
| 192 | + * |
|
| 193 | + * @var boolean $fileNameProtection |
|
| 194 | + */ |
|
| 195 | + protected $_fileNameProtection = true; |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Enable / disable automatic serialization |
|
| 199 | + * |
|
| 200 | + * it can be used to save directly datas which aren't strings |
|
| 201 | + * (but it's slower) |
|
| 202 | + * |
|
| 203 | + * @var boolean $_serialize |
|
| 204 | + */ |
|
| 205 | + protected $_automaticSerialization = false; |
|
| 206 | + |
|
| 207 | + // --- Public methods --- |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Constructor |
|
| 211 | + * |
|
| 212 | + * $options is an assoc. Available options are : |
|
| 213 | + * $options = array( |
|
| 214 | + * 'cacheDir' => directory where to put the cache files (string), |
|
| 215 | + * 'caching' => enable / disable caching (boolean), |
|
| 216 | + * 'lifeTime' => cache lifetime in seconds (int), |
|
| 217 | + * 'fileLocking' => enable / disable fileLocking (boolean), |
|
| 218 | + * 'writeControl' => enable / disable write control (boolean), |
|
| 219 | + * 'readControl' => enable / disable read control (boolean), |
|
| 220 | + * 'readControlType' => type of read control 'crc32', 'md5', 'strlen', |
|
| 221 | + * 'memoryCaching' => enable / disable memory caching (boolean), |
|
| 222 | + * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
| 223 | + * 'memoryCachingLimit' => max nbr of records in memory caching (int), |
|
| 224 | + * 'fileNameProtection' => enable / disable file name protection (boolean), |
|
| 225 | + * 'automaticSerialization' => enable / disable serialization (boolean) |
|
| 226 | + * ); |
|
| 227 | + * |
|
| 228 | + * @param array $options options |
|
| 229 | + * @access public |
|
| 230 | + */ |
|
| 231 | + function __construct($options = array(null)) |
|
| 232 | + { |
|
| 233 | + $availableOptions = array( 'automaticSerialization', |
|
| 234 | + 'fileNameProtection', |
|
| 235 | + 'memoryCaching', |
|
| 236 | + 'onlyMemoryCaching', |
|
| 237 | + 'memoryCachingLimit', |
|
| 238 | + 'cacheDir', |
|
| 239 | + 'caching', |
|
| 240 | + 'lifeTime', |
|
| 241 | + 'fileLocking', |
|
| 242 | + 'writeControl', |
|
| 243 | + 'readControl', |
|
| 244 | + 'readControlType'); |
|
| 245 | + foreach($options as $key => $value) { |
|
| 246 | + if(in_array($key, $availableOptions)) { |
|
| 247 | + $property = '_'.$key; |
|
| 248 | + $this->$property = $value; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + $this->_refreshTime = time() - $this->_lifeTime; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Test if a cache is available and (if yes) return it |
|
| 256 | - * |
|
| 257 | - * @param string $id cache id |
|
| 258 | - * @param string $group name of the cache group |
|
| 259 | - * @param boolean $doNotTestCacheValidity if set to true, the cache |
|
| 260 | - * validity won't be tested |
|
| 261 | - * @return string data of the cache (or false if no cache available) |
|
| 262 | - * @access public |
|
| 263 | - */ |
|
| 264 | - function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 265 | - { |
|
| 266 | - $this->_id = $id; |
|
| 267 | - $this->_group = $group; |
|
| 268 | - $data = false; |
|
| 269 | - if ($this->_caching) { |
|
| 270 | - $this->_setFileName($id, $group); |
|
| 271 | - if ($this->_memoryCaching) { |
|
| 272 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 273 | - if ($this->_automaticSerialization) { |
|
| 274 | - return unserialize( |
|
| 275 | - $this->_memoryCachingArray[$this->_file]); |
|
| 276 | - } else { |
|
| 277 | - return $this->_memoryCachingArray[$this->_file]; |
|
| 278 | - } |
|
| 279 | - } else { |
|
| 280 | - if ($this->_onlyMemoryCaching) { |
|
| 281 | - return false; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - if ($doNotTestCacheValidity) { |
|
| 286 | - if (file_exists($this->_file)) { |
|
| 287 | - $data = $this->_read(); |
|
| 288 | - } |
|
| 289 | - } else { |
|
| 290 | - if (@filemtime($this->_file) > $this->_refreshTime) { |
|
| 291 | - $data = $this->_read(); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - if (($data) and ($this->_memoryCaching)) { |
|
| 295 | - $this->_memoryCacheAdd($this->_file, $data); |
|
| 296 | - } |
|
| 297 | - if ($this->_automaticSerialization && is_string($data)) { |
|
| 298 | - $data = unserialize($data); |
|
| 299 | - } |
|
| 300 | - return $data; |
|
| 301 | - } |
|
| 302 | - return false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Save some data in a cache file |
|
| 307 | - * |
|
| 308 | - * @param string $data data to put in cache (can be another type than strings |
|
| 309 | - * if automaticSerialization is on) |
|
| 310 | - * @param string $id cache id |
|
| 311 | - * @param string $group name of the cache group |
|
| 312 | - * @return boolean true if no problem |
|
| 313 | - * @access public |
|
| 314 | - */ |
|
| 315 | - function save($data, $id = null, $group = 'default') |
|
| 316 | - { |
|
| 317 | - if ($this->_caching) { |
|
| 318 | - if ($this->_automaticSerialization) { |
|
| 319 | - $data = serialize($data); |
|
| 320 | - } |
|
| 321 | - if (isset($id)) { |
|
| 322 | - $this->_setFileName($id, $group); |
|
| 323 | - } |
|
| 324 | - if ($this->_memoryCaching) { |
|
| 325 | - $this->_memoryCacheAdd($this->_file, $data); |
|
| 326 | - if ($this->_onlyMemoryCaching) { |
|
| 327 | - return true; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - if ($this->_writeControl) { |
|
| 331 | - if (!$this->_writeAndControl($data)) { |
|
| 332 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 333 | - return false; |
|
| 334 | - } else { |
|
| 335 | - return true; |
|
| 336 | - } |
|
| 337 | - } else { |
|
| 338 | - return $this->_write($data); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Remove a cache file |
|
| 346 | - * |
|
| 347 | - * @param string $id cache id |
|
| 348 | - * @param string $group name of the cache group |
|
| 349 | - * @return boolean true if no problem |
|
| 350 | - * @access public |
|
| 351 | - */ |
|
| 352 | - function remove($id, $group = 'default') |
|
| 353 | - { |
|
| 354 | - $this->_setFileName($id, $group); |
|
| 355 | - if (!@unlink($this->_file)) { |
|
| 356 | - $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
|
| 357 | - return false; |
|
| 358 | - } |
|
| 359 | - return true; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Clean the cache |
|
| 364 | - * |
|
| 365 | - * if no group is specified all cache files will be destroyed |
|
| 366 | - * else only cache files of the specified group will be destroyed |
|
| 367 | - * |
|
| 368 | - * @param string $group name of the cache group |
|
| 369 | - * @return boolean true if no problem |
|
| 370 | - * @access public |
|
| 371 | - */ |
|
| 372 | - function clean($group = false) |
|
| 373 | - { |
|
| 374 | - if ($this->_fileNameProtection) { |
|
| 375 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 376 | - } else { |
|
| 377 | - $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 378 | - } |
|
| 379 | - if ($this->_memoryCaching) { |
|
| 380 | - while (list($key, $value) = each($this->_memoryCaching)) { |
|
| 381 | - if (strpos($key, $motif, 0)) { |
|
| 382 | - unset($this->_memoryCaching[$key]); |
|
| 383 | - $this->_memoryCachingCounter = |
|
| 384 | - $this->_memoryCachingCounter - 1; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - if ($this->_onlyMemoryCaching) { |
|
| 388 | - return true; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - if (!($dh = opendir($this->_cacheDir))) { |
|
| 392 | - $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - while ($file = readdir($dh)) { |
|
| 396 | - if (($file != '.') && ($file != '..')) { |
|
| 397 | - $file = $this->_cacheDir . $file; |
|
| 398 | - if (is_file($file)) { |
|
| 399 | - if (strpos($file, $motif, 0)) { |
|
| 400 | - if (!@unlink($file)) { |
|
| 401 | - $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 402 | - return false; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - return true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Set a new life time |
|
| 413 | - * |
|
| 414 | - * @param int $newLifeTime new life time (in seconds) |
|
| 415 | - * @access public |
|
| 416 | - */ |
|
| 417 | - function setLifeTime($newLifeTime) |
|
| 418 | - { |
|
| 419 | - $this->_lifeTime = $newLifeTime; |
|
| 420 | - $this->_refreshTime = time() - $newLifeTime; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * |
|
| 425 | - * @access public |
|
| 426 | - */ |
|
| 427 | - function saveMemoryCachingState($id, $group = 'default') |
|
| 428 | - { |
|
| 429 | - if ($this->_caching) { |
|
| 430 | - $array = array( |
|
| 431 | - 'counter' => $this->_memoryCachingCounter, |
|
| 432 | - 'array' => $this->_memoryCachingState |
|
| 433 | - ); |
|
| 434 | - $data = serialize($array); |
|
| 435 | - $this->save($data, $id, $group); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * |
|
| 441 | - * @access public |
|
| 442 | - */ |
|
| 443 | - function getMemoryCachingState($id, $group = 'default', |
|
| 444 | - $doNotTestCacheValidity = false) |
|
| 445 | - { |
|
| 446 | - if ($this->_caching) { |
|
| 447 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
| 448 | - { |
|
| 449 | - $array = unserialize($data); |
|
| 450 | - $this->_memoryCachingCounter = $array['counter']; |
|
| 451 | - $this->_memoryCachingArray = $array['array']; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Return the cache last modification time |
|
| 458 | - * |
|
| 459 | - * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 460 | - * |
|
| 461 | - * @return int last modification time |
|
| 462 | - */ |
|
| 463 | - function lastModified() { |
|
| 464 | - return filemtime($this->cache->_file); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Trigger a PEAR error |
|
| 469 | - * |
|
| 470 | - * To improve performances, the PEAR.php file is included dynamically. |
|
| 471 | - * The file is so included only when an error is triggered. So, in most |
|
| 472 | - * cases, the file isn't included and perfs are much better. |
|
| 473 | - * |
|
| 474 | - * @param string $msg error message |
|
| 475 | - * @param int $code error code |
|
| 476 | - * @access public |
|
| 477 | - */ |
|
| 478 | - function raiseError($msg, $code) |
|
| 479 | - { |
|
| 480 | - throw new Exception($msg); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // --- Private methods --- |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * |
|
| 487 | - * @access private |
|
| 488 | - */ |
|
| 489 | - function _memoryCacheAdd($id, $data) |
|
| 490 | - { |
|
| 491 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
| 492 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 493 | - list($key, $value) = each($this->_memoryCachingArray); |
|
| 494 | - unset($this->_memoryCachingArray[$key]); |
|
| 495 | - } else { |
|
| 496 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Make a file name (with path) |
|
| 502 | - * |
|
| 503 | - * @param string $id cache id |
|
| 504 | - * @param string $group name of the group |
|
| 505 | - * @access private |
|
| 506 | - */ |
|
| 507 | - function _setFileName($id, $group) |
|
| 508 | - { |
|
| 509 | - if ($this->_fileNameProtection) { |
|
| 510 | - $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
| 511 | - .md5($id)); |
|
| 512 | - } else { |
|
| 513 | - $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - function getCacheFile() |
|
| 518 | - { |
|
| 519 | - return $this->_file; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Read the cache file and return the content |
|
| 524 | - * |
|
| 525 | - * @return string content of the cache file |
|
| 526 | - * @access private |
|
| 527 | - */ |
|
| 528 | - function _read() |
|
| 529 | - { |
|
| 530 | - $fp = @fopen($this->_file, "rb"); |
|
| 531 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 532 | - if ($fp) { |
|
| 533 | - // because the filesize can be cached by PHP itself... |
|
| 534 | - clearstatcache(); |
|
| 535 | - $length = @filesize($this->_file); |
|
| 536 | - if ($this->_readControl) { |
|
| 537 | - $hashControl = @fread($fp, 32); |
|
| 538 | - $length = $length - 32; |
|
| 539 | - } |
|
| 540 | - $data = @fread($fp, $length); |
|
| 541 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 542 | - @fclose($fp); |
|
| 543 | - if ($this->_readControl) { |
|
| 544 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
| 545 | - if ($hashData != $hashControl) { |
|
| 546 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - return $data; |
|
| 551 | - } |
|
| 552 | - $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 553 | - return false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Write the given data in the cache file |
|
| 558 | - * |
|
| 559 | - * @param string $data data to put in cache |
|
| 560 | - * @return boolean true if ok |
|
| 561 | - * @access private |
|
| 562 | - */ |
|
| 563 | - function _write($data) |
|
| 564 | - { |
|
| 565 | - $fp = @fopen($this->_file, "wb"); |
|
| 566 | - if ($fp) { |
|
| 567 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 568 | - if ($this->_readControl) { |
|
| 569 | - @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 570 | - } |
|
| 571 | - $len = strlen($data); |
|
| 572 | - @fwrite($fp, $data, $len); |
|
| 573 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 574 | - @fclose($fp); |
|
| 575 | - return true; |
|
| 576 | - } |
|
| 577 | - $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
| 578 | - return false; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Write the given data in the cache file and control it just after to avoid |
|
| 583 | - * corrupted cache entries |
|
| 584 | - * |
|
| 585 | - * @param string $data data to put in cache |
|
| 586 | - * @return boolean true if the test is ok |
|
| 587 | - * @access private |
|
| 588 | - */ |
|
| 589 | - function _writeAndControl($data) |
|
| 590 | - { |
|
| 591 | - $this->_write($data); |
|
| 592 | - $dataRead = $this->_read($data); |
|
| 593 | - return ($dataRead==$data); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Make a control key with the string containing datas |
|
| 598 | - * |
|
| 599 | - * @param string $data data |
|
| 600 | - * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 601 | - * @return string control key |
|
| 602 | - * @access private |
|
| 603 | - */ |
|
| 604 | - function _hash($data, $controlType) |
|
| 605 | - { |
|
| 606 | - switch ($controlType) { |
|
| 607 | - case 'md5': |
|
| 608 | - return md5($data); |
|
| 609 | - case 'crc32': |
|
| 610 | - return sprintf('% 32d', crc32($data)); |
|
| 611 | - case 'strlen': |
|
| 612 | - return sprintf('% 32d', strlen($data)); |
|
| 613 | - default: |
|
| 614 | - $this->raiseError('Unknown controlType ! '. |
|
| 615 | - '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 616 | - } |
|
| 617 | - } |
|
| 254 | + /** |
|
| 255 | + * Test if a cache is available and (if yes) return it |
|
| 256 | + * |
|
| 257 | + * @param string $id cache id |
|
| 258 | + * @param string $group name of the cache group |
|
| 259 | + * @param boolean $doNotTestCacheValidity if set to true, the cache |
|
| 260 | + * validity won't be tested |
|
| 261 | + * @return string data of the cache (or false if no cache available) |
|
| 262 | + * @access public |
|
| 263 | + */ |
|
| 264 | + function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 265 | + { |
|
| 266 | + $this->_id = $id; |
|
| 267 | + $this->_group = $group; |
|
| 268 | + $data = false; |
|
| 269 | + if ($this->_caching) { |
|
| 270 | + $this->_setFileName($id, $group); |
|
| 271 | + if ($this->_memoryCaching) { |
|
| 272 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 273 | + if ($this->_automaticSerialization) { |
|
| 274 | + return unserialize( |
|
| 275 | + $this->_memoryCachingArray[$this->_file]); |
|
| 276 | + } else { |
|
| 277 | + return $this->_memoryCachingArray[$this->_file]; |
|
| 278 | + } |
|
| 279 | + } else { |
|
| 280 | + if ($this->_onlyMemoryCaching) { |
|
| 281 | + return false; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + if ($doNotTestCacheValidity) { |
|
| 286 | + if (file_exists($this->_file)) { |
|
| 287 | + $data = $this->_read(); |
|
| 288 | + } |
|
| 289 | + } else { |
|
| 290 | + if (@filemtime($this->_file) > $this->_refreshTime) { |
|
| 291 | + $data = $this->_read(); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + if (($data) and ($this->_memoryCaching)) { |
|
| 295 | + $this->_memoryCacheAdd($this->_file, $data); |
|
| 296 | + } |
|
| 297 | + if ($this->_automaticSerialization && is_string($data)) { |
|
| 298 | + $data = unserialize($data); |
|
| 299 | + } |
|
| 300 | + return $data; |
|
| 301 | + } |
|
| 302 | + return false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Save some data in a cache file |
|
| 307 | + * |
|
| 308 | + * @param string $data data to put in cache (can be another type than strings |
|
| 309 | + * if automaticSerialization is on) |
|
| 310 | + * @param string $id cache id |
|
| 311 | + * @param string $group name of the cache group |
|
| 312 | + * @return boolean true if no problem |
|
| 313 | + * @access public |
|
| 314 | + */ |
|
| 315 | + function save($data, $id = null, $group = 'default') |
|
| 316 | + { |
|
| 317 | + if ($this->_caching) { |
|
| 318 | + if ($this->_automaticSerialization) { |
|
| 319 | + $data = serialize($data); |
|
| 320 | + } |
|
| 321 | + if (isset($id)) { |
|
| 322 | + $this->_setFileName($id, $group); |
|
| 323 | + } |
|
| 324 | + if ($this->_memoryCaching) { |
|
| 325 | + $this->_memoryCacheAdd($this->_file, $data); |
|
| 326 | + if ($this->_onlyMemoryCaching) { |
|
| 327 | + return true; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + if ($this->_writeControl) { |
|
| 331 | + if (!$this->_writeAndControl($data)) { |
|
| 332 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 333 | + return false; |
|
| 334 | + } else { |
|
| 335 | + return true; |
|
| 336 | + } |
|
| 337 | + } else { |
|
| 338 | + return $this->_write($data); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Remove a cache file |
|
| 346 | + * |
|
| 347 | + * @param string $id cache id |
|
| 348 | + * @param string $group name of the cache group |
|
| 349 | + * @return boolean true if no problem |
|
| 350 | + * @access public |
|
| 351 | + */ |
|
| 352 | + function remove($id, $group = 'default') |
|
| 353 | + { |
|
| 354 | + $this->_setFileName($id, $group); |
|
| 355 | + if (!@unlink($this->_file)) { |
|
| 356 | + $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 359 | + return true; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Clean the cache |
|
| 364 | + * |
|
| 365 | + * if no group is specified all cache files will be destroyed |
|
| 366 | + * else only cache files of the specified group will be destroyed |
|
| 367 | + * |
|
| 368 | + * @param string $group name of the cache group |
|
| 369 | + * @return boolean true if no problem |
|
| 370 | + * @access public |
|
| 371 | + */ |
|
| 372 | + function clean($group = false) |
|
| 373 | + { |
|
| 374 | + if ($this->_fileNameProtection) { |
|
| 375 | + $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 376 | + } else { |
|
| 377 | + $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 378 | + } |
|
| 379 | + if ($this->_memoryCaching) { |
|
| 380 | + while (list($key, $value) = each($this->_memoryCaching)) { |
|
| 381 | + if (strpos($key, $motif, 0)) { |
|
| 382 | + unset($this->_memoryCaching[$key]); |
|
| 383 | + $this->_memoryCachingCounter = |
|
| 384 | + $this->_memoryCachingCounter - 1; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + if ($this->_onlyMemoryCaching) { |
|
| 388 | + return true; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + if (!($dh = opendir($this->_cacheDir))) { |
|
| 392 | + $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + while ($file = readdir($dh)) { |
|
| 396 | + if (($file != '.') && ($file != '..')) { |
|
| 397 | + $file = $this->_cacheDir . $file; |
|
| 398 | + if (is_file($file)) { |
|
| 399 | + if (strpos($file, $motif, 0)) { |
|
| 400 | + if (!@unlink($file)) { |
|
| 401 | + $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 402 | + return false; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + return true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Set a new life time |
|
| 413 | + * |
|
| 414 | + * @param int $newLifeTime new life time (in seconds) |
|
| 415 | + * @access public |
|
| 416 | + */ |
|
| 417 | + function setLifeTime($newLifeTime) |
|
| 418 | + { |
|
| 419 | + $this->_lifeTime = $newLifeTime; |
|
| 420 | + $this->_refreshTime = time() - $newLifeTime; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * |
|
| 425 | + * @access public |
|
| 426 | + */ |
|
| 427 | + function saveMemoryCachingState($id, $group = 'default') |
|
| 428 | + { |
|
| 429 | + if ($this->_caching) { |
|
| 430 | + $array = array( |
|
| 431 | + 'counter' => $this->_memoryCachingCounter, |
|
| 432 | + 'array' => $this->_memoryCachingState |
|
| 433 | + ); |
|
| 434 | + $data = serialize($array); |
|
| 435 | + $this->save($data, $id, $group); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * |
|
| 441 | + * @access public |
|
| 442 | + */ |
|
| 443 | + function getMemoryCachingState($id, $group = 'default', |
|
| 444 | + $doNotTestCacheValidity = false) |
|
| 445 | + { |
|
| 446 | + if ($this->_caching) { |
|
| 447 | + if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
| 448 | + { |
|
| 449 | + $array = unserialize($data); |
|
| 450 | + $this->_memoryCachingCounter = $array['counter']; |
|
| 451 | + $this->_memoryCachingArray = $array['array']; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Return the cache last modification time |
|
| 458 | + * |
|
| 459 | + * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 460 | + * |
|
| 461 | + * @return int last modification time |
|
| 462 | + */ |
|
| 463 | + function lastModified() { |
|
| 464 | + return filemtime($this->cache->_file); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Trigger a PEAR error |
|
| 469 | + * |
|
| 470 | + * To improve performances, the PEAR.php file is included dynamically. |
|
| 471 | + * The file is so included only when an error is triggered. So, in most |
|
| 472 | + * cases, the file isn't included and perfs are much better. |
|
| 473 | + * |
|
| 474 | + * @param string $msg error message |
|
| 475 | + * @param int $code error code |
|
| 476 | + * @access public |
|
| 477 | + */ |
|
| 478 | + function raiseError($msg, $code) |
|
| 479 | + { |
|
| 480 | + throw new Exception($msg); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // --- Private methods --- |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * |
|
| 487 | + * @access private |
|
| 488 | + */ |
|
| 489 | + function _memoryCacheAdd($id, $data) |
|
| 490 | + { |
|
| 491 | + $this->_memoryCachingArray[$this->_file] = $data; |
|
| 492 | + if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 493 | + list($key, $value) = each($this->_memoryCachingArray); |
|
| 494 | + unset($this->_memoryCachingArray[$key]); |
|
| 495 | + } else { |
|
| 496 | + $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Make a file name (with path) |
|
| 502 | + * |
|
| 503 | + * @param string $id cache id |
|
| 504 | + * @param string $group name of the group |
|
| 505 | + * @access private |
|
| 506 | + */ |
|
| 507 | + function _setFileName($id, $group) |
|
| 508 | + { |
|
| 509 | + if ($this->_fileNameProtection) { |
|
| 510 | + $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
| 511 | + .md5($id)); |
|
| 512 | + } else { |
|
| 513 | + $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + function getCacheFile() |
|
| 518 | + { |
|
| 519 | + return $this->_file; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Read the cache file and return the content |
|
| 524 | + * |
|
| 525 | + * @return string content of the cache file |
|
| 526 | + * @access private |
|
| 527 | + */ |
|
| 528 | + function _read() |
|
| 529 | + { |
|
| 530 | + $fp = @fopen($this->_file, "rb"); |
|
| 531 | + if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 532 | + if ($fp) { |
|
| 533 | + // because the filesize can be cached by PHP itself... |
|
| 534 | + clearstatcache(); |
|
| 535 | + $length = @filesize($this->_file); |
|
| 536 | + if ($this->_readControl) { |
|
| 537 | + $hashControl = @fread($fp, 32); |
|
| 538 | + $length = $length - 32; |
|
| 539 | + } |
|
| 540 | + $data = @fread($fp, $length); |
|
| 541 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 542 | + @fclose($fp); |
|
| 543 | + if ($this->_readControl) { |
|
| 544 | + $hashData = $this->_hash($data, $this->_readControlType); |
|
| 545 | + if ($hashData != $hashControl) { |
|
| 546 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + return $data; |
|
| 551 | + } |
|
| 552 | + $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 553 | + return false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Write the given data in the cache file |
|
| 558 | + * |
|
| 559 | + * @param string $data data to put in cache |
|
| 560 | + * @return boolean true if ok |
|
| 561 | + * @access private |
|
| 562 | + */ |
|
| 563 | + function _write($data) |
|
| 564 | + { |
|
| 565 | + $fp = @fopen($this->_file, "wb"); |
|
| 566 | + if ($fp) { |
|
| 567 | + if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 568 | + if ($this->_readControl) { |
|
| 569 | + @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 570 | + } |
|
| 571 | + $len = strlen($data); |
|
| 572 | + @fwrite($fp, $data, $len); |
|
| 573 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 574 | + @fclose($fp); |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 577 | + $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
| 578 | + return false; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Write the given data in the cache file and control it just after to avoid |
|
| 583 | + * corrupted cache entries |
|
| 584 | + * |
|
| 585 | + * @param string $data data to put in cache |
|
| 586 | + * @return boolean true if the test is ok |
|
| 587 | + * @access private |
|
| 588 | + */ |
|
| 589 | + function _writeAndControl($data) |
|
| 590 | + { |
|
| 591 | + $this->_write($data); |
|
| 592 | + $dataRead = $this->_read($data); |
|
| 593 | + return ($dataRead==$data); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Make a control key with the string containing datas |
|
| 598 | + * |
|
| 599 | + * @param string $data data |
|
| 600 | + * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 601 | + * @return string control key |
|
| 602 | + * @access private |
|
| 603 | + */ |
|
| 604 | + function _hash($data, $controlType) |
|
| 605 | + { |
|
| 606 | + switch ($controlType) { |
|
| 607 | + case 'md5': |
|
| 608 | + return md5($data); |
|
| 609 | + case 'crc32': |
|
| 610 | + return sprintf('% 32d', crc32($data)); |
|
| 611 | + case 'strlen': |
|
| 612 | + return sprintf('% 32d', strlen($data)); |
|
| 613 | + default: |
|
| 614 | + $this->raiseError('Unknown controlType ! '. |
|
| 615 | + '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | 619 | } |
| 620 | 620 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @var string $_cacheDir |
| 56 | 56 | */ |
| 57 | - protected $_cacheDir = '/tmp/'; |
|
| 57 | + protected $_cacheDir='/tmp/'; |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Enable / disable caching |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @var boolean $_caching |
| 65 | 65 | */ |
| 66 | - protected $_caching = true; |
|
| 66 | + protected $_caching=true; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Cache lifetime (in seconds) |
| 70 | 70 | * |
| 71 | 71 | * @var int $_lifeTime |
| 72 | 72 | */ |
| 73 | - protected $_lifeTime = 3600; |
|
| 73 | + protected $_lifeTime=3600; |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Enable / disable fileLocking |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @var boolean $_fileLocking |
| 81 | 81 | */ |
| 82 | - protected $_fileLocking = true; |
|
| 82 | + protected $_fileLocking=true; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Timestamp of the last valid cache |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @var boolean $_writeControl |
| 107 | 107 | */ |
| 108 | - protected $_writeControl = true; |
|
| 108 | + protected $_writeControl=true; |
|
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * Enable / disable read control |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @var boolean $_writeControl |
| 117 | 117 | */ |
| 118 | - protected $_readControl = true; |
|
| 118 | + protected $_readControl=true; |
|
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * Type of read control (only if read control is enabled) |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @var boolean $_readControlType |
| 130 | 130 | */ |
| 131 | - protected $_readControlType = 'crc32'; |
|
| 131 | + protected $_readControlType='crc32'; |
|
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Current cache id |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @var boolean $_memoryCaching |
| 153 | 153 | */ |
| 154 | - protected $_memoryCaching = false; |
|
| 154 | + protected $_memoryCaching=false; |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Enable / Disable "Only Memory Caching" |
@@ -159,28 +159,28 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @var boolean $_onlyMemoryCaching |
| 161 | 161 | */ |
| 162 | - protected $_onlyMemoryCaching = false; |
|
| 162 | + protected $_onlyMemoryCaching=false; |
|
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Memory caching array |
| 166 | 166 | * |
| 167 | 167 | * @var array $_memoryCachingArray |
| 168 | 168 | */ |
| 169 | - protected $_memoryCachingArray = array(); |
|
| 169 | + protected $_memoryCachingArray=array(); |
|
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * Memory caching counter |
| 173 | 173 | * |
| 174 | 174 | * @var int $memoryCachingCounter |
| 175 | 175 | */ |
| 176 | - protected $_memoryCachingCounter = 0; |
|
| 176 | + protected $_memoryCachingCounter=0; |
|
| 177 | 177 | |
| 178 | 178 | /** |
| 179 | 179 | * Memory caching limit |
| 180 | 180 | * |
| 181 | 181 | * @var int $memoryCachingLimit |
| 182 | 182 | */ |
| 183 | - protected $_memoryCachingLimit = 1000; |
|
| 183 | + protected $_memoryCachingLimit=1000; |
|
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * File Name protection |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @var boolean $fileNameProtection |
| 194 | 194 | */ |
| 195 | - protected $_fileNameProtection = true; |
|
| 195 | + protected $_fileNameProtection=true; |
|
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Enable / disable automatic serialization |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * |
| 203 | 203 | * @var boolean $_serialize |
| 204 | 204 | */ |
| 205 | - protected $_automaticSerialization = false; |
|
| 205 | + protected $_automaticSerialization=false; |
|
| 206 | 206 | |
| 207 | 207 | // --- Public methods --- |
| 208 | 208 | |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | * @param array $options options |
| 229 | 229 | * @access public |
| 230 | 230 | */ |
| 231 | - function __construct($options = array(null)) |
|
| 231 | + function __construct($options=array(null)) |
|
| 232 | 232 | { |
| 233 | - $availableOptions = array( 'automaticSerialization', |
|
| 233 | + $availableOptions=array('automaticSerialization', |
|
| 234 | 234 | 'fileNameProtection', |
| 235 | 235 | 'memoryCaching', |
| 236 | 236 | 'onlyMemoryCaching', |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | 'readControlType'); |
| 245 | 245 | foreach($options as $key => $value) { |
| 246 | 246 | if(in_array($key, $availableOptions)) { |
| 247 | - $property = '_'.$key; |
|
| 248 | - $this->$property = $value; |
|
| 247 | + $property='_'.$key; |
|
| 248 | + $this->$property=$value; |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
| 251 | + $this->_refreshTime=time() - $this->_lifeTime; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -261,41 +261,41 @@ discard block |
||
| 261 | 261 | * @return string data of the cache (or false if no cache available) |
| 262 | 262 | * @access public |
| 263 | 263 | */ |
| 264 | - function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 264 | + function get($id, $group='default', $doNotTestCacheValidity=false) |
|
| 265 | 265 | { |
| 266 | - $this->_id = $id; |
|
| 267 | - $this->_group = $group; |
|
| 268 | - $data = false; |
|
| 269 | - if ($this->_caching) { |
|
| 266 | + $this->_id=$id; |
|
| 267 | + $this->_group=$group; |
|
| 268 | + $data=false; |
|
| 269 | + if($this->_caching) { |
|
| 270 | 270 | $this->_setFileName($id, $group); |
| 271 | - if ($this->_memoryCaching) { |
|
| 272 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 273 | - if ($this->_automaticSerialization) { |
|
| 271 | + if($this->_memoryCaching) { |
|
| 272 | + if(isset($this->_memoryCachingArray[$this->_file])) { |
|
| 273 | + if($this->_automaticSerialization) { |
|
| 274 | 274 | return unserialize( |
| 275 | 275 | $this->_memoryCachingArray[$this->_file]); |
| 276 | 276 | } else { |
| 277 | 277 | return $this->_memoryCachingArray[$this->_file]; |
| 278 | 278 | } |
| 279 | 279 | } else { |
| 280 | - if ($this->_onlyMemoryCaching) { |
|
| 280 | + if($this->_onlyMemoryCaching) { |
|
| 281 | 281 | return false; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | - if ($doNotTestCacheValidity) { |
|
| 286 | - if (file_exists($this->_file)) { |
|
| 287 | - $data = $this->_read(); |
|
| 285 | + if($doNotTestCacheValidity) { |
|
| 286 | + if(file_exists($this->_file)) { |
|
| 287 | + $data=$this->_read(); |
|
| 288 | 288 | } |
| 289 | 289 | } else { |
| 290 | - if (@filemtime($this->_file) > $this->_refreshTime) { |
|
| 291 | - $data = $this->_read(); |
|
| 290 | + if(@filemtime($this->_file) > $this->_refreshTime) { |
|
| 291 | + $data=$this->_read(); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | - if (($data) and ($this->_memoryCaching)) { |
|
| 294 | + if(($data) and ($this->_memoryCaching)) { |
|
| 295 | 295 | $this->_memoryCacheAdd($this->_file, $data); |
| 296 | 296 | } |
| 297 | - if ($this->_automaticSerialization && is_string($data)) { |
|
| 298 | - $data = unserialize($data); |
|
| 297 | + if($this->_automaticSerialization && is_string($data)) { |
|
| 298 | + $data=unserialize($data); |
|
| 299 | 299 | } |
| 300 | 300 | return $data; |
| 301 | 301 | } |
@@ -312,24 +312,24 @@ discard block |
||
| 312 | 312 | * @return boolean true if no problem |
| 313 | 313 | * @access public |
| 314 | 314 | */ |
| 315 | - function save($data, $id = null, $group = 'default') |
|
| 315 | + function save($data, $id=null, $group='default') |
|
| 316 | 316 | { |
| 317 | - if ($this->_caching) { |
|
| 318 | - if ($this->_automaticSerialization) { |
|
| 319 | - $data = serialize($data); |
|
| 317 | + if($this->_caching) { |
|
| 318 | + if($this->_automaticSerialization) { |
|
| 319 | + $data=serialize($data); |
|
| 320 | 320 | } |
| 321 | - if (isset($id)) { |
|
| 321 | + if(isset($id)) { |
|
| 322 | 322 | $this->_setFileName($id, $group); |
| 323 | 323 | } |
| 324 | - if ($this->_memoryCaching) { |
|
| 324 | + if($this->_memoryCaching) { |
|
| 325 | 325 | $this->_memoryCacheAdd($this->_file, $data); |
| 326 | - if ($this->_onlyMemoryCaching) { |
|
| 326 | + if($this->_onlyMemoryCaching) { |
|
| 327 | 327 | return true; |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | - if ($this->_writeControl) { |
|
| 331 | - if (!$this->_writeAndControl($data)) { |
|
| 332 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 330 | + if($this->_writeControl) { |
|
| 331 | + if(!$this->_writeAndControl($data)) { |
|
| 332 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 333 | 333 | return false; |
| 334 | 334 | } else { |
| 335 | 335 | return true; |
@@ -349,10 +349,10 @@ discard block |
||
| 349 | 349 | * @return boolean true if no problem |
| 350 | 350 | * @access public |
| 351 | 351 | */ |
| 352 | - function remove($id, $group = 'default') |
|
| 352 | + function remove($id, $group='default') |
|
| 353 | 353 | { |
| 354 | 354 | $this->_setFileName($id, $group); |
| 355 | - if (!@unlink($this->_file)) { |
|
| 355 | + if(!@unlink($this->_file)) { |
|
| 356 | 356 | $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
| 357 | 357 | return false; |
| 358 | 358 | } |
@@ -369,35 +369,35 @@ discard block |
||
| 369 | 369 | * @return boolean true if no problem |
| 370 | 370 | * @access public |
| 371 | 371 | */ |
| 372 | - function clean($group = false) |
|
| 372 | + function clean($group=false) |
|
| 373 | 373 | { |
| 374 | - if ($this->_fileNameProtection) { |
|
| 375 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 374 | + if($this->_fileNameProtection) { |
|
| 375 | + $motif=($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 376 | 376 | } else { |
| 377 | - $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 377 | + $motif=($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 378 | 378 | } |
| 379 | - if ($this->_memoryCaching) { |
|
| 380 | - while (list($key, $value) = each($this->_memoryCaching)) { |
|
| 381 | - if (strpos($key, $motif, 0)) { |
|
| 379 | + if($this->_memoryCaching) { |
|
| 380 | + while(list($key, $value)=each($this->_memoryCaching)) { |
|
| 381 | + if(strpos($key, $motif, 0)) { |
|
| 382 | 382 | unset($this->_memoryCaching[$key]); |
| 383 | - $this->_memoryCachingCounter = |
|
| 383 | + $this->_memoryCachingCounter= |
|
| 384 | 384 | $this->_memoryCachingCounter - 1; |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | - if ($this->_onlyMemoryCaching) { |
|
| 387 | + if($this->_onlyMemoryCaching) { |
|
| 388 | 388 | return true; |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | - if (!($dh = opendir($this->_cacheDir))) { |
|
| 391 | + if(!($dh=opendir($this->_cacheDir))) { |
|
| 392 | 392 | $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | - while ($file = readdir($dh)) { |
|
| 396 | - if (($file != '.') && ($file != '..')) { |
|
| 397 | - $file = $this->_cacheDir . $file; |
|
| 398 | - if (is_file($file)) { |
|
| 399 | - if (strpos($file, $motif, 0)) { |
|
| 400 | - if (!@unlink($file)) { |
|
| 395 | + while($file=readdir($dh)) { |
|
| 396 | + if(($file!='.') && ($file!='..')) { |
|
| 397 | + $file=$this->_cacheDir.$file; |
|
| 398 | + if(is_file($file)) { |
|
| 399 | + if(strpos($file, $motif, 0)) { |
|
| 400 | + if(!@unlink($file)) { |
|
| 401 | 401 | $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
| 402 | 402 | return false; |
| 403 | 403 | } |
@@ -416,22 +416,22 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | function setLifeTime($newLifeTime) |
| 418 | 418 | { |
| 419 | - $this->_lifeTime = $newLifeTime; |
|
| 420 | - $this->_refreshTime = time() - $newLifeTime; |
|
| 419 | + $this->_lifeTime=$newLifeTime; |
|
| 420 | + $this->_refreshTime=time() - $newLifeTime; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
| 424 | 424 | * |
| 425 | 425 | * @access public |
| 426 | 426 | */ |
| 427 | - function saveMemoryCachingState($id, $group = 'default') |
|
| 427 | + function saveMemoryCachingState($id, $group='default') |
|
| 428 | 428 | { |
| 429 | - if ($this->_caching) { |
|
| 430 | - $array = array( |
|
| 429 | + if($this->_caching) { |
|
| 430 | + $array=array( |
|
| 431 | 431 | 'counter' => $this->_memoryCachingCounter, |
| 432 | 432 | 'array' => $this->_memoryCachingState |
| 433 | 433 | ); |
| 434 | - $data = serialize($array); |
|
| 434 | + $data=serialize($array); |
|
| 435 | 435 | $this->save($data, $id, $group); |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -440,15 +440,15 @@ discard block |
||
| 440 | 440 | * |
| 441 | 441 | * @access public |
| 442 | 442 | */ |
| 443 | - function getMemoryCachingState($id, $group = 'default', |
|
| 444 | - $doNotTestCacheValidity = false) |
|
| 443 | + function getMemoryCachingState($id, $group='default', |
|
| 444 | + $doNotTestCacheValidity=false) |
|
| 445 | 445 | { |
| 446 | - if ($this->_caching) { |
|
| 447 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
| 446 | + if($this->_caching) { |
|
| 447 | + if($data=$this->get($id, $group, $doNotTestCacheValidity)) |
|
| 448 | 448 | { |
| 449 | - $array = unserialize($data); |
|
| 450 | - $this->_memoryCachingCounter = $array['counter']; |
|
| 451 | - $this->_memoryCachingArray = $array['array']; |
|
| 449 | + $array=unserialize($data); |
|
| 450 | + $this->_memoryCachingCounter=$array['counter']; |
|
| 451 | + $this->_memoryCachingArray=$array['array']; |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | } |
@@ -488,12 +488,12 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | function _memoryCacheAdd($id, $data) |
| 490 | 490 | { |
| 491 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
| 492 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 493 | - list($key, $value) = each($this->_memoryCachingArray); |
|
| 491 | + $this->_memoryCachingArray[$this->_file]=$data; |
|
| 492 | + if($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 493 | + list($key, $value)=each($this->_memoryCachingArray); |
|
| 494 | 494 | unset($this->_memoryCachingArray[$key]); |
| 495 | 495 | } else { |
| 496 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
| 496 | + $this->_memoryCachingCounter=$this->_memoryCachingCounter + 1; |
|
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | */ |
| 507 | 507 | function _setFileName($id, $group) |
| 508 | 508 | { |
| 509 | - if ($this->_fileNameProtection) { |
|
| 510 | - $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
| 509 | + if($this->_fileNameProtection) { |
|
| 510 | + $this->_file=($this->_cacheDir.'cache_'.md5($group).'_' |
|
| 511 | 511 | .md5($id)); |
| 512 | 512 | } else { |
| 513 | - $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
| 513 | + $this->_file=$this->_cacheDir.'cache_'.$group.'_'.$id; |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
@@ -527,23 +527,23 @@ discard block |
||
| 527 | 527 | */ |
| 528 | 528 | function _read() |
| 529 | 529 | { |
| 530 | - $fp = @fopen($this->_file, "rb"); |
|
| 531 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 532 | - if ($fp) { |
|
| 530 | + $fp=@fopen($this->_file, "rb"); |
|
| 531 | + if($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 532 | + if($fp) { |
|
| 533 | 533 | // because the filesize can be cached by PHP itself... |
| 534 | 534 | clearstatcache(); |
| 535 | - $length = @filesize($this->_file); |
|
| 536 | - if ($this->_readControl) { |
|
| 537 | - $hashControl = @fread($fp, 32); |
|
| 538 | - $length = $length - 32; |
|
| 535 | + $length=@filesize($this->_file); |
|
| 536 | + if($this->_readControl) { |
|
| 537 | + $hashControl=@fread($fp, 32); |
|
| 538 | + $length=$length - 32; |
|
| 539 | 539 | } |
| 540 | - $data = @fread($fp, $length); |
|
| 541 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 540 | + $data=@fread($fp, $length); |
|
| 541 | + if($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 542 | 542 | @fclose($fp); |
| 543 | - if ($this->_readControl) { |
|
| 544 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
| 545 | - if ($hashData != $hashControl) { |
|
| 546 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 543 | + if($this->_readControl) { |
|
| 544 | + $hashData=$this->_hash($data, $this->_readControlType); |
|
| 545 | + if($hashData!=$hashControl) { |
|
| 546 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | } |
@@ -562,15 +562,15 @@ discard block |
||
| 562 | 562 | */ |
| 563 | 563 | function _write($data) |
| 564 | 564 | { |
| 565 | - $fp = @fopen($this->_file, "wb"); |
|
| 566 | - if ($fp) { |
|
| 567 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 568 | - if ($this->_readControl) { |
|
| 565 | + $fp=@fopen($this->_file, "wb"); |
|
| 566 | + if($fp) { |
|
| 567 | + if($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 568 | + if($this->_readControl) { |
|
| 569 | 569 | @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
| 570 | 570 | } |
| 571 | - $len = strlen($data); |
|
| 571 | + $len=strlen($data); |
|
| 572 | 572 | @fwrite($fp, $data, $len); |
| 573 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 573 | + if($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 574 | 574 | @fclose($fp); |
| 575 | 575 | return true; |
| 576 | 576 | } |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | function _writeAndControl($data) |
| 590 | 590 | { |
| 591 | 591 | $this->_write($data); |
| 592 | - $dataRead = $this->_read($data); |
|
| 592 | + $dataRead=$this->_read($data); |
|
| 593 | 593 | return ($dataRead==$data); |
| 594 | 594 | } |
| 595 | 595 | |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | function _hash($data, $controlType) |
| 605 | 605 | { |
| 606 | - switch ($controlType) { |
|
| 606 | + switch($controlType) { |
|
| 607 | 607 | case 'md5': |
| 608 | 608 | return md5($data); |
| 609 | 609 | case 'crc32': |
@@ -224,6 +224,9 @@ discard block |
||
| 224 | 224 | return $v_block; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | + /** |
|
| 228 | + * @param double $p_len |
|
| 229 | + */ |
|
| 227 | 230 | private function _jumpBlock($p_len=null) |
| 228 | 231 | { |
| 229 | 232 | if (is_resource($this->_file)) { |
@@ -317,6 +320,12 @@ discard block |
||
| 317 | 320 | return true; |
| 318 | 321 | } |
| 319 | 322 | |
| 323 | + /** |
|
| 324 | + * @param string $p_path |
|
| 325 | + * @param string $p_mode |
|
| 326 | + * @param integer $p_file_list |
|
| 327 | + * @param string $p_remove_path |
|
| 328 | + */ |
|
| 320 | 329 | protected function _extractList($p_path, &$p_list_detail, $p_mode, |
| 321 | 330 | $p_file_list, $p_remove_path) |
| 322 | 331 | { |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function __construct($p_tarname) |
| 62 | 62 | { |
| 63 | - $this->_tarname = $p_tarname; |
|
| 63 | + $this->_tarname=$p_tarname; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function __destruct() |
| 67 | 67 | { |
| 68 | 68 | $this->_close(); |
| 69 | 69 | // ----- Look for a local copy to delete |
| 70 | - if ($this->_temp_tarname != '') |
|
| 70 | + if($this->_temp_tarname!='') |
|
| 71 | 71 | @unlink($this->_temp_tarname); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function extractModify($p_path, $p_remove_path) |
| 112 | 112 | { |
| 113 | - $v_result = true; |
|
| 114 | - $v_list_detail = array(); |
|
| 113 | + $v_result=true; |
|
| 114 | + $v_list_detail=array(); |
|
| 115 | 115 | |
| 116 | - if ($v_result = $this->_openRead()) { |
|
| 117 | - $v_result = $this->_extractList($p_path, $v_list_detail, |
|
| 116 | + if($v_result=$this->_openRead()) { |
|
| 117 | + $v_result=$this->_extractList($p_path, $v_list_detail, |
|
| 118 | 118 | "complete", 0, $p_remove_path); |
| 119 | 119 | $this->_close(); |
| 120 | 120 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | private function _isArchive($p_filename=null) |
| 131 | 131 | { |
| 132 | - if ($p_filename == null) { |
|
| 133 | - $p_filename = $this->_tarname; |
|
| 132 | + if($p_filename==null) { |
|
| 133 | + $p_filename=$this->_tarname; |
|
| 134 | 134 | } |
| 135 | 135 | clearstatcache(); |
| 136 | 136 | return @is_file($p_filename); |
@@ -138,39 +138,39 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | private function _openRead() |
| 140 | 140 | { |
| 141 | - if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
| 141 | + if(strtolower(substr($this->_tarname, 0, 7))=='http://') { |
|
| 142 | 142 | |
| 143 | 143 | // ----- Look if a local copy need to be done |
| 144 | - if ($this->_temp_tarname == '') { |
|
| 145 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
| 146 | - if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
| 144 | + if($this->_temp_tarname=='') { |
|
| 145 | + $this->_temp_tarname=uniqid('tar').'.tmp'; |
|
| 146 | + if(!$v_file_from=@fopen($this->_tarname, 'rb')) { |
|
| 147 | 147 | $this->_error('Unable to open in read mode \'' |
| 148 | 148 | .$this->_tarname.'\''); |
| 149 | - $this->_temp_tarname = ''; |
|
| 149 | + $this->_temp_tarname=''; |
|
| 150 | 150 | return false; |
| 151 | 151 | } |
| 152 | - if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
| 152 | + if(!$v_file_to=@fopen($this->_temp_tarname, 'wb')) { |
|
| 153 | 153 | $this->_error('Unable to open in write mode \'' |
| 154 | 154 | .$this->_temp_tarname.'\''); |
| 155 | - $this->_temp_tarname = ''; |
|
| 155 | + $this->_temp_tarname=''; |
|
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
| 158 | + while($v_data=@fread($v_file_from, 1024)) |
|
| 159 | 159 | @fwrite($v_file_to, $v_data); |
| 160 | 160 | @fclose($v_file_from); |
| 161 | 161 | @fclose($v_file_to); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // ----- File to open if the local copy |
| 165 | - $v_filename = $this->_temp_tarname; |
|
| 165 | + $v_filename=$this->_temp_tarname; |
|
| 166 | 166 | |
| 167 | 167 | } else |
| 168 | 168 | // ----- File to open if the normal Tar file |
| 169 | - $v_filename = $this->_tarname; |
|
| 169 | + $v_filename=$this->_tarname; |
|
| 170 | 170 | |
| 171 | - $this->_file = @fopen($v_filename, "rb"); |
|
| 171 | + $this->_file=@fopen($v_filename, "rb"); |
|
| 172 | 172 | |
| 173 | - if ($this->_file == 0) { |
|
| 173 | + if($this->_file==0) { |
|
| 174 | 174 | $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
| 175 | 175 | return false; |
| 176 | 176 | } |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | private function _close() |
| 182 | 182 | { |
| 183 | 183 | //if (isset($this->_file)) { |
| 184 | - if (is_resource($this->_file)) |
|
| 184 | + if(is_resource($this->_file)) |
|
| 185 | 185 | { |
| 186 | 186 | @fclose($this->_file); |
| 187 | - $this->_file = 0; |
|
| 187 | + $this->_file=0; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // ----- Look if a local copy need to be erase |
| 191 | 191 | // Note that it might be interesting to keep the url for a time : ToDo |
| 192 | - if ($this->_temp_tarname != '') { |
|
| 192 | + if($this->_temp_tarname!='') { |
|
| 193 | 193 | @unlink($this->_temp_tarname); |
| 194 | - $this->_temp_tarname = ''; |
|
| 194 | + $this->_temp_tarname=''; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return true; |
@@ -202,76 +202,76 @@ discard block |
||
| 202 | 202 | $this->_close(); |
| 203 | 203 | |
| 204 | 204 | // ----- Look for a local copy |
| 205 | - if ($this->_temp_tarname != '') { |
|
| 205 | + if($this->_temp_tarname!='') { |
|
| 206 | 206 | // ----- Remove the local copy but not the remote tarname |
| 207 | 207 | @unlink($this->_temp_tarname); |
| 208 | - $this->_temp_tarname = ''; |
|
| 208 | + $this->_temp_tarname=''; |
|
| 209 | 209 | } else { |
| 210 | 210 | // ----- Remove the local tarname file |
| 211 | 211 | @unlink($this->_tarname); |
| 212 | 212 | } |
| 213 | - $this->_tarname = ''; |
|
| 213 | + $this->_tarname=''; |
|
| 214 | 214 | |
| 215 | 215 | return true; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | private function _readBlock() |
| 219 | 219 | { |
| 220 | - $v_block = null; |
|
| 221 | - if (is_resource($this->_file)) { |
|
| 222 | - $v_block = @fread($this->_file, 512); |
|
| 220 | + $v_block=null; |
|
| 221 | + if(is_resource($this->_file)) { |
|
| 222 | + $v_block=@fread($this->_file, 512); |
|
| 223 | 223 | } |
| 224 | 224 | return $v_block; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | private function _jumpBlock($p_len=null) |
| 228 | 228 | { |
| 229 | - if (is_resource($this->_file)) { |
|
| 230 | - if ($p_len === null) |
|
| 231 | - $p_len = 1; |
|
| 229 | + if(is_resource($this->_file)) { |
|
| 230 | + if($p_len===null) |
|
| 231 | + $p_len=1; |
|
| 232 | 232 | |
| 233 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
| 233 | + @fseek($this->_file, @ftell($this->_file) + ($p_len * 512)); |
|
| 234 | 234 | } |
| 235 | 235 | return true; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | private function _readHeader($v_binary_data, &$v_header) |
| 239 | 239 | { |
| 240 | - if (strlen($v_binary_data)==0) { |
|
| 241 | - $v_header['filename'] = ''; |
|
| 240 | + if(strlen($v_binary_data)==0) { |
|
| 241 | + $v_header['filename']=''; |
|
| 242 | 242 | return true; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if (strlen($v_binary_data) != 512) { |
|
| 246 | - $v_header['filename'] = ''; |
|
| 245 | + if(strlen($v_binary_data)!=512) { |
|
| 246 | + $v_header['filename']=''; |
|
| 247 | 247 | $this->_error('Invalid block size : '.strlen($v_binary_data)); |
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // ----- Calculate the checksum |
| 252 | - $v_checksum = 0; |
|
| 252 | + $v_checksum=0; |
|
| 253 | 253 | // ..... First part of the header |
| 254 | - for ($i=0; $i<148; $i++) |
|
| 255 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 254 | + for($i=0; $i < 148; $i++) |
|
| 255 | + $v_checksum+=ord(substr($v_binary_data, $i, 1)); |
|
| 256 | 256 | // ..... Ignore the checksum value and replace it by ' ' (space) |
| 257 | - for ($i=148; $i<156; $i++) |
|
| 258 | - $v_checksum += ord(' '); |
|
| 257 | + for($i=148; $i < 156; $i++) |
|
| 258 | + $v_checksum+=ord(' '); |
|
| 259 | 259 | // ..... Last part of the header |
| 260 | - for ($i=156; $i<512; $i++) |
|
| 261 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 260 | + for($i=156; $i < 512; $i++) |
|
| 261 | + $v_checksum+=ord(substr($v_binary_data, $i, 1)); |
|
| 262 | 262 | |
| 263 | - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
| 263 | + $v_data=unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
| 264 | 264 | ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
| 265 | 265 | ."a32uname/a32gname/a8devmajor/a8devminor", |
| 266 | 266 | $v_binary_data); |
| 267 | 267 | |
| 268 | 268 | // ----- Extract the checksum |
| 269 | - $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
| 270 | - if ($v_header['checksum'] != $v_checksum) { |
|
| 271 | - $v_header['filename'] = ''; |
|
| 269 | + $v_header['checksum']=OctDec(trim($v_data['checksum'])); |
|
| 270 | + if($v_header['checksum']!=$v_checksum) { |
|
| 271 | + $v_header['filename']=''; |
|
| 272 | 272 | |
| 273 | 273 | // ----- Look for last block (empty block) |
| 274 | - if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
| 274 | + if(($v_checksum==256) && ($v_header['checksum']==0)) |
|
| 275 | 275 | return true; |
| 276 | 276 | |
| 277 | 277 | $this->_error('Invalid checksum for file "'.$v_data['filename'] |
@@ -281,38 +281,38 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // ----- Extract the properties |
| 284 | - $v_header['filename'] = trim($v_data['filename']); |
|
| 285 | - $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
| 286 | - $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
| 287 | - $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
| 288 | - $v_header['size'] = OctDec(trim($v_data['size'])); |
|
| 289 | - $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
| 290 | - if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
| 291 | - $v_header['size'] = 0; |
|
| 284 | + $v_header['filename']=trim($v_data['filename']); |
|
| 285 | + $v_header['mode']=OctDec(trim($v_data['mode'])); |
|
| 286 | + $v_header['uid']=OctDec(trim($v_data['uid'])); |
|
| 287 | + $v_header['gid']=OctDec(trim($v_data['gid'])); |
|
| 288 | + $v_header['size']=OctDec(trim($v_data['size'])); |
|
| 289 | + $v_header['mtime']=OctDec(trim($v_data['mtime'])); |
|
| 290 | + if(($v_header['typeflag']=$v_data['typeflag'])=="5") { |
|
| 291 | + $v_header['size']=0; |
|
| 292 | 292 | } |
| 293 | 293 | return true; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | private function _readLongHeader(&$v_header) |
| 297 | 297 | { |
| 298 | - $v_filename = ''; |
|
| 299 | - $n = floor($v_header['size']/512); |
|
| 300 | - for ($i=0; $i<$n; $i++) { |
|
| 301 | - $v_content = $this->_readBlock(); |
|
| 302 | - $v_filename .= $v_content; |
|
| 298 | + $v_filename=''; |
|
| 299 | + $n=floor($v_header['size'] / 512); |
|
| 300 | + for($i=0; $i < $n; $i++) { |
|
| 301 | + $v_content=$this->_readBlock(); |
|
| 302 | + $v_filename.=$v_content; |
|
| 303 | 303 | } |
| 304 | - if (($v_header['size'] % 512) != 0) { |
|
| 305 | - $v_content = $this->_readBlock(); |
|
| 306 | - $v_filename .= $v_content; |
|
| 304 | + if(($v_header['size'] % 512)!=0) { |
|
| 305 | + $v_content=$this->_readBlock(); |
|
| 306 | + $v_filename.=$v_content; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // ----- Read the next header |
| 310 | - $v_binary_data = $this->_readBlock(); |
|
| 310 | + $v_binary_data=$this->_readBlock(); |
|
| 311 | 311 | |
| 312 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 312 | + if(!$this->_readHeader($v_binary_data, $v_header)) |
|
| 313 | 313 | return false; |
| 314 | 314 | |
| 315 | - $v_header['filename'] = $v_filename; |
|
| 315 | + $v_header['filename']=$v_filename; |
|
| 316 | 316 | |
| 317 | 317 | return true; |
| 318 | 318 | } |
@@ -321,34 +321,34 @@ discard block |
||
| 321 | 321 | $p_file_list, $p_remove_path) |
| 322 | 322 | { |
| 323 | 323 | $v_result=true; |
| 324 | - $v_nb = 0; |
|
| 325 | - $v_extract_all = true; |
|
| 326 | - $v_listing = false; |
|
| 327 | - |
|
| 328 | - $p_path = $this->_translateWinPath($p_path, false); |
|
| 329 | - if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
| 330 | - && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
| 331 | - $p_path = "./".$p_path; |
|
| 324 | + $v_nb=0; |
|
| 325 | + $v_extract_all=true; |
|
| 326 | + $v_listing=false; |
|
| 327 | + |
|
| 328 | + $p_path=$this->_translateWinPath($p_path, false); |
|
| 329 | + if($p_path=='' || (substr($p_path, 0, 1)!='/' |
|
| 330 | + && substr($p_path, 0, 3)!="../" && !strpos($p_path, ':'))) { |
|
| 331 | + $p_path="./".$p_path; |
|
| 332 | 332 | } |
| 333 | - $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
| 333 | + $p_remove_path=$this->_translateWinPath($p_remove_path); |
|
| 334 | 334 | |
| 335 | 335 | // ----- Look for path to remove format (should end by /) |
| 336 | - if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
| 337 | - $p_remove_path .= '/'; |
|
| 338 | - $p_remove_path_size = strlen($p_remove_path); |
|
| 336 | + if(($p_remove_path!='') && (substr($p_remove_path, -1)!='/')) |
|
| 337 | + $p_remove_path.='/'; |
|
| 338 | + $p_remove_path_size=strlen($p_remove_path); |
|
| 339 | 339 | |
| 340 | - switch ($p_mode) { |
|
| 340 | + switch($p_mode) { |
|
| 341 | 341 | case "complete" : |
| 342 | - $v_extract_all = true; |
|
| 343 | - $v_listing = false; |
|
| 342 | + $v_extract_all=true; |
|
| 343 | + $v_listing=false; |
|
| 344 | 344 | break; |
| 345 | 345 | case "partial" : |
| 346 | - $v_extract_all = false; |
|
| 347 | - $v_listing = false; |
|
| 346 | + $v_extract_all=false; |
|
| 347 | + $v_listing=false; |
|
| 348 | 348 | break; |
| 349 | 349 | case "list" : |
| 350 | - $v_extract_all = false; |
|
| 351 | - $v_listing = true; |
|
| 350 | + $v_extract_all=false; |
|
| 351 | + $v_listing=true; |
|
| 352 | 352 | break; |
| 353 | 353 | default : |
| 354 | 354 | $this->_error('Invalid extract mode ('.$p_mode.')'); |
@@ -357,103 +357,103 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | clearstatcache(); |
| 359 | 359 | |
| 360 | - while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
| 360 | + while(strlen($v_binary_data=$this->_readBlock())!=0) |
|
| 361 | 361 | { |
| 362 | - $v_extract_file = false; |
|
| 363 | - $v_extraction_stopped = 0; |
|
| 362 | + $v_extract_file=false; |
|
| 363 | + $v_extraction_stopped=0; |
|
| 364 | 364 | |
| 365 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 365 | + if(!$this->_readHeader($v_binary_data, $v_header)) |
|
| 366 | 366 | return false; |
| 367 | 367 | |
| 368 | - if ($v_header['filename'] == '') { |
|
| 368 | + if($v_header['filename']=='') { |
|
| 369 | 369 | continue; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // ----- Look for long filename |
| 373 | - if ($v_header['typeflag'] == 'L') { |
|
| 374 | - if (!$this->_readLongHeader($v_header)) |
|
| 373 | + if($v_header['typeflag']=='L') { |
|
| 374 | + if(!$this->_readLongHeader($v_header)) |
|
| 375 | 375 | return false; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
| 378 | + if((!$v_extract_all) && (is_array($p_file_list))) { |
|
| 379 | 379 | // ----- By default no unzip if the file is not found |
| 380 | - $v_extract_file = false; |
|
| 380 | + $v_extract_file=false; |
|
| 381 | 381 | |
| 382 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
| 382 | + for($i=0; $i < sizeof($p_file_list); $i++) { |
|
| 383 | 383 | // ----- Look if it is a directory |
| 384 | - if (substr($p_file_list[$i], -1) == '/') { |
|
| 384 | + if(substr($p_file_list[$i], -1)=='/') { |
|
| 385 | 385 | // ----- Look if the directory is in the filename path |
| 386 | - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
| 386 | + if((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
| 387 | 387 | && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
| 388 | 388 | == $p_file_list[$i])) { |
| 389 | - $v_extract_file = true; |
|
| 389 | + $v_extract_file=true; |
|
| 390 | 390 | break; |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // ----- It is a file, so compare the file names |
| 395 | - elseif ($p_file_list[$i] == $v_header['filename']) { |
|
| 396 | - $v_extract_file = true; |
|
| 395 | + elseif($p_file_list[$i]==$v_header['filename']) { |
|
| 396 | + $v_extract_file=true; |
|
| 397 | 397 | break; |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | } else { |
| 401 | - $v_extract_file = true; |
|
| 401 | + $v_extract_file=true; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | // ----- Look if this file need to be extracted |
| 405 | - if (($v_extract_file) && (!$v_listing)) |
|
| 405 | + if(($v_extract_file) && (!$v_listing)) |
|
| 406 | 406 | { |
| 407 | - if (($p_remove_path != '') |
|
| 407 | + if(($p_remove_path!='') |
|
| 408 | 408 | && (substr($v_header['filename'], 0, $p_remove_path_size) |
| 409 | 409 | == $p_remove_path)) |
| 410 | - $v_header['filename'] = substr($v_header['filename'], |
|
| 410 | + $v_header['filename']=substr($v_header['filename'], |
|
| 411 | 411 | $p_remove_path_size); |
| 412 | - if (($p_path != './') && ($p_path != '/')) { |
|
| 413 | - while (substr($p_path, -1) == '/') |
|
| 414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 412 | + if(($p_path!='./') && ($p_path!='/')) { |
|
| 413 | + while(substr($p_path, -1)=='/') |
|
| 414 | + $p_path=substr($p_path, 0, strlen($p_path) - 1); |
|
| 415 | 415 | |
| 416 | - if (substr($v_header['filename'], 0, 1) == '/') |
|
| 417 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
| 416 | + if(substr($v_header['filename'], 0, 1)=='/') |
|
| 417 | + $v_header['filename']=$p_path.$v_header['filename']; |
|
| 418 | 418 | else |
| 419 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
| 419 | + $v_header['filename']=$p_path.'/'.$v_header['filename']; |
|
| 420 | 420 | } |
| 421 | - if (file_exists($v_header['filename'])) { |
|
| 422 | - if ( (@is_dir($v_header['filename'])) |
|
| 423 | - && ($v_header['typeflag'] == '')) { |
|
| 421 | + if(file_exists($v_header['filename'])) { |
|
| 422 | + if((@is_dir($v_header['filename'])) |
|
| 423 | + && ($v_header['typeflag']=='')) { |
|
| 424 | 424 | $this->_error('File '.$v_header['filename'] |
| 425 | 425 | .' already exists as a directory'); |
| 426 | 426 | return false; |
| 427 | 427 | } |
| 428 | - if ( ($this->_isArchive($v_header['filename'])) |
|
| 429 | - && ($v_header['typeflag'] == "5")) { |
|
| 428 | + if(($this->_isArchive($v_header['filename'])) |
|
| 429 | + && ($v_header['typeflag']=="5")) { |
|
| 430 | 430 | $this->_error('Directory '.$v_header['filename'] |
| 431 | 431 | .' already exists as a file'); |
| 432 | 432 | return false; |
| 433 | 433 | } |
| 434 | - if (!is_writeable($v_header['filename'])) { |
|
| 434 | + if(!is_writeable($v_header['filename'])) { |
|
| 435 | 435 | $this->_error('File '.$v_header['filename'] |
| 436 | 436 | .' already exists and is write protected'); |
| 437 | 437 | return false; |
| 438 | 438 | } |
| 439 | - if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
| 439 | + if(filemtime($v_header['filename']) > $v_header['mtime']) { |
|
| 440 | 440 | // To be completed : An error or silent no replace ? |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // ----- Check the directory availability and create it if necessary |
| 445 | - elseif (($v_result |
|
| 446 | - = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
| 447 | - ?$v_header['filename'] |
|
| 448 | - :dirname($v_header['filename'])))) != 1) { |
|
| 445 | + elseif(($v_result |
|
| 446 | + = $this->_dirCheck(($v_header['typeflag']=="5" |
|
| 447 | + ? $v_header['filename'] |
|
| 448 | + :dirname($v_header['filename']))))!=1) { |
|
| 449 | 449 | $this->_error('Unable to create path for '.$v_header['filename']); |
| 450 | 450 | return false; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - if ($v_extract_file) { |
|
| 454 | - if ($v_header['typeflag'] == "5") { |
|
| 455 | - if (!@file_exists($v_header['filename'])) { |
|
| 456 | - if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
| 453 | + if($v_extract_file) { |
|
| 454 | + if($v_header['typeflag']=="5") { |
|
| 455 | + if(!@file_exists($v_header['filename'])) { |
|
| 456 | + if(!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
| 457 | 457 | $this->_error('Unable to create directory {' |
| 458 | 458 | .$v_header['filename'].'}'); |
| 459 | 459 | return false; |
@@ -461,18 +461,18 @@ discard block |
||
| 461 | 461 | chmod($v_header['filename'], PRADO_CHMOD); |
| 462 | 462 | } |
| 463 | 463 | } else { |
| 464 | - if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
| 464 | + if(($v_dest_file=@fopen($v_header['filename'], "wb"))==0) { |
|
| 465 | 465 | $this->_error('Error while opening {'.$v_header['filename'] |
| 466 | 466 | .'} in write binary mode'); |
| 467 | 467 | return false; |
| 468 | 468 | } else { |
| 469 | - $n = floor($v_header['size']/512); |
|
| 470 | - for ($i=0; $i<$n; $i++) { |
|
| 471 | - $v_content = $this->_readBlock(); |
|
| 469 | + $n=floor($v_header['size'] / 512); |
|
| 470 | + for($i=0; $i < $n; $i++) { |
|
| 471 | + $v_content=$this->_readBlock(); |
|
| 472 | 472 | fwrite($v_dest_file, $v_content, 512); |
| 473 | 473 | } |
| 474 | - if (($v_header['size'] % 512) != 0) { |
|
| 475 | - $v_content = $this->_readBlock(); |
|
| 474 | + if(($v_header['size'] % 512)!=0) { |
|
| 475 | + $v_content=$this->_readBlock(); |
|
| 476 | 476 | fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
| 477 | 477 | } |
| 478 | 478 | |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | |
| 487 | 487 | // ----- Check the file size |
| 488 | 488 | clearstatcache(); |
| 489 | - if (filesize($v_header['filename']) != $v_header['size']) { |
|
| 489 | + if(filesize($v_header['filename'])!=$v_header['size']) { |
|
| 490 | 490 | $this->_error('Extracted file '.$v_header['filename'] |
| 491 | 491 | .' does not have the correct file size \'' |
| 492 | 492 | .filesize($v_header['filename']) |
@@ -496,10 +496,10 @@ discard block |
||
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | } else { |
| 499 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 499 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
| 500 | 500 | } |
| 501 | 501 | } else { |
| 502 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 502 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /* TBC : Seems to be unused ... |
@@ -509,15 +509,15 @@ discard block |
||
| 509 | 509 | $v_end_of_file = @feof($this->_file); |
| 510 | 510 | */ |
| 511 | 511 | |
| 512 | - if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
| 512 | + if($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
| 513 | 513 | // ----- Log extracted files |
| 514 | - if (($v_file_dir = dirname($v_header['filename'])) |
|
| 514 | + if(($v_file_dir=dirname($v_header['filename'])) |
|
| 515 | 515 | == $v_header['filename']) |
| 516 | - $v_file_dir = ''; |
|
| 517 | - if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
| 518 | - $v_file_dir = '/'; |
|
| 516 | + $v_file_dir=''; |
|
| 517 | + if((substr($v_header['filename'], 0, 1)=='/') && ($v_file_dir=='')) |
|
| 518 | + $v_file_dir='/'; |
|
| 519 | 519 | |
| 520 | - $p_list_detail[$v_nb++] = $v_header; |
|
| 520 | + $p_list_detail[$v_nb++]=$v_header; |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
@@ -534,36 +534,36 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | protected function _dirCheck($p_dir) |
| 536 | 536 | { |
| 537 | - if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
| 537 | + if((@is_dir($p_dir)) || ($p_dir=='')) |
|
| 538 | 538 | return true; |
| 539 | 539 | |
| 540 | - $p_parent_dir = dirname($p_dir); |
|
| 540 | + $p_parent_dir=dirname($p_dir); |
|
| 541 | 541 | |
| 542 | - if (($p_parent_dir != $p_dir) && |
|
| 543 | - ($p_parent_dir != '') && |
|
| 542 | + if(($p_parent_dir!=$p_dir) && |
|
| 543 | + ($p_parent_dir!='') && |
|
| 544 | 544 | (!$this->_dirCheck($p_parent_dir))) |
| 545 | 545 | return false; |
| 546 | 546 | |
| 547 | - if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
| 547 | + if(!@mkdir($p_dir, PRADO_CHMOD)) { |
|
| 548 | 548 | $this->_error("Unable to create directory '$p_dir'"); |
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | - chmod($p_dir,PRADO_CHMOD); |
|
| 551 | + chmod($p_dir, PRADO_CHMOD); |
|
| 552 | 552 | |
| 553 | 553 | return true; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
| 557 | 557 | { |
| 558 | - if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
| 558 | + if(substr(PHP_OS, 0, 3)=='WIN') { |
|
| 559 | 559 | // ----- Look for potential disk letter |
| 560 | - if ( ($p_remove_disk_letter) |
|
| 561 | - && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 562 | - $p_path = substr($p_path, $v_position+1); |
|
| 560 | + if(($p_remove_disk_letter) |
|
| 561 | + && (($v_position=strpos($p_path, ':'))!=false)) { |
|
| 562 | + $p_path=substr($p_path, $v_position + 1); |
|
| 563 | 563 | } |
| 564 | 564 | // ----- Change potential windows directory separator |
| 565 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 566 | - $p_path = strtr($p_path, '\\', '/'); |
|
| 565 | + if((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1)=='\\')) { |
|
| 566 | + $p_path=strtr($p_path, '\\', '/'); |
|
| 567 | 567 | } |
| 568 | 568 | } |
| 569 | 569 | return $p_path; |
@@ -155,8 +155,9 @@ discard block |
||
| 155 | 155 | $this->_temp_tarname = ''; |
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
| 159 | - @fwrite($v_file_to, $v_data); |
|
| 158 | + while ($v_data = @fread($v_file_from, 1024)) { |
|
| 159 | + @fwrite($v_file_to, $v_data); |
|
| 160 | + } |
|
| 160 | 161 | @fclose($v_file_from); |
| 161 | 162 | @fclose($v_file_to); |
| 162 | 163 | } |
@@ -410,8 +411,9 @@ discard block |
||
| 410 | 411 | $v_header['filename'] = substr($v_header['filename'], |
| 411 | 412 | $p_remove_path_size); |
| 412 | 413 | if (($p_path != './') && ($p_path != '/')) { |
| 413 | - while (substr($p_path, -1) == '/') |
|
| 414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 414 | + while (substr($p_path, -1) == '/') { |
|
| 415 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 416 | + } |
|
| 415 | 417 | |
| 416 | 418 | if (substr($v_header['filename'], 0, 1) == '/') |
| 417 | 419 | $v_header['filename'] = $p_path.$v_header['filename']; |
@@ -37,537 +37,537 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class TTarFileExtractor |
| 39 | 39 | { |
| 40 | - /** |
|
| 41 | - * @var string Name of the Tar |
|
| 42 | - */ |
|
| 43 | - private $_tarname=''; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var file descriptor |
|
| 47 | - */ |
|
| 48 | - private $_file=0; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
| 52 | - */ |
|
| 53 | - private $_temp_tarname=''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Archive_Tar Class constructor. This flavour of the constructor only |
|
| 57 | - * declare a new Archive_Tar object, identifying it by the name of the |
|
| 58 | - * tar file. |
|
| 59 | - * |
|
| 60 | - * @param string $p_tarname The name of the tar archive to create |
|
| 61 | - * @access public |
|
| 62 | - */ |
|
| 63 | - public function __construct($p_tarname) |
|
| 64 | - { |
|
| 65 | - $this->_tarname = $p_tarname; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function __destruct() |
|
| 69 | - { |
|
| 70 | - $this->_close(); |
|
| 71 | - // ----- Look for a local copy to delete |
|
| 72 | - if ($this->_temp_tarname != '') |
|
| 73 | - @unlink($this->_temp_tarname); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function extract($p_path='') |
|
| 77 | - { |
|
| 78 | - return $this->extractModify($p_path, ''); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * This method extract all the content of the archive in the directory |
|
| 83 | - * indicated by $p_path. When relevant the memorized path of the |
|
| 84 | - * files/dir can be modified by removing the $p_remove_path path at the |
|
| 85 | - * beginning of the file/dir path. |
|
| 86 | - * While extracting a file, if the directory path does not exists it is |
|
| 87 | - * created. |
|
| 88 | - * While extracting a file, if the file already exists it is replaced |
|
| 89 | - * without looking for last modification date. |
|
| 90 | - * While extracting a file, if the file already exists and is write |
|
| 91 | - * protected, the extraction is aborted. |
|
| 92 | - * While extracting a file, if a directory with the same name already |
|
| 93 | - * exists, the extraction is aborted. |
|
| 94 | - * While extracting a directory, if a file with the same name already |
|
| 95 | - * exists, the extraction is aborted. |
|
| 96 | - * While extracting a file/directory if the destination directory exist |
|
| 97 | - * and is write protected, or does not exist but can not be created, |
|
| 98 | - * the extraction is aborted. |
|
| 99 | - * If after extraction an extracted file does not show the correct |
|
| 100 | - * stored file size, the extraction is aborted. |
|
| 101 | - * When the extraction is aborted, a PEAR error text is set and false |
|
| 102 | - * is returned. However the result can be a partial extraction that may |
|
| 103 | - * need to be manually cleaned. |
|
| 104 | - * |
|
| 105 | - * @param string $p_path The path of the directory where the |
|
| 106 | - * files/dir need to by extracted. |
|
| 107 | - * @param string $p_remove_path Part of the memorized path that can be |
|
| 108 | - * removed if present at the beginning of |
|
| 109 | - * the file/dir path. |
|
| 110 | - * @return boolean true on success, false on error. |
|
| 111 | - * @access public |
|
| 112 | - */ |
|
| 113 | - protected function extractModify($p_path, $p_remove_path) |
|
| 114 | - { |
|
| 115 | - $v_result = true; |
|
| 116 | - $v_list_detail = array(); |
|
| 117 | - |
|
| 118 | - if ($v_result = $this->_openRead()) { |
|
| 119 | - $v_result = $this->_extractList($p_path, $v_list_detail, |
|
| 120 | - "complete", 0, $p_remove_path); |
|
| 121 | - $this->_close(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $v_result; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - protected function _error($p_message) |
|
| 128 | - { |
|
| 40 | + /** |
|
| 41 | + * @var string Name of the Tar |
|
| 42 | + */ |
|
| 43 | + private $_tarname=''; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var file descriptor |
|
| 47 | + */ |
|
| 48 | + private $_file=0; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
| 52 | + */ |
|
| 53 | + private $_temp_tarname=''; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Archive_Tar Class constructor. This flavour of the constructor only |
|
| 57 | + * declare a new Archive_Tar object, identifying it by the name of the |
|
| 58 | + * tar file. |
|
| 59 | + * |
|
| 60 | + * @param string $p_tarname The name of the tar archive to create |
|
| 61 | + * @access public |
|
| 62 | + */ |
|
| 63 | + public function __construct($p_tarname) |
|
| 64 | + { |
|
| 65 | + $this->_tarname = $p_tarname; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function __destruct() |
|
| 69 | + { |
|
| 70 | + $this->_close(); |
|
| 71 | + // ----- Look for a local copy to delete |
|
| 72 | + if ($this->_temp_tarname != '') |
|
| 73 | + @unlink($this->_temp_tarname); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function extract($p_path='') |
|
| 77 | + { |
|
| 78 | + return $this->extractModify($p_path, ''); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * This method extract all the content of the archive in the directory |
|
| 83 | + * indicated by $p_path. When relevant the memorized path of the |
|
| 84 | + * files/dir can be modified by removing the $p_remove_path path at the |
|
| 85 | + * beginning of the file/dir path. |
|
| 86 | + * While extracting a file, if the directory path does not exists it is |
|
| 87 | + * created. |
|
| 88 | + * While extracting a file, if the file already exists it is replaced |
|
| 89 | + * without looking for last modification date. |
|
| 90 | + * While extracting a file, if the file already exists and is write |
|
| 91 | + * protected, the extraction is aborted. |
|
| 92 | + * While extracting a file, if a directory with the same name already |
|
| 93 | + * exists, the extraction is aborted. |
|
| 94 | + * While extracting a directory, if a file with the same name already |
|
| 95 | + * exists, the extraction is aborted. |
|
| 96 | + * While extracting a file/directory if the destination directory exist |
|
| 97 | + * and is write protected, or does not exist but can not be created, |
|
| 98 | + * the extraction is aborted. |
|
| 99 | + * If after extraction an extracted file does not show the correct |
|
| 100 | + * stored file size, the extraction is aborted. |
|
| 101 | + * When the extraction is aborted, a PEAR error text is set and false |
|
| 102 | + * is returned. However the result can be a partial extraction that may |
|
| 103 | + * need to be manually cleaned. |
|
| 104 | + * |
|
| 105 | + * @param string $p_path The path of the directory where the |
|
| 106 | + * files/dir need to by extracted. |
|
| 107 | + * @param string $p_remove_path Part of the memorized path that can be |
|
| 108 | + * removed if present at the beginning of |
|
| 109 | + * the file/dir path. |
|
| 110 | + * @return boolean true on success, false on error. |
|
| 111 | + * @access public |
|
| 112 | + */ |
|
| 113 | + protected function extractModify($p_path, $p_remove_path) |
|
| 114 | + { |
|
| 115 | + $v_result = true; |
|
| 116 | + $v_list_detail = array(); |
|
| 117 | + |
|
| 118 | + if ($v_result = $this->_openRead()) { |
|
| 119 | + $v_result = $this->_extractList($p_path, $v_list_detail, |
|
| 120 | + "complete", 0, $p_remove_path); |
|
| 121 | + $this->_close(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $v_result; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + protected function _error($p_message) |
|
| 128 | + { |
|
| 129 | 129 | throw new \Exception($p_message); |
| 130 | - } |
|
| 131 | - |
|
| 132 | - private function _isArchive($p_filename=null) |
|
| 133 | - { |
|
| 134 | - if ($p_filename == null) { |
|
| 135 | - $p_filename = $this->_tarname; |
|
| 136 | - } |
|
| 137 | - clearstatcache(); |
|
| 138 | - return @is_file($p_filename); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - private function _openRead() |
|
| 142 | - { |
|
| 143 | - if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
| 144 | - |
|
| 145 | - // ----- Look if a local copy need to be done |
|
| 146 | - if ($this->_temp_tarname == '') { |
|
| 147 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
| 148 | - if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
| 149 | - $this->_error('Unable to open in read mode \'' |
|
| 150 | - .$this->_tarname.'\''); |
|
| 151 | - $this->_temp_tarname = ''; |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
| 155 | - $this->_error('Unable to open in write mode \'' |
|
| 156 | - .$this->_temp_tarname.'\''); |
|
| 157 | - $this->_temp_tarname = ''; |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - while ($v_data = @fread($v_file_from, 1024)) |
|
| 161 | - @fwrite($v_file_to, $v_data); |
|
| 162 | - @fclose($v_file_from); |
|
| 163 | - @fclose($v_file_to); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // ----- File to open if the local copy |
|
| 167 | - $v_filename = $this->_temp_tarname; |
|
| 168 | - |
|
| 169 | - } else |
|
| 170 | - // ----- File to open if the normal Tar file |
|
| 171 | - $v_filename = $this->_tarname; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + private function _isArchive($p_filename=null) |
|
| 133 | + { |
|
| 134 | + if ($p_filename == null) { |
|
| 135 | + $p_filename = $this->_tarname; |
|
| 136 | + } |
|
| 137 | + clearstatcache(); |
|
| 138 | + return @is_file($p_filename); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + private function _openRead() |
|
| 142 | + { |
|
| 143 | + if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
| 144 | + |
|
| 145 | + // ----- Look if a local copy need to be done |
|
| 146 | + if ($this->_temp_tarname == '') { |
|
| 147 | + $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
| 148 | + if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
| 149 | + $this->_error('Unable to open in read mode \'' |
|
| 150 | + .$this->_tarname.'\''); |
|
| 151 | + $this->_temp_tarname = ''; |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
| 155 | + $this->_error('Unable to open in write mode \'' |
|
| 156 | + .$this->_temp_tarname.'\''); |
|
| 157 | + $this->_temp_tarname = ''; |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + while ($v_data = @fread($v_file_from, 1024)) |
|
| 161 | + @fwrite($v_file_to, $v_data); |
|
| 162 | + @fclose($v_file_from); |
|
| 163 | + @fclose($v_file_to); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // ----- File to open if the local copy |
|
| 167 | + $v_filename = $this->_temp_tarname; |
|
| 168 | + |
|
| 169 | + } else |
|
| 170 | + // ----- File to open if the normal Tar file |
|
| 171 | + $v_filename = $this->_tarname; |
|
| 172 | 172 | |
| 173 | 173 | $this->_file = @fopen($v_filename, "rb"); |
| 174 | 174 | |
| 175 | - if ($this->_file == 0) { |
|
| 176 | - $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 175 | + if ($this->_file == 0) { |
|
| 176 | + $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - return true; |
|
| 181 | - } |
|
| 180 | + return true; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - private function _close() |
|
| 184 | - { |
|
| 185 | - //if (isset($this->_file)) { |
|
| 186 | - if (is_resource($this->_file)) |
|
| 183 | + private function _close() |
|
| 184 | + { |
|
| 185 | + //if (isset($this->_file)) { |
|
| 186 | + if (is_resource($this->_file)) |
|
| 187 | 187 | { |
| 188 | - @fclose($this->_file); |
|
| 189 | - $this->_file = 0; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // ----- Look if a local copy need to be erase |
|
| 193 | - // Note that it might be interesting to keep the url for a time : ToDo |
|
| 194 | - if ($this->_temp_tarname != '') { |
|
| 195 | - @unlink($this->_temp_tarname); |
|
| 196 | - $this->_temp_tarname = ''; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - private function _cleanFile() |
|
| 203 | - { |
|
| 204 | - $this->_close(); |
|
| 205 | - |
|
| 206 | - // ----- Look for a local copy |
|
| 207 | - if ($this->_temp_tarname != '') { |
|
| 208 | - // ----- Remove the local copy but not the remote tarname |
|
| 209 | - @unlink($this->_temp_tarname); |
|
| 210 | - $this->_temp_tarname = ''; |
|
| 211 | - } else { |
|
| 212 | - // ----- Remove the local tarname file |
|
| 213 | - @unlink($this->_tarname); |
|
| 214 | - } |
|
| 215 | - $this->_tarname = ''; |
|
| 216 | - |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - private function _readBlock() |
|
| 221 | - { |
|
| 222 | - $v_block = null; |
|
| 223 | - if (is_resource($this->_file)) { |
|
| 224 | - $v_block = @fread($this->_file, 512); |
|
| 225 | - } |
|
| 226 | - return $v_block; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - private function _jumpBlock($p_len=null) |
|
| 230 | - { |
|
| 231 | - if (is_resource($this->_file)) { |
|
| 232 | - if ($p_len === null) |
|
| 233 | - $p_len = 1; |
|
| 234 | - |
|
| 235 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
| 236 | - } |
|
| 237 | - return true; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - private function _readHeader($v_binary_data, &$v_header) |
|
| 241 | - { |
|
| 242 | - if (strlen($v_binary_data)==0) { |
|
| 243 | - $v_header['filename'] = ''; |
|
| 244 | - return true; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if (strlen($v_binary_data) != 512) { |
|
| 248 | - $v_header['filename'] = ''; |
|
| 249 | - $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // ----- Calculate the checksum |
|
| 254 | - $v_checksum = 0; |
|
| 255 | - // ..... First part of the header |
|
| 256 | - for ($i=0; $i<148; $i++) |
|
| 257 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 258 | - // ..... Ignore the checksum value and replace it by ' ' (space) |
|
| 259 | - for ($i=148; $i<156; $i++) |
|
| 260 | - $v_checksum += ord(' '); |
|
| 261 | - // ..... Last part of the header |
|
| 262 | - for ($i=156; $i<512; $i++) |
|
| 263 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 264 | - |
|
| 265 | - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
| 266 | - ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
| 188 | + @fclose($this->_file); |
|
| 189 | + $this->_file = 0; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // ----- Look if a local copy need to be erase |
|
| 193 | + // Note that it might be interesting to keep the url for a time : ToDo |
|
| 194 | + if ($this->_temp_tarname != '') { |
|
| 195 | + @unlink($this->_temp_tarname); |
|
| 196 | + $this->_temp_tarname = ''; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + private function _cleanFile() |
|
| 203 | + { |
|
| 204 | + $this->_close(); |
|
| 205 | + |
|
| 206 | + // ----- Look for a local copy |
|
| 207 | + if ($this->_temp_tarname != '') { |
|
| 208 | + // ----- Remove the local copy but not the remote tarname |
|
| 209 | + @unlink($this->_temp_tarname); |
|
| 210 | + $this->_temp_tarname = ''; |
|
| 211 | + } else { |
|
| 212 | + // ----- Remove the local tarname file |
|
| 213 | + @unlink($this->_tarname); |
|
| 214 | + } |
|
| 215 | + $this->_tarname = ''; |
|
| 216 | + |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + private function _readBlock() |
|
| 221 | + { |
|
| 222 | + $v_block = null; |
|
| 223 | + if (is_resource($this->_file)) { |
|
| 224 | + $v_block = @fread($this->_file, 512); |
|
| 225 | + } |
|
| 226 | + return $v_block; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + private function _jumpBlock($p_len=null) |
|
| 230 | + { |
|
| 231 | + if (is_resource($this->_file)) { |
|
| 232 | + if ($p_len === null) |
|
| 233 | + $p_len = 1; |
|
| 234 | + |
|
| 235 | + @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
| 236 | + } |
|
| 237 | + return true; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + private function _readHeader($v_binary_data, &$v_header) |
|
| 241 | + { |
|
| 242 | + if (strlen($v_binary_data)==0) { |
|
| 243 | + $v_header['filename'] = ''; |
|
| 244 | + return true; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if (strlen($v_binary_data) != 512) { |
|
| 248 | + $v_header['filename'] = ''; |
|
| 249 | + $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // ----- Calculate the checksum |
|
| 254 | + $v_checksum = 0; |
|
| 255 | + // ..... First part of the header |
|
| 256 | + for ($i=0; $i<148; $i++) |
|
| 257 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 258 | + // ..... Ignore the checksum value and replace it by ' ' (space) |
|
| 259 | + for ($i=148; $i<156; $i++) |
|
| 260 | + $v_checksum += ord(' '); |
|
| 261 | + // ..... Last part of the header |
|
| 262 | + for ($i=156; $i<512; $i++) |
|
| 263 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
| 264 | + |
|
| 265 | + $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
| 266 | + ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
| 267 | 267 | ."a32uname/a32gname/a8devmajor/a8devminor", |
| 268 | 268 | $v_binary_data); |
| 269 | 269 | |
| 270 | - // ----- Extract the checksum |
|
| 271 | - $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
| 272 | - if ($v_header['checksum'] != $v_checksum) { |
|
| 273 | - $v_header['filename'] = ''; |
|
| 270 | + // ----- Extract the checksum |
|
| 271 | + $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
| 272 | + if ($v_header['checksum'] != $v_checksum) { |
|
| 273 | + $v_header['filename'] = ''; |
|
| 274 | 274 | |
| 275 | - // ----- Look for last block (empty block) |
|
| 276 | - if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
| 277 | - return true; |
|
| 275 | + // ----- Look for last block (empty block) |
|
| 276 | + if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
| 277 | + return true; |
|
| 278 | 278 | |
| 279 | - $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
| 280 | - .'" : '.$v_checksum.' calculated, ' |
|
| 279 | + $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
| 280 | + .'" : '.$v_checksum.' calculated, ' |
|
| 281 | 281 | .$v_header['checksum'].' expected'); |
| 282 | - return false; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - // ----- Extract the properties |
|
| 286 | - $v_header['filename'] = trim($v_data['filename']); |
|
| 287 | - $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
| 288 | - $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
| 289 | - $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
| 290 | - $v_header['size'] = OctDec(trim($v_data['size'])); |
|
| 291 | - $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
| 292 | - if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
| 293 | - $v_header['size'] = 0; |
|
| 294 | - } |
|
| 295 | - return true; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - private function _readLongHeader(&$v_header) |
|
| 299 | - { |
|
| 300 | - $v_filename = ''; |
|
| 301 | - $n = floor($v_header['size']/512); |
|
| 302 | - for ($i=0; $i<$n; $i++) { |
|
| 303 | - $v_content = $this->_readBlock(); |
|
| 304 | - $v_filename .= $v_content; |
|
| 305 | - } |
|
| 306 | - if (($v_header['size'] % 512) != 0) { |
|
| 307 | - $v_content = $this->_readBlock(); |
|
| 308 | - $v_filename .= $v_content; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // ----- Read the next header |
|
| 312 | - $v_binary_data = $this->_readBlock(); |
|
| 313 | - |
|
| 314 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 315 | - return false; |
|
| 316 | - |
|
| 317 | - $v_header['filename'] = $v_filename; |
|
| 318 | - |
|
| 319 | - return true; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
| 323 | - $p_file_list, $p_remove_path) |
|
| 324 | - { |
|
| 325 | - $v_result=true; |
|
| 326 | - $v_nb = 0; |
|
| 327 | - $v_extract_all = true; |
|
| 328 | - $v_listing = false; |
|
| 329 | - |
|
| 330 | - $p_path = $this->_translateWinPath($p_path, false); |
|
| 331 | - if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
| 332 | - && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
| 333 | - $p_path = "./".$p_path; |
|
| 334 | - } |
|
| 335 | - $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
| 336 | - |
|
| 337 | - // ----- Look for path to remove format (should end by /) |
|
| 338 | - if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
| 339 | - $p_remove_path .= '/'; |
|
| 340 | - $p_remove_path_size = strlen($p_remove_path); |
|
| 341 | - |
|
| 342 | - switch ($p_mode) { |
|
| 343 | - case "complete" : |
|
| 344 | - $v_extract_all = true; |
|
| 345 | - $v_listing = false; |
|
| 346 | - break; |
|
| 347 | - case "partial" : |
|
| 348 | - $v_extract_all = false; |
|
| 349 | - $v_listing = false; |
|
| 350 | - break; |
|
| 351 | - case "list" : |
|
| 352 | - $v_extract_all = false; |
|
| 353 | - $v_listing = true; |
|
| 354 | - break; |
|
| 355 | - default : |
|
| 356 | - $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
| 357 | - return false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - clearstatcache(); |
|
| 361 | - |
|
| 362 | - while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
| 363 | - { |
|
| 364 | - $v_extract_file = false; |
|
| 365 | - $v_extraction_stopped = 0; |
|
| 366 | - |
|
| 367 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 368 | - return false; |
|
| 369 | - |
|
| 370 | - if ($v_header['filename'] == '') { |
|
| 371 | - continue; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // ----- Look for long filename |
|
| 375 | - if ($v_header['typeflag'] == 'L') { |
|
| 376 | - if (!$this->_readLongHeader($v_header)) |
|
| 377 | - return false; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
| 381 | - // ----- By default no unzip if the file is not found |
|
| 382 | - $v_extract_file = false; |
|
| 383 | - |
|
| 384 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
| 385 | - // ----- Look if it is a directory |
|
| 386 | - if (substr($p_file_list[$i], -1) == '/') { |
|
| 387 | - // ----- Look if the directory is in the filename path |
|
| 388 | - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
| 389 | - && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
| 390 | - == $p_file_list[$i])) { |
|
| 391 | - $v_extract_file = true; |
|
| 392 | - break; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - // ----- It is a file, so compare the file names |
|
| 397 | - elseif ($p_file_list[$i] == $v_header['filename']) { |
|
| 398 | - $v_extract_file = true; |
|
| 399 | - break; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } else { |
|
| 403 | - $v_extract_file = true; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // ----- Look if this file need to be extracted |
|
| 407 | - if (($v_extract_file) && (!$v_listing)) |
|
| 408 | - { |
|
| 409 | - if (($p_remove_path != '') |
|
| 410 | - && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
| 411 | - == $p_remove_path)) |
|
| 412 | - $v_header['filename'] = substr($v_header['filename'], |
|
| 413 | - $p_remove_path_size); |
|
| 414 | - if (($p_path != './') && ($p_path != '/')) { |
|
| 415 | - while (substr($p_path, -1) == '/') |
|
| 416 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 417 | - |
|
| 418 | - if (substr($v_header['filename'], 0, 1) == '/') |
|
| 419 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
| 420 | - else |
|
| 421 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
| 422 | - } |
|
| 423 | - if (file_exists($v_header['filename'])) { |
|
| 424 | - if ( (@is_dir($v_header['filename'])) |
|
| 425 | - && ($v_header['typeflag'] == '')) { |
|
| 426 | - $this->_error('File '.$v_header['filename'] |
|
| 427 | - .' already exists as a directory'); |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if ( ($this->_isArchive($v_header['filename'])) |
|
| 431 | - && ($v_header['typeflag'] == "5")) { |
|
| 432 | - $this->_error('Directory '.$v_header['filename'] |
|
| 433 | - .' already exists as a file'); |
|
| 434 | - return false; |
|
| 435 | - } |
|
| 436 | - if (!is_writeable($v_header['filename'])) { |
|
| 437 | - $this->_error('File '.$v_header['filename'] |
|
| 438 | - .' already exists and is write protected'); |
|
| 439 | - return false; |
|
| 440 | - } |
|
| 441 | - if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
| 442 | - // To be completed : An error or silent no replace ? |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // ----- Check the directory availability and create it if necessary |
|
| 447 | - elseif (($v_result |
|
| 448 | - = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
| 449 | - ?$v_header['filename'] |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + // ----- Extract the properties |
|
| 286 | + $v_header['filename'] = trim($v_data['filename']); |
|
| 287 | + $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
| 288 | + $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
| 289 | + $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
| 290 | + $v_header['size'] = OctDec(trim($v_data['size'])); |
|
| 291 | + $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
| 292 | + if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
| 293 | + $v_header['size'] = 0; |
|
| 294 | + } |
|
| 295 | + return true; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + private function _readLongHeader(&$v_header) |
|
| 299 | + { |
|
| 300 | + $v_filename = ''; |
|
| 301 | + $n = floor($v_header['size']/512); |
|
| 302 | + for ($i=0; $i<$n; $i++) { |
|
| 303 | + $v_content = $this->_readBlock(); |
|
| 304 | + $v_filename .= $v_content; |
|
| 305 | + } |
|
| 306 | + if (($v_header['size'] % 512) != 0) { |
|
| 307 | + $v_content = $this->_readBlock(); |
|
| 308 | + $v_filename .= $v_content; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // ----- Read the next header |
|
| 312 | + $v_binary_data = $this->_readBlock(); |
|
| 313 | + |
|
| 314 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 315 | + return false; |
|
| 316 | + |
|
| 317 | + $v_header['filename'] = $v_filename; |
|
| 318 | + |
|
| 319 | + return true; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
| 323 | + $p_file_list, $p_remove_path) |
|
| 324 | + { |
|
| 325 | + $v_result=true; |
|
| 326 | + $v_nb = 0; |
|
| 327 | + $v_extract_all = true; |
|
| 328 | + $v_listing = false; |
|
| 329 | + |
|
| 330 | + $p_path = $this->_translateWinPath($p_path, false); |
|
| 331 | + if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
| 332 | + && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
| 333 | + $p_path = "./".$p_path; |
|
| 334 | + } |
|
| 335 | + $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
| 336 | + |
|
| 337 | + // ----- Look for path to remove format (should end by /) |
|
| 338 | + if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
| 339 | + $p_remove_path .= '/'; |
|
| 340 | + $p_remove_path_size = strlen($p_remove_path); |
|
| 341 | + |
|
| 342 | + switch ($p_mode) { |
|
| 343 | + case "complete" : |
|
| 344 | + $v_extract_all = true; |
|
| 345 | + $v_listing = false; |
|
| 346 | + break; |
|
| 347 | + case "partial" : |
|
| 348 | + $v_extract_all = false; |
|
| 349 | + $v_listing = false; |
|
| 350 | + break; |
|
| 351 | + case "list" : |
|
| 352 | + $v_extract_all = false; |
|
| 353 | + $v_listing = true; |
|
| 354 | + break; |
|
| 355 | + default : |
|
| 356 | + $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + clearstatcache(); |
|
| 361 | + |
|
| 362 | + while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
| 363 | + { |
|
| 364 | + $v_extract_file = false; |
|
| 365 | + $v_extraction_stopped = 0; |
|
| 366 | + |
|
| 367 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
| 368 | + return false; |
|
| 369 | + |
|
| 370 | + if ($v_header['filename'] == '') { |
|
| 371 | + continue; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // ----- Look for long filename |
|
| 375 | + if ($v_header['typeflag'] == 'L') { |
|
| 376 | + if (!$this->_readLongHeader($v_header)) |
|
| 377 | + return false; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
| 381 | + // ----- By default no unzip if the file is not found |
|
| 382 | + $v_extract_file = false; |
|
| 383 | + |
|
| 384 | + for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
| 385 | + // ----- Look if it is a directory |
|
| 386 | + if (substr($p_file_list[$i], -1) == '/') { |
|
| 387 | + // ----- Look if the directory is in the filename path |
|
| 388 | + if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
| 389 | + && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
| 390 | + == $p_file_list[$i])) { |
|
| 391 | + $v_extract_file = true; |
|
| 392 | + break; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + // ----- It is a file, so compare the file names |
|
| 397 | + elseif ($p_file_list[$i] == $v_header['filename']) { |
|
| 398 | + $v_extract_file = true; |
|
| 399 | + break; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } else { |
|
| 403 | + $v_extract_file = true; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // ----- Look if this file need to be extracted |
|
| 407 | + if (($v_extract_file) && (!$v_listing)) |
|
| 408 | + { |
|
| 409 | + if (($p_remove_path != '') |
|
| 410 | + && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
| 411 | + == $p_remove_path)) |
|
| 412 | + $v_header['filename'] = substr($v_header['filename'], |
|
| 413 | + $p_remove_path_size); |
|
| 414 | + if (($p_path != './') && ($p_path != '/')) { |
|
| 415 | + while (substr($p_path, -1) == '/') |
|
| 416 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 417 | + |
|
| 418 | + if (substr($v_header['filename'], 0, 1) == '/') |
|
| 419 | + $v_header['filename'] = $p_path.$v_header['filename']; |
|
| 420 | + else |
|
| 421 | + $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
| 422 | + } |
|
| 423 | + if (file_exists($v_header['filename'])) { |
|
| 424 | + if ( (@is_dir($v_header['filename'])) |
|
| 425 | + && ($v_header['typeflag'] == '')) { |
|
| 426 | + $this->_error('File '.$v_header['filename'] |
|
| 427 | + .' already exists as a directory'); |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if ( ($this->_isArchive($v_header['filename'])) |
|
| 431 | + && ($v_header['typeflag'] == "5")) { |
|
| 432 | + $this->_error('Directory '.$v_header['filename'] |
|
| 433 | + .' already exists as a file'); |
|
| 434 | + return false; |
|
| 435 | + } |
|
| 436 | + if (!is_writeable($v_header['filename'])) { |
|
| 437 | + $this->_error('File '.$v_header['filename'] |
|
| 438 | + .' already exists and is write protected'); |
|
| 439 | + return false; |
|
| 440 | + } |
|
| 441 | + if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
| 442 | + // To be completed : An error or silent no replace ? |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // ----- Check the directory availability and create it if necessary |
|
| 447 | + elseif (($v_result |
|
| 448 | + = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
| 449 | + ?$v_header['filename'] |
|
| 450 | 450 | :dirname($v_header['filename'])))) != 1) { |
| 451 | - $this->_error('Unable to create path for '.$v_header['filename']); |
|
| 452 | - return false; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if ($v_extract_file) { |
|
| 456 | - if ($v_header['typeflag'] == "5") { |
|
| 457 | - if (!@file_exists($v_header['filename'])) { |
|
| 458 | - if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
| 459 | - $this->_error('Unable to create directory {' |
|
| 460 | - .$v_header['filename'].'}'); |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - chmod($v_header['filename'], PRADO_CHMOD); |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
| 467 | - $this->_error('Error while opening {'.$v_header['filename'] |
|
| 468 | - .'} in write binary mode'); |
|
| 469 | - return false; |
|
| 470 | - } else { |
|
| 471 | - $n = floor($v_header['size']/512); |
|
| 472 | - for ($i=0; $i<$n; $i++) { |
|
| 473 | - $v_content = $this->_readBlock(); |
|
| 474 | - fwrite($v_dest_file, $v_content, 512); |
|
| 475 | - } |
|
| 476 | - if (($v_header['size'] % 512) != 0) { |
|
| 477 | - $v_content = $this->_readBlock(); |
|
| 478 | - fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - @fclose($v_dest_file); |
|
| 482 | - |
|
| 483 | - // ----- Change the file mode, mtime |
|
| 484 | - @touch($v_header['filename'], $v_header['mtime']); |
|
| 485 | - // To be completed |
|
| 486 | - //chmod($v_header[filename], DecOct($v_header[mode])); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // ----- Check the file size |
|
| 490 | - clearstatcache(); |
|
| 491 | - if (filesize($v_header['filename']) != $v_header['size']) { |
|
| 492 | - $this->_error('Extracted file '.$v_header['filename'] |
|
| 493 | - .' does not have the correct file size \'' |
|
| 451 | + $this->_error('Unable to create path for '.$v_header['filename']); |
|
| 452 | + return false; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($v_extract_file) { |
|
| 456 | + if ($v_header['typeflag'] == "5") { |
|
| 457 | + if (!@file_exists($v_header['filename'])) { |
|
| 458 | + if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
| 459 | + $this->_error('Unable to create directory {' |
|
| 460 | + .$v_header['filename'].'}'); |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + chmod($v_header['filename'], PRADO_CHMOD); |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
| 467 | + $this->_error('Error while opening {'.$v_header['filename'] |
|
| 468 | + .'} in write binary mode'); |
|
| 469 | + return false; |
|
| 470 | + } else { |
|
| 471 | + $n = floor($v_header['size']/512); |
|
| 472 | + for ($i=0; $i<$n; $i++) { |
|
| 473 | + $v_content = $this->_readBlock(); |
|
| 474 | + fwrite($v_dest_file, $v_content, 512); |
|
| 475 | + } |
|
| 476 | + if (($v_header['size'] % 512) != 0) { |
|
| 477 | + $v_content = $this->_readBlock(); |
|
| 478 | + fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + @fclose($v_dest_file); |
|
| 482 | + |
|
| 483 | + // ----- Change the file mode, mtime |
|
| 484 | + @touch($v_header['filename'], $v_header['mtime']); |
|
| 485 | + // To be completed |
|
| 486 | + //chmod($v_header[filename], DecOct($v_header[mode])); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // ----- Check the file size |
|
| 490 | + clearstatcache(); |
|
| 491 | + if (filesize($v_header['filename']) != $v_header['size']) { |
|
| 492 | + $this->_error('Extracted file '.$v_header['filename'] |
|
| 493 | + .' does not have the correct file size \'' |
|
| 494 | 494 | .filesize($v_header['filename']) |
| 495 | 495 | .'\' ('.$v_header['size'] |
| 496 | 496 | .' expected). Archive may be corrupted.'); |
| 497 | - return false; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } else { |
|
| 501 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 502 | - } |
|
| 503 | - } else { |
|
| 504 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /* TBC : Seems to be unused ... |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } else { |
|
| 501 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 502 | + } |
|
| 503 | + } else { |
|
| 504 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /* TBC : Seems to be unused ... |
|
| 508 | 508 | if ($this->_compress) |
| 509 | 509 | $v_end_of_file = @gzeof($this->_file); |
| 510 | 510 | else |
| 511 | 511 | $v_end_of_file = @feof($this->_file); |
| 512 | 512 | */ |
| 513 | 513 | |
| 514 | - if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
| 515 | - // ----- Log extracted files |
|
| 516 | - if (($v_file_dir = dirname($v_header['filename'])) |
|
| 517 | - == $v_header['filename']) |
|
| 518 | - $v_file_dir = ''; |
|
| 519 | - if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
| 520 | - $v_file_dir = '/'; |
|
| 521 | - |
|
| 522 | - $p_list_detail[$v_nb++] = $v_header; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - return true; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Check if a directory exists and create it (including parent |
|
| 531 | - * dirs) if not. |
|
| 532 | - * |
|
| 533 | - * @param string $p_dir directory to check |
|
| 534 | - * |
|
| 535 | - * @return bool true if the directory exists or was created |
|
| 536 | - */ |
|
| 537 | - protected function _dirCheck($p_dir) |
|
| 538 | - { |
|
| 539 | - if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
| 540 | - return true; |
|
| 541 | - |
|
| 542 | - $p_parent_dir = dirname($p_dir); |
|
| 543 | - |
|
| 544 | - if (($p_parent_dir != $p_dir) && |
|
| 545 | - ($p_parent_dir != '') && |
|
| 546 | - (!$this->_dirCheck($p_parent_dir))) |
|
| 547 | - return false; |
|
| 548 | - |
|
| 549 | - if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
| 550 | - $this->_error("Unable to create directory '$p_dir'"); |
|
| 551 | - return false; |
|
| 552 | - } |
|
| 553 | - chmod($p_dir,PRADO_CHMOD); |
|
| 554 | - |
|
| 555 | - return true; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 559 | - { |
|
| 560 | - if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
| 561 | - // ----- Look for potential disk letter |
|
| 562 | - if ( ($p_remove_disk_letter) |
|
| 563 | - && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 564 | - $p_path = substr($p_path, $v_position+1); |
|
| 565 | - } |
|
| 566 | - // ----- Change potential windows directory separator |
|
| 567 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 568 | - $p_path = strtr($p_path, '\\', '/'); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - return $p_path; |
|
| 572 | - } |
|
| 514 | + if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
| 515 | + // ----- Log extracted files |
|
| 516 | + if (($v_file_dir = dirname($v_header['filename'])) |
|
| 517 | + == $v_header['filename']) |
|
| 518 | + $v_file_dir = ''; |
|
| 519 | + if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
| 520 | + $v_file_dir = '/'; |
|
| 521 | + |
|
| 522 | + $p_list_detail[$v_nb++] = $v_header; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + return true; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Check if a directory exists and create it (including parent |
|
| 531 | + * dirs) if not. |
|
| 532 | + * |
|
| 533 | + * @param string $p_dir directory to check |
|
| 534 | + * |
|
| 535 | + * @return bool true if the directory exists or was created |
|
| 536 | + */ |
|
| 537 | + protected function _dirCheck($p_dir) |
|
| 538 | + { |
|
| 539 | + if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
| 540 | + return true; |
|
| 541 | + |
|
| 542 | + $p_parent_dir = dirname($p_dir); |
|
| 543 | + |
|
| 544 | + if (($p_parent_dir != $p_dir) && |
|
| 545 | + ($p_parent_dir != '') && |
|
| 546 | + (!$this->_dirCheck($p_parent_dir))) |
|
| 547 | + return false; |
|
| 548 | + |
|
| 549 | + if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
| 550 | + $this->_error("Unable to create directory '$p_dir'"); |
|
| 551 | + return false; |
|
| 552 | + } |
|
| 553 | + chmod($p_dir,PRADO_CHMOD); |
|
| 554 | + |
|
| 555 | + return true; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 559 | + { |
|
| 560 | + if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
| 561 | + // ----- Look for potential disk letter |
|
| 562 | + if ( ($p_remove_disk_letter) |
|
| 563 | + && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 564 | + $p_path = substr($p_path, $v_position+1); |
|
| 565 | + } |
|
| 566 | + // ----- Change potential windows directory separator |
|
| 567 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 568 | + $p_path = strtr($p_path, '\\', '/'); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + return $p_path; |
|
| 572 | + } |
|
| 573 | 573 | } |
@@ -38,6 +38,7 @@ |
||
| 38 | 38 | /** |
| 39 | 39 | * Writes a string. |
| 40 | 40 | * @param string string to be written |
| 41 | + * @param string $str |
|
| 41 | 42 | */ |
| 42 | 43 | public function write($str) |
| 43 | 44 | { |
@@ -49,6 +49,7 @@ |
||
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @param string id of this service |
| 52 | + * @param string $value |
|
| 52 | 53 | */ |
| 53 | 54 | public function setID($value) |
| 54 | 55 | { |
@@ -98,6 +98,7 @@ |
||
| 98 | 98 | * @param integer level filter |
| 99 | 99 | * @param array category filter |
| 100 | 100 | * @param array control filter |
| 101 | + * @param integer $levels |
|
| 101 | 102 | * @return array list of messages. Each array elements represents one message |
| 102 | 103 | * with the following structure: |
| 103 | 104 | * array( |
@@ -63,16 +63,16 @@ discard block |
||
| 63 | 63 | * @param string category of the message |
| 64 | 64 | * @param string|TControl control of the message |
| 65 | 65 | */ |
| 66 | - public function log($message,$level,$category='Uncategorized', $ctl=null) |
|
| 66 | + public function log($message, $level, $category='Uncategorized', $ctl=null) |
|
| 67 | 67 | { |
| 68 | 68 | if($ctl) { |
| 69 | 69 | if($ctl instanceof TControl) |
| 70 | - $ctl = $ctl->ClientId; |
|
| 70 | + $ctl=$ctl->ClientId; |
|
| 71 | 71 | else if(!is_string($ctl)) |
| 72 | - $ctl = null; |
|
| 72 | + $ctl=null; |
|
| 73 | 73 | } else |
| 74 | - $ctl = null; |
|
| 75 | - $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl); |
|
| 74 | + $ctl=null; |
|
| 75 | + $this->_logs[]=array($message, $level, $category, microtime(true), memory_get_usage(), $ctl); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * [4] => memory in bytes |
| 109 | 109 | * [5] => control client id |
| 110 | 110 | */ |
| 111 | - public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
| 111 | + public function getLogs($levels=null, $categories=null, $controls=null, $timestamp=null) |
|
| 112 | 112 | { |
| 113 | 113 | $this->_levels=$levels; |
| 114 | 114 | $this->_categories=$categories; |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | $this->_timestamp=$timestamp; |
| 117 | 117 | if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp)) |
| 118 | 118 | return $this->_logs; |
| 119 | - $logs = $this->_logs; |
|
| 119 | + $logs=$this->_logs; |
|
| 120 | 120 | if(!empty($levels)) |
| 121 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) )); |
|
| 121 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByLevels')))); |
|
| 122 | 122 | if(!empty($categories)) |
| 123 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) )); |
|
| 123 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByCategories')))); |
|
| 124 | 124 | if(!empty($controls)) |
| 125 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) )); |
|
| 125 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByControl')))); |
|
| 126 | 126 | if(!is_null($timestamp)) |
| 127 | - $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) )); |
|
| 127 | + $logs=array_values(array_filter(array_filter($logs, array($this, 'filterByTimeStamp')))); |
|
| 128 | 128 | return $logs; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param array category filter |
| 153 | 153 | * @param array control filter |
| 154 | 154 | */ |
| 155 | - public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null) |
|
| 155 | + public function deleteLogs($levels=null, $categories=null, $controls=null, $timestamp=null) |
|
| 156 | 156 | { |
| 157 | 157 | $this->_levels=$levels; |
| 158 | 158 | $this->_categories=$categories; |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | $this->_logs=array(); |
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | - $logs = $this->_logs; |
|
| 166 | + $logs=$this->_logs; |
|
| 167 | 167 | if(!empty($levels)) |
| 168 | - $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) ); |
|
| 168 | + $logs=array_filter(array_filter($logs, array($this, 'filterByLevels'))); |
|
| 169 | 169 | if(!empty($categories)) |
| 170 | - $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) ); |
|
| 170 | + $logs=array_filter(array_filter($logs, array($this, 'filterByCategories'))); |
|
| 171 | 171 | if(!empty($controls)) |
| 172 | - $logs = array_filter( array_filter($logs,array($this,'filterByControl')) ); |
|
| 172 | + $logs=array_filter(array_filter($logs, array($this, 'filterByControl'))); |
|
| 173 | 173 | if(!is_null($timestamp)) |
| 174 | - $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ); |
|
| 175 | - $this->_logs = array_values( array_diff_key($this->_logs, $logs) ); |
|
| 174 | + $logs=array_filter(array_filter($logs, array($this, 'filterByTimeStamp'))); |
|
| 175 | + $this->_logs=array_values(array_diff_key($this->_logs, $logs)); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | foreach($this->_categories as $category) |
| 185 | 185 | { |
| 186 | 186 | // element 2 is the category |
| 187 | - if($value[2]===$category || strpos($value[2],$category.'.')===0) |
|
| 187 | + if($value[2]===$category || strpos($value[2], $category.'.')===0) |
|
| 188 | 188 | return $value; |
| 189 | 189 | } |
| 190 | 190 | return false; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | // element 5 are the control client ids |
| 213 | 213 | foreach($this->_controls as $control) |
| 214 | 214 | { |
| 215 | - if($value[5]===$control || strpos($value[5],$control)===0) |
|
| 215 | + if($value[5]===$control || strpos($value[5], $control)===0) |
|
| 216 | 216 | return $value; |
| 217 | 217 | } |
| 218 | 218 | return false; |
@@ -105,6 +105,9 @@ |
||
| 105 | 105 | * @param string RPC server URL |
| 106 | 106 | * @param array payload data |
| 107 | 107 | * @param string request mime type |
| 108 | + * @param string $serverUrl |
|
| 109 | + * @param string $mimeType |
|
| 110 | + * @return string |
|
| 108 | 111 | */ |
| 109 | 112 | protected function performRequest($serverUrl, $payload, $mimeType) |
| 110 | 113 | { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @var boolean whether the request is a notification and therefore should not care about the result (default: false) |
| 59 | 59 | */ |
| 60 | - private $_isNotification = false; |
|
| 60 | + private $_isNotification=false; |
|
| 61 | 61 | |
| 62 | 62 | // magics |
| 63 | 63 | |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | * @param string url to RPC server |
| 66 | 66 | * @param boolean whether requests are considered to be notifications (completely ignoring the response) (default: false) |
| 67 | 67 | */ |
| 68 | - public function __construct($serverUrl, $isNotification = false) |
|
| 68 | + public function __construct($serverUrl, $isNotification=false) |
|
| 69 | 69 | { |
| 70 | - $this->_serverUrl = $serverUrl; |
|
| 71 | - $this->_isNotification = TPropertyValue::ensureBoolean($isNotification); |
|
| 70 | + $this->_serverUrl=$serverUrl; |
|
| 71 | + $this->_isNotification=TPropertyValue::ensureBoolean($isNotification); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // methods |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return TRpcClient instance |
| 79 | 79 | * @throws TApplicationException if an unsupported RPC client type was specified |
| 80 | 80 | */ |
| 81 | - public static function create($type, $serverUrl, $isNotification = false) |
|
| 81 | + public static function create($type, $serverUrl, $isNotification=false) |
|
| 82 | 82 | { |
| 83 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
| 83 | + if(($_handler=constant('TRpcClientTypesEnumerable::'.strtoupper($type)))===null) |
|
| 84 | 84 | throw new TApplicationException('rpcclient_unsupported_handler'); |
| 85 | 85 | |
| 86 | 86 | return new $_handler($serverUrl, $isNotification); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function performRequest($serverUrl, $payload, $mimeType) |
| 112 | 112 | { |
| 113 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
| 113 | + if(($_response=@file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType)))===false) |
|
| 114 | 114 | throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
| 115 | 115 | |
| 116 | 116 | return $_response; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public function setIsNotification($bool) |
| 133 | 133 | { |
| 134 | - $this->_isNotification = TPropertyValue::ensureBoolean($bool); |
|
| 134 | + $this->_isNotification=TPropertyValue::ensureBoolean($bool); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -147,6 +147,6 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function setServerUrl($value) |
| 149 | 149 | { |
| 150 | - $this->_serverUrl = $value; |
|
| 150 | + $this->_serverUrl=$value; |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | \ No newline at end of file |
@@ -60,6 +60,7 @@ discard block |
||
| 60 | 60 | * Constructor, create a new date time formatter. |
| 61 | 61 | * @param string formatting pattern. |
| 62 | 62 | * @param string pattern and value charset |
| 63 | + * @param string $pattern |
|
| 63 | 64 | */ |
| 64 | 65 | public function __construct($pattern, $charset='UTF-8') |
| 65 | 66 | { |
@@ -93,6 +94,7 @@ discard block |
||
| 93 | 94 | |
| 94 | 95 | /** |
| 95 | 96 | * @param string formatting charset. |
| 97 | + * @param string $charset |
|
| 96 | 98 | */ |
| 97 | 99 | public function setCharset($charset) |
| 98 | 100 | { |
@@ -313,6 +315,7 @@ discard block |
||
| 313 | 315 | |
| 314 | 316 | /** |
| 315 | 317 | * Calculate the length of a string, may be consider iconv_strlen? |
| 318 | + * @param string $string |
|
| 316 | 319 | */ |
| 317 | 320 | private function length($string) |
| 318 | 321 | { |
@@ -338,6 +341,9 @@ discard block |
||
| 338 | 341 | |
| 339 | 342 | /** |
| 340 | 343 | * Returns true if char at position equals a particular char. |
| 344 | + * @param string $string |
|
| 345 | + * @param integer $pos |
|
| 346 | + * @param string $char |
|
| 341 | 347 | */ |
| 342 | 348 | private function charEqual($string, $pos, $char) |
| 343 | 349 | { |
@@ -350,6 +356,10 @@ discard block |
||
| 350 | 356 | * @param int starting position |
| 351 | 357 | * @param int minimum integer length |
| 352 | 358 | * @param int maximum integer length |
| 359 | + * @param string $str |
|
| 360 | + * @param integer $i |
|
| 361 | + * @param integer|null $minlength |
|
| 362 | + * @param integer|null $maxlength |
|
| 353 | 363 | * @return string integer portion of the string, null otherwise |
| 354 | 364 | */ |
| 355 | 365 | private function getInteger($str,$i,$minlength,$maxlength) |
@@ -225,8 +225,7 @@ discard block |
||
| 225 | 225 | $year = "{$date['year']}"; |
| 226 | 226 | $month = $date['mon']; |
| 227 | 227 | $day = $date['mday']; |
| 228 | - } |
|
| 229 | - else |
|
| 228 | + } else |
|
| 230 | 229 | { |
| 231 | 230 | $year = null; |
| 232 | 231 | $month = null; |
@@ -262,8 +261,7 @@ discard block |
||
| 262 | 261 | $year = $iYear + 2000; |
| 263 | 262 | } |
| 264 | 263 | $year = (int)$year; |
| 265 | - } |
|
| 266 | - elseif($token=='MM' || $token=='M') |
|
| 264 | + } elseif($token=='MM' || $token=='M') |
|
| 267 | 265 | { |
| 268 | 266 | $month=$this->getInteger($value,$i_val, |
| 269 | 267 | $this->length($token),2); |
@@ -273,8 +271,7 @@ discard block |
||
| 273 | 271 | //throw new TInvalidDataValueException('Invalid month', $value); |
| 274 | 272 | $i_val += strlen($month); |
| 275 | 273 | $month = $iMonth; |
| 276 | - } |
|
| 277 | - elseif ($token=='dd' || $token=='d') |
|
| 274 | + } elseif ($token=='dd' || $token=='d') |
|
| 278 | 275 | { |
| 279 | 276 | $day = $this->getInteger($value,$i_val, |
| 280 | 277 | $this->length($token), 2); |
@@ -284,8 +281,7 @@ discard block |
||
| 284 | 281 | //throw new TInvalidDataValueException('Invalid day', $value); |
| 285 | 282 | $i_val += strlen($day); |
| 286 | 283 | $day = $iDay; |
| 287 | - } |
|
| 288 | - else |
|
| 284 | + } else |
|
| 289 | 285 | { |
| 290 | 286 | if($this->substring($value, $i_val, $this->length($token)) != $token) |
| 291 | 287 | return null; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * Charset, default is 'UTF-8' |
| 61 | 61 | * @var string |
| 62 | 62 | */ |
| 63 | - private $charset = 'UTF-8'; |
|
| 63 | + private $charset='UTF-8'; |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Constructor, create a new date time formatter. |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function setPattern($pattern) |
| 88 | 88 | { |
| 89 | - $this->pattern = $pattern; |
|
| 89 | + $this->pattern=$pattern; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function setCharset($charset) |
| 104 | 104 | { |
| 105 | - $this->charset = $charset; |
|
| 105 | + $this->charset=$charset; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -112,17 +112,17 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function format($value) |
| 114 | 114 | { |
| 115 | - $date = $this->getDate($value); |
|
| 116 | - $bits['yyyy'] = $date['year']; |
|
| 117 | - $bits['yy'] = substr("{$date['year']}", -2); |
|
| 115 | + $date=$this->getDate($value); |
|
| 116 | + $bits['yyyy']=$date['year']; |
|
| 117 | + $bits['yy']=substr("{$date['year']}", -2); |
|
| 118 | 118 | |
| 119 | - $bits['MM'] = str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT); |
|
| 120 | - $bits['M'] = $date['mon']; |
|
| 119 | + $bits['MM']=str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT); |
|
| 120 | + $bits['M']=$date['mon']; |
|
| 121 | 121 | |
| 122 | - $bits['dd'] = str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT); |
|
| 123 | - $bits['d'] = $date['mday']; |
|
| 122 | + $bits['dd']=str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT); |
|
| 123 | + $bits['d']=$date['mday']; |
|
| 124 | 124 | |
| 125 | - $pattern = preg_replace('/M{3,4}/', 'MM', $this->pattern); |
|
| 125 | + $pattern=preg_replace('/M{3,4}/', 'MM', $this->pattern); |
|
| 126 | 126 | return str_replace(array_keys($bits), $bits, $pattern); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | public function getDayMonthYearOrdering() |
| 161 | 161 | { |
| 162 | - $ordering = array(); |
|
| 163 | - if(is_int($day= strpos($this->pattern, 'd'))) |
|
| 164 | - $ordering['day'] = $day; |
|
| 165 | - if(is_int($month= strpos($this->pattern, 'M'))) |
|
| 166 | - $ordering['month'] = $month; |
|
| 167 | - if(is_int($year= strpos($this->pattern, 'yy'))) |
|
| 168 | - $ordering['year'] = $year; |
|
| 162 | + $ordering=array(); |
|
| 163 | + if(is_int($day=strpos($this->pattern, 'd'))) |
|
| 164 | + $ordering['day']=$day; |
|
| 165 | + if(is_int($month=strpos($this->pattern, 'M'))) |
|
| 166 | + $ordering['month']=$month; |
|
| 167 | + if(is_int($year=strpos($this->pattern, 'yy'))) |
|
| 168 | + $ordering['year']=$year; |
|
| 169 | 169 | asort($ordering); |
| 170 | 170 | return array_keys($ordering); |
| 171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | private function getDate($value) |
| 179 | 179 | { |
| 180 | - $s = new TDateTimeStamp; |
|
| 180 | + $s=new TDateTimeStamp; |
|
| 181 | 181 | if(is_numeric($value)) |
| 182 | 182 | return $s->getDate($value); |
| 183 | 183 | else |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function isValidDate($value) |
| 191 | 191 | { |
| 192 | - if($value === null) { |
|
| 192 | + if($value===null) { |
|
| 193 | 193 | return false; |
| 194 | 194 | } else { |
| 195 | - return $this->parse($value, false) !== null; |
|
| 195 | + return $this->parse($value, false)!==null; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return int date time stamp |
| 203 | 203 | * @throws TInvalidDataValueException if date string is malformed. |
| 204 | 204 | */ |
| 205 | - public function parse($value,$defaultToCurrentTime=true) |
|
| 205 | + public function parse($value, $defaultToCurrentTime=true) |
|
| 206 | 206 | { |
| 207 | 207 | if(is_int($value) || is_float($value)) |
| 208 | 208 | return $value; |
@@ -211,108 +211,108 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | if(empty($this->pattern)) return time(); |
| 213 | 213 | |
| 214 | - $date = time(); |
|
| 214 | + $date=time(); |
|
| 215 | 215 | |
| 216 | 216 | if($this->length(trim($value)) < 1) |
| 217 | 217 | return $defaultToCurrentTime ? $date : null; |
| 218 | 218 | |
| 219 | - $pattern = $this->pattern; |
|
| 219 | + $pattern=$this->pattern; |
|
| 220 | 220 | |
| 221 | - $i_val = 0; |
|
| 222 | - $i_format = 0; |
|
| 223 | - $pattern_length = $this->length($pattern); |
|
| 224 | - $c = ''; |
|
| 221 | + $i_val=0; |
|
| 222 | + $i_format=0; |
|
| 223 | + $pattern_length=$this->length($pattern); |
|
| 224 | + $c=''; |
|
| 225 | 225 | $token=''; |
| 226 | 226 | $x=null; $y=null; |
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | if($defaultToCurrentTime) |
| 230 | 230 | { |
| 231 | - $year = "{$date['year']}"; |
|
| 232 | - $month = $date['mon']; |
|
| 233 | - $day = $date['mday']; |
|
| 231 | + $year="{$date['year']}"; |
|
| 232 | + $month=$date['mon']; |
|
| 233 | + $day=$date['mday']; |
|
| 234 | 234 | } |
| 235 | 235 | else |
| 236 | 236 | { |
| 237 | - $year = null; |
|
| 238 | - $month = null; |
|
| 239 | - $day = null; |
|
| 237 | + $year=null; |
|
| 238 | + $month=null; |
|
| 239 | + $day=null; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - while ($i_format < $pattern_length) |
|
| 242 | + while($i_format < $pattern_length) |
|
| 243 | 243 | { |
| 244 | - $c = $this->charAt($pattern,$i_format); |
|
| 244 | + $c=$this->charAt($pattern, $i_format); |
|
| 245 | 245 | $token=''; |
| 246 | - while ($this->charEqual($pattern, $i_format, $c) |
|
| 246 | + while($this->charEqual($pattern, $i_format, $c) |
|
| 247 | 247 | && ($i_format < $pattern_length)) |
| 248 | 248 | { |
| 249 | - $token .= $this->charAt($pattern, $i_format++); |
|
| 249 | + $token.=$this->charAt($pattern, $i_format++); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if ($token=='yyyy' || $token=='yy' || $token=='y') |
|
| 252 | + if($token=='yyyy' || $token=='yy' || $token=='y') |
|
| 253 | 253 | { |
| 254 | - if ($token=='yyyy') { $x=4;$y=4; } |
|
| 255 | - if ($token=='yy') { $x=2;$y=2; } |
|
| 256 | - if ($token=='y') { $x=2;$y=4; } |
|
| 257 | - $year = $this->getInteger($value,$i_val,$x,$y); |
|
| 258 | - if($year === null) |
|
| 254 | + if($token=='yyyy') { $x=4; $y=4; } |
|
| 255 | + if($token=='yy') { $x=2; $y=2; } |
|
| 256 | + if($token=='y') { $x=2; $y=4; } |
|
| 257 | + $year=$this->getInteger($value, $i_val, $x, $y); |
|
| 258 | + if($year===null) |
|
| 259 | 259 | return null; |
| 260 | 260 | //throw new TInvalidDataValueException('Invalid year', $value); |
| 261 | - $i_val += strlen($year); |
|
| 262 | - if(strlen($year) == 2) |
|
| 261 | + $i_val+=strlen($year); |
|
| 262 | + if(strlen($year)==2) |
|
| 263 | 263 | { |
| 264 | - $iYear = (int)$year; |
|
| 264 | + $iYear=(int) $year; |
|
| 265 | 265 | if($iYear > 70) |
| 266 | - $year = $iYear + 1900; |
|
| 266 | + $year=$iYear + 1900; |
|
| 267 | 267 | else |
| 268 | - $year = $iYear + 2000; |
|
| 268 | + $year=$iYear + 2000; |
|
| 269 | 269 | } |
| 270 | - $year = (int)$year; |
|
| 270 | + $year=(int) $year; |
|
| 271 | 271 | } |
| 272 | 272 | elseif($token=='MM' || $token=='M') |
| 273 | 273 | { |
| 274 | - $month=$this->getInteger($value,$i_val, |
|
| 275 | - $this->length($token),2); |
|
| 276 | - $iMonth = (int)$month; |
|
| 277 | - if($month === null || $iMonth < 1 || $iMonth > 12 ) |
|
| 274 | + $month=$this->getInteger($value, $i_val, |
|
| 275 | + $this->length($token), 2); |
|
| 276 | + $iMonth=(int) $month; |
|
| 277 | + if($month===null || $iMonth < 1 || $iMonth > 12) |
|
| 278 | 278 | return null; |
| 279 | 279 | //throw new TInvalidDataValueException('Invalid month', $value); |
| 280 | - $i_val += strlen($month); |
|
| 281 | - $month = $iMonth; |
|
| 280 | + $i_val+=strlen($month); |
|
| 281 | + $month=$iMonth; |
|
| 282 | 282 | } |
| 283 | - elseif ($token=='dd' || $token=='d') |
|
| 283 | + elseif($token=='dd' || $token=='d') |
|
| 284 | 284 | { |
| 285 | - $day = $this->getInteger($value,$i_val, |
|
| 285 | + $day=$this->getInteger($value, $i_val, |
|
| 286 | 286 | $this->length($token), 2); |
| 287 | - $iDay = (int)$day; |
|
| 288 | - if($day === null || $iDay < 1 || $iDay >31) |
|
| 287 | + $iDay=(int) $day; |
|
| 288 | + if($day===null || $iDay < 1 || $iDay > 31) |
|
| 289 | 289 | return null; |
| 290 | 290 | //throw new TInvalidDataValueException('Invalid day', $value); |
| 291 | - $i_val += strlen($day); |
|
| 292 | - $day = $iDay; |
|
| 291 | + $i_val+=strlen($day); |
|
| 292 | + $day=$iDay; |
|
| 293 | 293 | } |
| 294 | 294 | else |
| 295 | 295 | { |
| 296 | - if($this->substring($value, $i_val, $this->length($token)) != $token) |
|
| 296 | + if($this->substring($value, $i_val, $this->length($token))!=$token) |
|
| 297 | 297 | return null; |
| 298 | 298 | //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value); |
| 299 | 299 | else |
| 300 | - $i_val += $this->length($token); |
|
| 300 | + $i_val+=$this->length($token); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | - if ($i_val != $this->length($value)) |
|
| 303 | + if($i_val!=$this->length($value)) |
|
| 304 | 304 | return null; |
| 305 | 305 | //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); |
| 306 | - if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
|
| 306 | + if(!$defaultToCurrentTime && ($month===null || $day===null || $year===null)) |
|
| 307 | 307 | return null; |
| 308 | 308 | else |
| 309 | 309 | { |
| 310 | 310 | if(empty($year)) { |
| 311 | - $year = date('Y'); |
|
| 311 | + $year=date('Y'); |
|
| 312 | 312 | } |
| 313 | - $day = (int)$day <= 0 ? 1 : (int)$day; |
|
| 314 | - $month = (int)$month <= 0 ? 1 : (int)$month; |
|
| 315 | - $s = new TDateTimeStamp; |
|
| 313 | + $day=(int) $day <= 0 ? 1 : (int) $day; |
|
| 314 | + $month=(int) $month <= 0 ? 1 : (int) $month; |
|
| 315 | + $s=new TDateTimeStamp; |
|
| 316 | 316 | return $s->getTimeStamp(0, 0, 0, $month, $day, $year); |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | private function charEqual($string, $pos, $char) |
| 349 | 349 | { |
| 350 | - return $this->charAt($string, $pos) == $char; |
|
| 350 | + return $this->charAt($string, $pos)==$char; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -358,15 +358,15 @@ discard block |
||
| 358 | 358 | * @param int maximum integer length |
| 359 | 359 | * @return string integer portion of the string, null otherwise |
| 360 | 360 | */ |
| 361 | - private function getInteger($str,$i,$minlength,$maxlength) |
|
| 361 | + private function getInteger($str, $i, $minlength, $maxlength) |
|
| 362 | 362 | { |
| 363 | 363 | //match for digits backwards |
| 364 | - for ($x = $maxlength; $x >= $minlength; $x--) |
|
| 364 | + for($x=$maxlength; $x >= $minlength; $x--) |
|
| 365 | 365 | { |
| 366 | - $token= $this->substring($str, $i,$x); |
|
| 367 | - if ($this->length($token) < $minlength) |
|
| 366 | + $token=$this->substring($str, $i, $x); |
|
| 367 | + if($this->length($token) < $minlength) |
|
| 368 | 368 | return null; |
| 369 | - if (preg_match('/^\d+$/', $token)) |
|
| 369 | + if(preg_match('/^\d+$/', $token)) |
|
| 370 | 370 | return $token; |
| 371 | 371 | } |
| 372 | 372 | return null; |
@@ -55,6 +55,9 @@ |
||
| 55 | 55 | return self::$_output; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + /** |
|
| 59 | + * @param integer $level |
|
| 60 | + */ |
|
| 58 | 61 | private static function dumpInternal($var,$level) |
| 59 | 62 | { |
| 60 | 63 | switch(gettype($var)) |
@@ -40,27 +40,27 @@ discard block |
||
| 40 | 40 | * @param integer maximum depth that the dumper should go into the variable. Defaults to 10. |
| 41 | 41 | * @return string the string representation of the variable |
| 42 | 42 | */ |
| 43 | - public static function dump($var,$depth=10,$highlight=false) |
|
| 43 | + public static function dump($var, $depth=10, $highlight=false) |
|
| 44 | 44 | { |
| 45 | 45 | self::$_output=''; |
| 46 | 46 | self::$_objects=array(); |
| 47 | 47 | self::$_depth=$depth; |
| 48 | - self::dumpInternal($var,0); |
|
| 48 | + self::dumpInternal($var, 0); |
|
| 49 | 49 | if($highlight) |
| 50 | 50 | { |
| 51 | - $result=highlight_string("<?php\n".self::$_output,true); |
|
| 52 | - return preg_replace('/<\\?php<br \\/>/','',$result,1); |
|
| 51 | + $result=highlight_string("<?php\n".self::$_output, true); |
|
| 52 | + return preg_replace('/<\\?php<br \\/>/', '', $result, 1); |
|
| 53 | 53 | } |
| 54 | 54 | else |
| 55 | 55 | return self::$_output; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - private static function dumpInternal($var,$level) |
|
| 58 | + private static function dumpInternal($var, $level) |
|
| 59 | 59 | { |
| 60 | 60 | switch(gettype($var)) |
| 61 | 61 | { |
| 62 | 62 | case 'boolean': |
| 63 | - self::$_output.=$var?'true':'false'; |
|
| 63 | + self::$_output.=$var ? 'true' : 'false'; |
|
| 64 | 64 | break; |
| 65 | 65 | case 'integer': |
| 66 | 66 | self::$_output.="$var"; |
@@ -81,41 +81,41 @@ discard block |
||
| 81 | 81 | self::$_output.='{unknown}'; |
| 82 | 82 | break; |
| 83 | 83 | case 'array': |
| 84 | - if(self::$_depth<=$level) |
|
| 84 | + if(self::$_depth <= $level) |
|
| 85 | 85 | self::$_output.='array(...)'; |
| 86 | 86 | else if(empty($var)) |
| 87 | 87 | self::$_output.='array()'; |
| 88 | 88 | else |
| 89 | 89 | { |
| 90 | 90 | $keys=array_keys($var); |
| 91 | - $spaces=str_repeat(' ',$level*4); |
|
| 91 | + $spaces=str_repeat(' ', $level * 4); |
|
| 92 | 92 | self::$_output.="array\n".$spaces.'('; |
| 93 | 93 | foreach($keys as $key) |
| 94 | 94 | { |
| 95 | 95 | self::$_output.="\n".$spaces." [$key] => "; |
| 96 | - self::$_output.=self::dumpInternal($var[$key],$level+1); |
|
| 96 | + self::$_output.=self::dumpInternal($var[$key], $level + 1); |
|
| 97 | 97 | } |
| 98 | 98 | self::$_output.="\n".$spaces.')'; |
| 99 | 99 | } |
| 100 | 100 | break; |
| 101 | 101 | case 'object': |
| 102 | - if(($id=array_search($var,self::$_objects,true))!==false) |
|
| 103 | - self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
| 104 | - else if(self::$_depth<=$level) |
|
| 102 | + if(($id=array_search($var, self::$_objects, true))!==false) |
|
| 103 | + self::$_output.=get_class($var).'#'.($id + 1).'(...)'; |
|
| 104 | + else if(self::$_depth <= $level) |
|
| 105 | 105 | self::$_output.=get_class($var).'(...)'; |
| 106 | 106 | else |
| 107 | 107 | { |
| 108 | - $id=array_push(self::$_objects,$var); |
|
| 108 | + $id=array_push(self::$_objects, $var); |
|
| 109 | 109 | $className=get_class($var); |
| 110 | - $members=(array)$var; |
|
| 110 | + $members=(array) $var; |
|
| 111 | 111 | $keys=array_keys($members); |
| 112 | - $spaces=str_repeat(' ',$level*4); |
|
| 112 | + $spaces=str_repeat(' ', $level * 4); |
|
| 113 | 113 | self::$_output.="$className#$id\n".$spaces.'('; |
| 114 | 114 | foreach($keys as $key) |
| 115 | 115 | { |
| 116 | - $keyDisplay=strtr(trim($key),array("\0"=>':')); |
|
| 116 | + $keyDisplay=strtr(trim($key), array("\0"=>':')); |
|
| 117 | 117 | self::$_output.="\n".$spaces." [$keyDisplay] => "; |
| 118 | - self::$_output.=self::dumpInternal($members[$key],$level+1); |
|
| 118 | + self::$_output.=self::dumpInternal($members[$key], $level + 1); |
|
| 119 | 119 | } |
| 120 | 120 | self::$_output.="\n".$spaces.')'; |
| 121 | 121 | } |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | { |
| 53 | 53 | $result=highlight_string("<?php\n".self::$_output,true); |
| 54 | 54 | return preg_replace('/<\\?php<br \\/>/','',$result,1); |
| 55 | - } |
|
| 56 | - else |
|
| 55 | + } else |
|
| 57 | 56 | return self::$_output; |
| 58 | 57 | } |
| 59 | 58 | |
@@ -73,6 +73,9 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
| 75 | 75 | |
| 76 | + /** |
|
| 77 | + * @param integer $d |
|
| 78 | + */ |
|
| 76 | 79 | protected function action($d) { |
| 77 | 80 | switch($d) { |
| 78 | 81 | case 1: |
@@ -132,6 +135,9 @@ discard block |
||
| 132 | 135 | } |
| 133 | 136 | } |
| 134 | 137 | |
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 135 | 141 | protected function get() { |
| 136 | 142 | $c = $this->lookAhead; |
| 137 | 143 | $this->lookAhead = null; |
@@ -156,6 +162,9 @@ discard block |
||
| 156 | 162 | return ' '; |
| 157 | 163 | } |
| 158 | 164 | |
| 165 | + /** |
|
| 166 | + * @param string $c |
|
| 167 | + */ |
|
| 159 | 168 | protected function isAlphaNum($c) { |
| 160 | 169 | return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
| 161 | 170 | } |
@@ -191,8 +191,7 @@ discard block |
||
| 191 | 191 | default: |
| 192 | 192 | if ($this->isAlphaNum($this->b)) { |
| 193 | 193 | $this->action(1); |
| 194 | - } |
|
| 195 | - else { |
|
| 194 | + } else { |
|
| 196 | 195 | $this->action(2); |
| 197 | 196 | } |
| 198 | 197 | } |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | default: |
| 225 | 224 | if ($this->isAlphaNum($this->a)) { |
| 226 | 225 | $this->action(1); |
| 227 | - } |
|
| 228 | - else { |
|
| 226 | + } else { |
|
| 229 | 227 | $this->action(3); |
| 230 | 228 | } |
| 231 | 229 | } |
@@ -59,228 +59,228 @@ |
||
| 59 | 59 | // -- Public Static Methods -------------------------------------------------- |
| 60 | 60 | |
| 61 | 61 | public static function minify($js) { |
| 62 | - $jsmin = new JSMin($js); |
|
| 63 | - return $jsmin->min(); |
|
| 62 | + $jsmin = new JSMin($js); |
|
| 63 | + return $jsmin->min(); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // -- Public Instance Methods ------------------------------------------------ |
| 67 | 67 | |
| 68 | 68 | public function __construct($input) { |
| 69 | - $this->input = str_replace("\r\n", "\n", $input); |
|
| 70 | - $this->inputLength = strlen($this->input); |
|
| 69 | + $this->input = str_replace("\r\n", "\n", $input); |
|
| 70 | + $this->inputLength = strlen($this->input); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // -- Protected Instance Methods --------------------------------------------- |
| 74 | 74 | |
| 75 | 75 | protected function action($d) { |
| 76 | - switch($d) { |
|
| 77 | - case 1: |
|
| 78 | - $this->output .= $this->a; |
|
| 79 | - |
|
| 80 | - case 2: |
|
| 81 | - $this->a = $this->b; |
|
| 82 | - |
|
| 83 | - if ($this->a === "'" || $this->a === '"') { |
|
| 84 | - for (;;) { |
|
| 85 | - $this->output .= $this->a; |
|
| 86 | - $this->a = $this->get(); |
|
| 87 | - |
|
| 88 | - if ($this->a === $this->b) { |
|
| 89 | - break; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (ord($this->a) <= self::ORD_LF) { |
|
| 93 | - throw new JSMinException('Unterminated string literal.'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($this->a === '\\') { |
|
| 97 | - $this->output .= $this->a; |
|
| 98 | - $this->a = $this->get(); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - case 3: |
|
| 104 | - $this->b = $this->next(); |
|
| 105 | - |
|
| 106 | - if ($this->b === '/' && ( |
|
| 107 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
| 108 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
| 109 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
| 110 | - |
|
| 111 | - $this->output .= $this->a . $this->b; |
|
| 112 | - |
|
| 113 | - for (;;) { |
|
| 114 | - $this->a = $this->get(); |
|
| 115 | - |
|
| 116 | - if ($this->a === '/') { |
|
| 117 | - break; |
|
| 118 | - } elseif ($this->a === '\\') { |
|
| 119 | - $this->output .= $this->a; |
|
| 120 | - $this->a = $this->get(); |
|
| 121 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
| 122 | - throw new JSMinException('Unterminated regular expression '. |
|
| 123 | - 'literal.'); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $this->output .= $this->a; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $this->b = $this->next(); |
|
| 130 | - } |
|
| 131 | - } |
|
| 76 | + switch($d) { |
|
| 77 | + case 1: |
|
| 78 | + $this->output .= $this->a; |
|
| 79 | + |
|
| 80 | + case 2: |
|
| 81 | + $this->a = $this->b; |
|
| 82 | + |
|
| 83 | + if ($this->a === "'" || $this->a === '"') { |
|
| 84 | + for (;;) { |
|
| 85 | + $this->output .= $this->a; |
|
| 86 | + $this->a = $this->get(); |
|
| 87 | + |
|
| 88 | + if ($this->a === $this->b) { |
|
| 89 | + break; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (ord($this->a) <= self::ORD_LF) { |
|
| 93 | + throw new JSMinException('Unterminated string literal.'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($this->a === '\\') { |
|
| 97 | + $this->output .= $this->a; |
|
| 98 | + $this->a = $this->get(); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + case 3: |
|
| 104 | + $this->b = $this->next(); |
|
| 105 | + |
|
| 106 | + if ($this->b === '/' && ( |
|
| 107 | + $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
| 108 | + $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
| 109 | + $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
| 110 | + |
|
| 111 | + $this->output .= $this->a . $this->b; |
|
| 112 | + |
|
| 113 | + for (;;) { |
|
| 114 | + $this->a = $this->get(); |
|
| 115 | + |
|
| 116 | + if ($this->a === '/') { |
|
| 117 | + break; |
|
| 118 | + } elseif ($this->a === '\\') { |
|
| 119 | + $this->output .= $this->a; |
|
| 120 | + $this->a = $this->get(); |
|
| 121 | + } elseif (ord($this->a) <= self::ORD_LF) { |
|
| 122 | + throw new JSMinException('Unterminated regular expression '. |
|
| 123 | + 'literal.'); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $this->output .= $this->a; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $this->b = $this->next(); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | protected function get() { |
| 135 | - $c = $this->lookAhead; |
|
| 136 | - $this->lookAhead = null; |
|
| 137 | - |
|
| 138 | - if ($c === null) { |
|
| 139 | - if ($this->inputIndex < $this->inputLength) { |
|
| 140 | - $c = $this->input[$this->inputIndex]; |
|
| 141 | - $this->inputIndex += 1; |
|
| 142 | - } else { |
|
| 143 | - $c = null; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if ($c === "\r") { |
|
| 148 | - return "\n"; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
| 152 | - return $c; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return ' '; |
|
| 135 | + $c = $this->lookAhead; |
|
| 136 | + $this->lookAhead = null; |
|
| 137 | + |
|
| 138 | + if ($c === null) { |
|
| 139 | + if ($this->inputIndex < $this->inputLength) { |
|
| 140 | + $c = $this->input[$this->inputIndex]; |
|
| 141 | + $this->inputIndex += 1; |
|
| 142 | + } else { |
|
| 143 | + $c = null; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if ($c === "\r") { |
|
| 148 | + return "\n"; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
| 152 | + return $c; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return ' '; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | protected function isAlphaNum($c) { |
| 159 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
| 159 | + return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | protected function min() { |
| 163 | - $this->a = "\n"; |
|
| 164 | - $this->action(3); |
|
| 165 | - |
|
| 166 | - while ($this->a !== null) { |
|
| 167 | - switch ($this->a) { |
|
| 168 | - case ' ': |
|
| 169 | - if ($this->isAlphaNum($this->b)) { |
|
| 170 | - $this->action(1); |
|
| 171 | - } else { |
|
| 172 | - $this->action(2); |
|
| 173 | - } |
|
| 174 | - break; |
|
| 175 | - |
|
| 176 | - case "\n": |
|
| 177 | - switch ($this->b) { |
|
| 178 | - case '{': |
|
| 179 | - case '[': |
|
| 180 | - case '(': |
|
| 181 | - case '+': |
|
| 182 | - case '-': |
|
| 183 | - $this->action(1); |
|
| 184 | - break; |
|
| 185 | - |
|
| 186 | - case ' ': |
|
| 187 | - $this->action(3); |
|
| 188 | - break; |
|
| 189 | - |
|
| 190 | - default: |
|
| 191 | - if ($this->isAlphaNum($this->b)) { |
|
| 192 | - $this->action(1); |
|
| 193 | - } |
|
| 194 | - else { |
|
| 195 | - $this->action(2); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - break; |
|
| 199 | - |
|
| 200 | - default: |
|
| 201 | - switch ($this->b) { |
|
| 202 | - case ' ': |
|
| 203 | - if ($this->isAlphaNum($this->a)) { |
|
| 204 | - $this->action(1); |
|
| 205 | - break; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $this->action(3); |
|
| 209 | - break; |
|
| 210 | - |
|
| 211 | - case "\n": |
|
| 212 | - switch ($this->a) { |
|
| 213 | - case '}': |
|
| 214 | - case ']': |
|
| 215 | - case ')': |
|
| 216 | - case '+': |
|
| 217 | - case '-': |
|
| 218 | - case '"': |
|
| 219 | - case "'": |
|
| 220 | - $this->action(1); |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - default: |
|
| 224 | - if ($this->isAlphaNum($this->a)) { |
|
| 225 | - $this->action(1); |
|
| 226 | - } |
|
| 227 | - else { |
|
| 228 | - $this->action(3); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - break; |
|
| 232 | - |
|
| 233 | - default: |
|
| 234 | - $this->action(1); |
|
| 235 | - break; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $this->output; |
|
| 163 | + $this->a = "\n"; |
|
| 164 | + $this->action(3); |
|
| 165 | + |
|
| 166 | + while ($this->a !== null) { |
|
| 167 | + switch ($this->a) { |
|
| 168 | + case ' ': |
|
| 169 | + if ($this->isAlphaNum($this->b)) { |
|
| 170 | + $this->action(1); |
|
| 171 | + } else { |
|
| 172 | + $this->action(2); |
|
| 173 | + } |
|
| 174 | + break; |
|
| 175 | + |
|
| 176 | + case "\n": |
|
| 177 | + switch ($this->b) { |
|
| 178 | + case '{': |
|
| 179 | + case '[': |
|
| 180 | + case '(': |
|
| 181 | + case '+': |
|
| 182 | + case '-': |
|
| 183 | + $this->action(1); |
|
| 184 | + break; |
|
| 185 | + |
|
| 186 | + case ' ': |
|
| 187 | + $this->action(3); |
|
| 188 | + break; |
|
| 189 | + |
|
| 190 | + default: |
|
| 191 | + if ($this->isAlphaNum($this->b)) { |
|
| 192 | + $this->action(1); |
|
| 193 | + } |
|
| 194 | + else { |
|
| 195 | + $this->action(2); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + break; |
|
| 199 | + |
|
| 200 | + default: |
|
| 201 | + switch ($this->b) { |
|
| 202 | + case ' ': |
|
| 203 | + if ($this->isAlphaNum($this->a)) { |
|
| 204 | + $this->action(1); |
|
| 205 | + break; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $this->action(3); |
|
| 209 | + break; |
|
| 210 | + |
|
| 211 | + case "\n": |
|
| 212 | + switch ($this->a) { |
|
| 213 | + case '}': |
|
| 214 | + case ']': |
|
| 215 | + case ')': |
|
| 216 | + case '+': |
|
| 217 | + case '-': |
|
| 218 | + case '"': |
|
| 219 | + case "'": |
|
| 220 | + $this->action(1); |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + default: |
|
| 224 | + if ($this->isAlphaNum($this->a)) { |
|
| 225 | + $this->action(1); |
|
| 226 | + } |
|
| 227 | + else { |
|
| 228 | + $this->action(3); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + break; |
|
| 232 | + |
|
| 233 | + default: |
|
| 234 | + $this->action(1); |
|
| 235 | + break; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $this->output; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | protected function next() { |
| 244 | - $c = $this->get(); |
|
| 245 | - |
|
| 246 | - if ($c === '/') { |
|
| 247 | - switch($this->peek()) { |
|
| 248 | - case '/': |
|
| 249 | - for (;;) { |
|
| 250 | - $c = $this->get(); |
|
| 251 | - |
|
| 252 | - if (ord($c) <= self::ORD_LF) { |
|
| 253 | - return $c; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - case '*': |
|
| 258 | - $this->get(); |
|
| 259 | - |
|
| 260 | - for (;;) { |
|
| 261 | - switch($this->get()) { |
|
| 262 | - case '*': |
|
| 263 | - if ($this->peek() === '/') { |
|
| 264 | - $this->get(); |
|
| 265 | - return ' '; |
|
| 266 | - } |
|
| 267 | - break; |
|
| 268 | - |
|
| 269 | - case null: |
|
| 270 | - throw new JSMinException('Unterminated comment.'); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - default: |
|
| 275 | - return $c; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $c; |
|
| 244 | + $c = $this->get(); |
|
| 245 | + |
|
| 246 | + if ($c === '/') { |
|
| 247 | + switch($this->peek()) { |
|
| 248 | + case '/': |
|
| 249 | + for (;;) { |
|
| 250 | + $c = $this->get(); |
|
| 251 | + |
|
| 252 | + if (ord($c) <= self::ORD_LF) { |
|
| 253 | + return $c; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + case '*': |
|
| 258 | + $this->get(); |
|
| 259 | + |
|
| 260 | + for (;;) { |
|
| 261 | + switch($this->get()) { |
|
| 262 | + case '*': |
|
| 263 | + if ($this->peek() === '/') { |
|
| 264 | + $this->get(); |
|
| 265 | + return ' '; |
|
| 266 | + } |
|
| 267 | + break; |
|
| 268 | + |
|
| 269 | + case null: |
|
| 270 | + throw new JSMinException('Unterminated comment.'); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + default: |
|
| 275 | + return $c; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $c; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | protected function peek() { |
| 283 | - $this->lookAhead = $this->get(); |
|
| 284 | - return $this->lookAhead; |
|
| 283 | + $this->lookAhead = $this->get(); |
|
| 284 | + return $this->lookAhead; |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | \ No newline at end of file |
@@ -47,29 +47,29 @@ discard block |
||
| 47 | 47 | namespace Prado\Web\Javascripts; |
| 48 | 48 | |
| 49 | 49 | class JSMin { |
| 50 | - const ORD_LF = 10; |
|
| 51 | - const ORD_SPACE = 32; |
|
| 50 | + const ORD_LF=10; |
|
| 51 | + const ORD_SPACE=32; |
|
| 52 | 52 | |
| 53 | - protected $a = ''; |
|
| 54 | - protected $b = ''; |
|
| 55 | - protected $input = ''; |
|
| 56 | - protected $inputIndex = 0; |
|
| 57 | - protected $inputLength = 0; |
|
| 58 | - protected $lookAhead = null; |
|
| 59 | - protected $output = ''; |
|
| 53 | + protected $a=''; |
|
| 54 | + protected $b=''; |
|
| 55 | + protected $input=''; |
|
| 56 | + protected $inputIndex=0; |
|
| 57 | + protected $inputLength=0; |
|
| 58 | + protected $lookAhead=null; |
|
| 59 | + protected $output=''; |
|
| 60 | 60 | |
| 61 | 61 | // -- Public Static Methods -------------------------------------------------- |
| 62 | 62 | |
| 63 | 63 | public static function minify($js) { |
| 64 | - $jsmin = new JSMin($js); |
|
| 64 | + $jsmin=new JSMin($js); |
|
| 65 | 65 | return $jsmin->min(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // -- Public Instance Methods ------------------------------------------------ |
| 69 | 69 | |
| 70 | 70 | public function __construct($input) { |
| 71 | - $this->input = str_replace("\r\n", "\n", $input); |
|
| 72 | - $this->inputLength = strlen($this->input); |
|
| 71 | + $this->input=str_replace("\r\n", "\n", $input); |
|
| 72 | + $this->inputLength=strlen($this->input); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // -- Protected Instance Methods --------------------------------------------- |
@@ -77,80 +77,80 @@ discard block |
||
| 77 | 77 | protected function action($d) { |
| 78 | 78 | switch($d) { |
| 79 | 79 | case 1: |
| 80 | - $this->output .= $this->a; |
|
| 80 | + $this->output.=$this->a; |
|
| 81 | 81 | |
| 82 | 82 | case 2: |
| 83 | - $this->a = $this->b; |
|
| 83 | + $this->a=$this->b; |
|
| 84 | 84 | |
| 85 | - if ($this->a === "'" || $this->a === '"') { |
|
| 86 | - for (;;) { |
|
| 87 | - $this->output .= $this->a; |
|
| 88 | - $this->a = $this->get(); |
|
| 85 | + if($this->a==="'" || $this->a==='"') { |
|
| 86 | + for(;;) { |
|
| 87 | + $this->output.=$this->a; |
|
| 88 | + $this->a=$this->get(); |
|
| 89 | 89 | |
| 90 | - if ($this->a === $this->b) { |
|
| 90 | + if($this->a===$this->b) { |
|
| 91 | 91 | break; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if (ord($this->a) <= self::ORD_LF) { |
|
| 94 | + if(ord($this->a) <= self::ORD_LF) { |
|
| 95 | 95 | throw new JSMinException('Unterminated string literal.'); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ($this->a === '\\') { |
|
| 99 | - $this->output .= $this->a; |
|
| 100 | - $this->a = $this->get(); |
|
| 98 | + if($this->a==='\\') { |
|
| 99 | + $this->output.=$this->a; |
|
| 100 | + $this->a=$this->get(); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | case 3: |
| 106 | - $this->b = $this->next(); |
|
| 106 | + $this->b=$this->next(); |
|
| 107 | 107 | |
| 108 | - if ($this->b === '/' && ( |
|
| 109 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
| 110 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
| 111 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
| 108 | + if($this->b==='/' && ( |
|
| 109 | + $this->a==='(' || $this->a===',' || $this->a==='=' || |
|
| 110 | + $this->a===':' || $this->a==='[' || $this->a==='!' || |
|
| 111 | + $this->a==='&' || $this->a==='|' || $this->a==='?')) { |
|
| 112 | 112 | |
| 113 | - $this->output .= $this->a . $this->b; |
|
| 113 | + $this->output.=$this->a.$this->b; |
|
| 114 | 114 | |
| 115 | - for (;;) { |
|
| 116 | - $this->a = $this->get(); |
|
| 115 | + for(;;) { |
|
| 116 | + $this->a=$this->get(); |
|
| 117 | 117 | |
| 118 | - if ($this->a === '/') { |
|
| 118 | + if($this->a==='/') { |
|
| 119 | 119 | break; |
| 120 | - } elseif ($this->a === '\\') { |
|
| 121 | - $this->output .= $this->a; |
|
| 122 | - $this->a = $this->get(); |
|
| 123 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
| 120 | + } elseif($this->a==='\\') { |
|
| 121 | + $this->output.=$this->a; |
|
| 122 | + $this->a=$this->get(); |
|
| 123 | + } elseif(ord($this->a) <= self::ORD_LF) { |
|
| 124 | 124 | throw new JSMinException('Unterminated regular expression '. |
| 125 | 125 | 'literal.'); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $this->output .= $this->a; |
|
| 128 | + $this->output.=$this->a; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $this->b = $this->next(); |
|
| 131 | + $this->b=$this->next(); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | protected function get() { |
| 137 | - $c = $this->lookAhead; |
|
| 138 | - $this->lookAhead = null; |
|
| 137 | + $c=$this->lookAhead; |
|
| 138 | + $this->lookAhead=null; |
|
| 139 | 139 | |
| 140 | - if ($c === null) { |
|
| 141 | - if ($this->inputIndex < $this->inputLength) { |
|
| 142 | - $c = $this->input[$this->inputIndex]; |
|
| 143 | - $this->inputIndex += 1; |
|
| 140 | + if($c===null) { |
|
| 141 | + if($this->inputIndex < $this->inputLength) { |
|
| 142 | + $c=$this->input[$this->inputIndex]; |
|
| 143 | + $this->inputIndex+=1; |
|
| 144 | 144 | } else { |
| 145 | - $c = null; |
|
| 145 | + $c=null; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if ($c === "\r") { |
|
| 149 | + if($c==="\r") { |
|
| 150 | 150 | return "\n"; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
| 153 | + if($c===null || $c==="\n" || ord($c) >= self::ORD_SPACE) { |
|
| 154 | 154 | return $c; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | protected function isAlphaNum($c) { |
| 161 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
| 161 | + return ord($c) > 126 || $c==='\\' || preg_match('/^[\w\$]$/', $c)===1; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | protected function min() { |
| 165 | - $this->a = "\n"; |
|
| 165 | + $this->a="\n"; |
|
| 166 | 166 | $this->action(3); |
| 167 | 167 | |
| 168 | - while ($this->a !== null) { |
|
| 169 | - switch ($this->a) { |
|
| 168 | + while($this->a!==null) { |
|
| 169 | + switch($this->a) { |
|
| 170 | 170 | case ' ': |
| 171 | - if ($this->isAlphaNum($this->b)) { |
|
| 171 | + if($this->isAlphaNum($this->b)) { |
|
| 172 | 172 | $this->action(1); |
| 173 | 173 | } else { |
| 174 | 174 | $this->action(2); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | break; |
| 177 | 177 | |
| 178 | 178 | case "\n": |
| 179 | - switch ($this->b) { |
|
| 179 | + switch($this->b) { |
|
| 180 | 180 | case '{': |
| 181 | 181 | case '[': |
| 182 | 182 | case '(': |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | break; |
| 191 | 191 | |
| 192 | 192 | default: |
| 193 | - if ($this->isAlphaNum($this->b)) { |
|
| 193 | + if($this->isAlphaNum($this->b)) { |
|
| 194 | 194 | $this->action(1); |
| 195 | 195 | } |
| 196 | 196 | else { |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | break; |
| 201 | 201 | |
| 202 | 202 | default: |
| 203 | - switch ($this->b) { |
|
| 203 | + switch($this->b) { |
|
| 204 | 204 | case ' ': |
| 205 | - if ($this->isAlphaNum($this->a)) { |
|
| 205 | + if($this->isAlphaNum($this->a)) { |
|
| 206 | 206 | $this->action(1); |
| 207 | 207 | break; |
| 208 | 208 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | break; |
| 212 | 212 | |
| 213 | 213 | case "\n": |
| 214 | - switch ($this->a) { |
|
| 214 | + switch($this->a) { |
|
| 215 | 215 | case '}': |
| 216 | 216 | case ']': |
| 217 | 217 | case ')': |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | break; |
| 224 | 224 | |
| 225 | 225 | default: |
| 226 | - if ($this->isAlphaNum($this->a)) { |
|
| 226 | + if($this->isAlphaNum($this->a)) { |
|
| 227 | 227 | $this->action(1); |
| 228 | 228 | } |
| 229 | 229 | else { |
@@ -243,15 +243,15 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | protected function next() { |
| 246 | - $c = $this->get(); |
|
| 246 | + $c=$this->get(); |
|
| 247 | 247 | |
| 248 | - if ($c === '/') { |
|
| 248 | + if($c==='/') { |
|
| 249 | 249 | switch($this->peek()) { |
| 250 | 250 | case '/': |
| 251 | - for (;;) { |
|
| 252 | - $c = $this->get(); |
|
| 251 | + for(;;) { |
|
| 252 | + $c=$this->get(); |
|
| 253 | 253 | |
| 254 | - if (ord($c) <= self::ORD_LF) { |
|
| 254 | + if(ord($c) <= self::ORD_LF) { |
|
| 255 | 255 | return $c; |
| 256 | 256 | } |
| 257 | 257 | } |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | case '*': |
| 260 | 260 | $this->get(); |
| 261 | 261 | |
| 262 | - for (;;) { |
|
| 262 | + for(;;) { |
|
| 263 | 263 | switch($this->get()) { |
| 264 | 264 | case '*': |
| 265 | - if ($this->peek() === '/') { |
|
| 265 | + if($this->peek()==='/') { |
|
| 266 | 266 | $this->get(); |
| 267 | 267 | return ' '; |
| 268 | 268 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | protected function peek() { |
| 285 | - $this->lookAhead = $this->get(); |
|
| 285 | + $this->lookAhead=$this->get(); |
|
| 286 | 286 | return $this->lookAhead; |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | \ No newline at end of file |