@@ -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 | |
@@ -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': |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * unquote chars |
| 34 | 34 | * @var array |
| 35 | 35 | */ |
| 36 | - private $uqChars = array('[', ']', '"', '`', "'"); |
|
| 36 | + private $uqChars=array('[', ']', '"', '`', "'"); |
|
| 37 | 37 | |
| 38 | 38 | function __construct() |
| 39 | 39 | { |
@@ -42,31 +42,31 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function setClasPrefix($_clas_prefix) |
| 44 | 44 | { |
| 45 | - $this->_clasPrefix = $_clas_prefix; |
|
| 45 | + $this->_clasPrefix=$_clas_prefix; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function setClassSufix($_clas_sufix) |
| 49 | 49 | { |
| 50 | - $this->_classSufix = $_clas_sufix; |
|
| 50 | + $this->_classSufix=$_clas_sufix; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | //----------------------------------------------------------------------------- |
| 54 | 54 | // <editor-fold defaultstate="collapsed" desc="Main APIs"> |
| 55 | 55 | public function generate($tableName) |
| 56 | 56 | { |
| 57 | - $tableInfo = $this->_dbMetaData->getTableInfo($tableName); |
|
| 57 | + $tableInfo=$this->_dbMetaData->getTableInfo($tableName); |
|
| 58 | 58 | $this->_commonGenerate($tableName, $tableInfo); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public function generateAll() |
| 62 | 62 | { |
| 63 | - foreach ($this->getAllTableNames() as $tableName) |
|
| 63 | + foreach($this->getAllTableNames() as $tableName) |
|
| 64 | 64 | { |
| 65 | - $tableInfo = $this->_dbMetaData->getTableInfo($tableName); |
|
| 66 | - if (!empty($this->_relations)) |
|
| 65 | + $tableInfo=$this->_dbMetaData->getTableInfo($tableName); |
|
| 66 | + if(!empty($this->_relations)) |
|
| 67 | 67 | { |
| 68 | 68 | // Cancel generation of M-M relationships middle table |
| 69 | - if (count($tableInfo->getPrimaryKeys()) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships |
|
| 69 | + if(count($tableInfo->getPrimaryKeys())===2 && count($tableInfo->getColumns())===2)//M-M relationships |
|
| 70 | 70 | continue; |
| 71 | 71 | } |
| 72 | 72 | $this->_commonGenerate($tableName, $tableInfo); |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function buildRelations() |
| 77 | 77 | { |
| 78 | - $this->_relations = array(); |
|
| 79 | - foreach ($this->getAllTableNames() as $table_name) |
|
| 78 | + $this->_relations=array(); |
|
| 79 | + foreach($this->getAllTableNames() as $table_name) |
|
| 80 | 80 | { |
| 81 | - $tableInfo = $this->_dbMetaData->getTableInfo($table_name); |
|
| 82 | - $pks = $tableInfo->getPrimaryKeys(); |
|
| 83 | - $fks = $tableInfo->getForeignKeys(); |
|
| 81 | + $tableInfo=$this->_dbMetaData->getTableInfo($table_name); |
|
| 82 | + $pks=$tableInfo->getPrimaryKeys(); |
|
| 83 | + $fks=$tableInfo->getForeignKeys(); |
|
| 84 | 84 | |
| 85 | - if (count($pks) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships |
|
| 85 | + if(count($pks)===2 && count($tableInfo->getColumns())===2)//M-M relationships |
|
| 86 | 86 | { |
| 87 | - $table_name_mm = $fks[0]["table"]; |
|
| 88 | - $table_name_mm2 = $fks[1]["table"]; |
|
| 87 | + $table_name_mm=$fks[0]["table"]; |
|
| 88 | + $table_name_mm2=$fks[1]["table"]; |
|
| 89 | 89 | |
| 90 | - $this->_relations[$table_name_mm][] = array( |
|
| 90 | + $this->_relations[$table_name_mm][]=array( |
|
| 91 | 91 | "prop_name" => strtolower($table_name_mm2), |
| 92 | 92 | "rel_type" => "self::MANY_TO_MANY", |
| 93 | 93 | "ref_class_name" => $this->_getProperClassName($table_name_mm2), |
| 94 | 94 | "prop_ref" => $table_name |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | - $this->_relations[$table_name_mm2][] = array( |
|
| 97 | + $this->_relations[$table_name_mm2][]=array( |
|
| 98 | 98 | "prop_name" => strtolower($table_name_mm), |
| 99 | 99 | "rel_type" => "self::MANY_TO_MANY", |
| 100 | 100 | "ref_class_name" => $this->_getProperClassName($table_name_mm), |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | ); |
| 103 | 103 | continue; |
| 104 | 104 | } |
| 105 | - foreach ($fks as $fk_data)//1-M relationships |
|
| 105 | + foreach($fks as $fk_data)//1-M relationships |
|
| 106 | 106 | { |
| 107 | - $owner_table = $fk_data["table"]; |
|
| 108 | - $slave_table = $table_name; |
|
| 109 | - $fk_prop = key($fk_data["keys"]); |
|
| 107 | + $owner_table=$fk_data["table"]; |
|
| 108 | + $slave_table=$table_name; |
|
| 109 | + $fk_prop=key($fk_data["keys"]); |
|
| 110 | 110 | |
| 111 | - $this->_relations[$owner_table][] = array( |
|
| 111 | + $this->_relations[$owner_table][]=array( |
|
| 112 | 112 | "prop_name" => strtolower($slave_table), |
| 113 | 113 | "rel_type" => "self::HAS_MANY", |
| 114 | 114 | "ref_class_name" => $this->_getProperClassName($slave_table), |
| 115 | 115 | "prop_ref" => $fk_prop |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - $this->_relations[$slave_table][] = array( |
|
| 118 | + $this->_relations[$slave_table][]=array( |
|
| 119 | 119 | "prop_name" => strtolower($owner_table), |
| 120 | 120 | "rel_type" => "self::BELONGS_TO", |
| 121 | 121 | "ref_class_name" => $this->_getProperClassName($owner_table), |
@@ -131,88 +131,88 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | private function _commonGenerate($tableName, $tableInfo) |
| 133 | 133 | { |
| 134 | - if (count($tableInfo->getColumns()) === 0) |
|
| 135 | - throw new Exception("Unable to find table or view $tableName in " . $this->_dbMetaData->getDbConnection()->getConnectionString() . "."); |
|
| 134 | + if(count($tableInfo->getColumns())===0) |
|
| 135 | + throw new Exception("Unable to find table or view $tableName in ".$this->_dbMetaData->getDbConnection()->getConnectionString()."."); |
|
| 136 | 136 | else |
| 137 | 137 | { |
| 138 | - $properties = array(); |
|
| 139 | - foreach ($tableInfo->getColumns() as $field => $metadata) |
|
| 140 | - $properties[] = $this->generateProperty($field, $metadata); |
|
| 141 | - $toString = $this->_buildSmartToString($tableInfo); |
|
| 138 | + $properties=array(); |
|
| 139 | + foreach($tableInfo->getColumns() as $field => $metadata) |
|
| 140 | + $properties[]=$this->generateProperty($field, $metadata); |
|
| 141 | + $toString=$this->_buildSmartToString($tableInfo); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $clasName = $this->_getProperClassName($tableName); |
|
| 145 | - $class = $this->generateClass($properties, $tableName, $clasName, $toString); |
|
| 146 | - $output = $this->_opFile . DIRECTORY_SEPARATOR . $clasName . ".php"; |
|
| 144 | + $clasName=$this->_getProperClassName($tableName); |
|
| 145 | + $class=$this->generateClass($properties, $tableName, $clasName, $toString); |
|
| 146 | + $output=$this->_opFile.DIRECTORY_SEPARATOR.$clasName.".php"; |
|
| 147 | 147 | file_put_contents($output, $class); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | private function _getProperClassName($tableName) |
| 151 | 151 | { |
| 152 | - $table_name_words = str_replace("_", " ", strtolower($tableName)); |
|
| 153 | - $final_conversion = str_replace(" ", "", ucwords($table_name_words)); |
|
| 154 | - return $this->_clasPrefix . $final_conversion . $this->_classSufix; |
|
| 152 | + $table_name_words=str_replace("_", " ", strtolower($tableName)); |
|
| 153 | + $final_conversion=str_replace(" ", "", ucwords($table_name_words)); |
|
| 154 | + return $this->_clasPrefix.$final_conversion.$this->_classSufix; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | //----------------------------------------------------------------------------- |
| 158 | 158 | |
| 159 | 159 | protected function generateProperty($field, $metadata) |
| 160 | 160 | { |
| 161 | - $prop = ''; |
|
| 162 | - $name = '$' . $field; |
|
| 161 | + $prop=''; |
|
| 162 | + $name='$'.$field; |
|
| 163 | 163 | |
| 164 | 164 | /* TODO use in version 2.0 */ |
| 165 | 165 | // $type = $column->getPHPType(); |
| 166 | 166 | |
| 167 | - $prop .= "\tpublic $name;"; |
|
| 167 | + $prop.="\tpublic $name;"; |
|
| 168 | 168 | return $prop; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | private function _renderRelations($tablename) |
| 172 | 172 | { |
| 173 | - if (!isset($this->_relations[$tablename])) |
|
| 173 | + if(!isset($this->_relations[$tablename])) |
|
| 174 | 174 | return ""; |
| 175 | 175 | |
| 176 | - $code = "\tpublic static \$RELATIONS = array ("; |
|
| 177 | - foreach ($this->_relations[$tablename] as $rel_data) |
|
| 178 | - $code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),"; |
|
| 176 | + $code="\tpublic static \$RELATIONS = array ("; |
|
| 177 | + foreach($this->_relations[$tablename] as $rel_data) |
|
| 178 | + $code.="\n\t\t'".$rel_data["prop_name"]."' => array(".$rel_data["rel_type"].", '".$rel_data["ref_class_name"]."', '".$rel_data["prop_ref"]."'),"; |
|
| 179 | 179 | |
| 180 | - $code = substr($code, 0, -1); |
|
| 181 | - $code .= "\n\t);"; |
|
| 180 | + $code=substr($code, 0, -1); |
|
| 181 | + $code.="\n\t);"; |
|
| 182 | 182 | return $code; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | private function _buildSmartToString($tableInfo) |
| 186 | 186 | { |
| 187 | - $code = "\tpublic function __toString() {"; |
|
| 188 | - $property = "throw new THttpException(500, 'Not implemented yet.');"; |
|
| 187 | + $code="\tpublic function __toString() {"; |
|
| 188 | + $property="throw new THttpException(500, 'Not implemented yet.');"; |
|
| 189 | 189 | try |
| 190 | 190 | { |
| 191 | - foreach ($tableInfo->getColumns() as $column) |
|
| 191 | + foreach($tableInfo->getColumns() as $column) |
|
| 192 | 192 | { |
| 193 | - if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) |
|
| 194 | - $property = str_replace($this->uqChars, "", $column->ColumnName); |
|
| 195 | - elseif ($column->PdoType == PDO::PARAM_STR && $column->DBType != "date") |
|
| 193 | + if(isset($column->IsPrimaryKey) && $column->IsPrimaryKey) |
|
| 194 | + $property=str_replace($this->uqChars, "", $column->ColumnName); |
|
| 195 | + elseif($column->PdoType==PDO::PARAM_STR && $column->DBType!="date") |
|
| 196 | 196 | { |
| 197 | - $property = str_replace($this->uqChars, "", $column->ColumnName); |
|
| 197 | + $property=str_replace($this->uqChars, "", $column->ColumnName); |
|
| 198 | 198 | break; |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - } catch (Exception $ex) |
|
| 201 | + } catch(Exception $ex) |
|
| 202 | 202 | { |
| 203 | 203 | Prado::trace($ex->getMessage()); |
| 204 | 204 | } |
| 205 | - $code .= "\n\t\treturn \$this->$property;"; |
|
| 206 | - $code .= "\n\t}"; |
|
| 205 | + $code.="\n\t\treturn \$this->$property;"; |
|
| 206 | + $code.="\n\t}"; |
|
| 207 | 207 | return $code; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | protected function generateClass($properties, $tablename, $classname, $toString) |
| 211 | 211 | { |
| 212 | - $props = implode("\n", $properties); |
|
| 213 | - $relations = $this->_renderRelations($tablename); |
|
| 214 | - $date = date('Y-m-d h:i:s'); |
|
| 215 | - $env_user = getenv("username"); |
|
| 212 | + $props=implode("\n", $properties); |
|
| 213 | + $relations=$this->_renderRelations($tablename); |
|
| 214 | + $date=date('Y-m-d h:i:s'); |
|
| 215 | + $env_user=getenv("username"); |
|
| 216 | 216 | return <<<EOD |
| 217 | 217 | <?php |
| 218 | 218 | /** |
@@ -27,31 +27,31 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | function __construct() |
| 29 | 29 | { |
| 30 | - if (!class_exists("TActiveRecordManager", false)) |
|
| 30 | + if(!class_exists("TActiveRecordManager", false)) |
|
| 31 | 31 | throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); |
| 32 | - $ar_manager = TActiveRecordManager::getInstance(); |
|
| 33 | - $_conn = $ar_manager->getDbConnection(); |
|
| 34 | - $_conn->Active = true; |
|
| 35 | - $this->_dbMetaData = TDbMetaData::getInstance($_conn); |
|
| 32 | + $ar_manager=TActiveRecordManager::getInstance(); |
|
| 33 | + $_conn=$ar_manager->getDbConnection(); |
|
| 34 | + $_conn->Active=true; |
|
| 35 | + $this->_dbMetaData=TDbMetaData::getInstance($_conn); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function setOpFile($op_file_namespace) |
| 39 | 39 | { |
| 40 | - $op_file = Prado::getPathOfNamespace($op_file_namespace); |
|
| 41 | - if (empty($op_file)) |
|
| 40 | + $op_file=Prado::getPathOfNamespace($op_file_namespace); |
|
| 41 | + if(empty($op_file)) |
|
| 42 | 42 | throw new Exception("You need to fix your output folder namespace."); |
| 43 | - if (!is_dir($op_file)) |
|
| 43 | + if(!is_dir($op_file)) |
|
| 44 | 44 | mkdir($op_file, 0777, true); |
| 45 | - $this->_opFile = $op_file; |
|
| 45 | + $this->_opFile=$op_file; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function renderAllTablesInformation() |
| 49 | 49 | { |
| 50 | - foreach ($this->getAllTableNames() as $table_name) |
|
| 50 | + foreach($this->getAllTableNames() as $table_name) |
|
| 51 | 51 | { |
| 52 | - echo $table_name . "<br>"; |
|
| 53 | - $tableInfo = $this->_dbMetaData->getTableInfo($table_name); |
|
| 54 | - echo "Table info:" . "<br>"; |
|
| 52 | + echo $table_name."<br>"; |
|
| 53 | + $tableInfo=$this->_dbMetaData->getTableInfo($table_name); |
|
| 54 | + echo "Table info:"."<br>"; |
|
| 55 | 55 | echo "<pre>"; |
| 56 | 56 | print_r($tableInfo); |
| 57 | 57 | echo "</pre>"; |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public function getAllTableNames() |
| 62 | 62 | { |
| 63 | - $tableNames = $this->_dbMetaData->findTableNames(); |
|
| 64 | - $index = array_search('pradocache', $tableNames); |
|
| 65 | - if ($index) |
|
| 63 | + $tableNames=$this->_dbMetaData->findTableNames(); |
|
| 64 | + $index=array_search('pradocache', $tableNames); |
|
| 65 | + if($index) |
|
| 66 | 66 | array_splice($tableNames, $index, 1); |
| 67 | 67 | return $tableNames; |
| 68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | protected function eq($data) |
| 78 | 78 | { |
| 79 | - return '"' . $data . '"'; |
|
| 79 | + return '"'.$data.'"'; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | } |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Const View Types for generation |
| 19 | 19 | */ |
| 20 | - const LIST_TYPE = 0; |
|
| 21 | - const ADD_TYPE = 1; |
|
| 22 | - const SHOW_TYPE = 2; |
|
| 20 | + const LIST_TYPE=0; |
|
| 21 | + const ADD_TYPE=1; |
|
| 22 | + const SHOW_TYPE=2; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Bootstrap option |
@@ -46,34 +46,34 @@ discard block |
||
| 46 | 46 | // <editor-fold defaultstate="collapsed" desc="Page Generation"> |
| 47 | 47 | public function generate($tableName, $viewType) |
| 48 | 48 | { |
| 49 | - switch ($viewType) |
|
| 49 | + switch($viewType) |
|
| 50 | 50 | { |
| 51 | 51 | default: |
| 52 | 52 | case self::LIST_TYPE: |
| 53 | - $unitName = "list" . ucfirst($tableName); |
|
| 53 | + $unitName="list".ucfirst($tableName); |
|
| 54 | 54 | break; |
| 55 | 55 | |
| 56 | 56 | case self::ADD_TYPE: |
| 57 | - $unitName = "add" . ucfirst($tableName); |
|
| 57 | + $unitName="add".ucfirst($tableName); |
|
| 58 | 58 | break; |
| 59 | 59 | |
| 60 | 60 | case self::SHOW_TYPE: |
| 61 | - $unitName = "show" . ucfirst($tableName); |
|
| 61 | + $unitName="show".ucfirst($tableName); |
|
| 62 | 62 | break; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $class = $this->generateClass($unitName); |
|
| 66 | - $outputClass = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".php"; |
|
| 65 | + $class=$this->generateClass($unitName); |
|
| 66 | + $outputClass=$this->_opFile.DIRECTORY_SEPARATOR.$unitName.".php"; |
|
| 67 | 67 | file_put_contents($outputClass, $class); |
| 68 | 68 | |
| 69 | - $outputPage = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".page"; |
|
| 70 | - $page = $this->generatePage($tableName, $viewType); |
|
| 69 | + $outputPage=$this->_opFile.DIRECTORY_SEPARATOR.$unitName.".page"; |
|
| 70 | + $page=$this->generatePage($tableName, $viewType); |
|
| 71 | 71 | file_put_contents($outputPage, $page); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - private function generatePage($tableName, $type, $tContentId = "Content") |
|
| 74 | + private function generatePage($tableName, $type, $tContentId="Content") |
|
| 75 | 75 | { |
| 76 | - $pageContent = $this->getPageContent($tableName, $type); |
|
| 76 | + $pageContent=$this->getPageContent($tableName, $type); |
|
| 77 | 77 | return <<<EOD |
| 78 | 78 | <com:TContent ID="$tContentId"> |
| 79 | 79 | |
@@ -85,30 +85,30 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | private function getPageContent($tableName, $type) |
| 87 | 87 | { |
| 88 | - $code = ""; |
|
| 89 | - $tableInfo = $this->_dbMetaData->getTableInfo($tableName); |
|
| 90 | - switch ($type) |
|
| 88 | + $code=""; |
|
| 89 | + $tableInfo=$this->_dbMetaData->getTableInfo($tableName); |
|
| 90 | + switch($type) |
|
| 91 | 91 | { |
| 92 | 92 | case self::LIST_TYPE: |
| 93 | 93 | break; |
| 94 | 94 | case self::ADD_TYPE: |
| 95 | - foreach ($tableInfo->getColumns() as $colField => $colMetadata) |
|
| 95 | + foreach($tableInfo->getColumns() as $colField => $colMetadata) |
|
| 96 | 96 | { |
| 97 | - if (!$colMetadata->IsPrimaryKey && !$colMetadata->IsForeignKey) |
|
| 97 | + if(!$colMetadata->IsPrimaryKey && !$colMetadata->IsForeignKey) |
|
| 98 | 98 | { |
| 99 | - $code .= $this->generateControl($colMetadata); |
|
| 100 | - $code .= $this->generateValidators($colMetadata); |
|
| 101 | - $code .= "\n"; |
|
| 99 | + $code.=$this->generateControl($colMetadata); |
|
| 100 | + $code.=$this->generateValidators($colMetadata); |
|
| 101 | + $code.="\n"; |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | - foreach ($tableInfo->getForeignKeys() as $colField => $colMetadata) |
|
| 104 | + foreach($tableInfo->getForeignKeys() as $colField => $colMetadata) |
|
| 105 | 105 | { |
| 106 | - $colField = $this->eq($colMetadata["table"]); |
|
| 107 | - $code .= "\t<com:TTextBox ID=$colField />\n"; |
|
| 108 | - $code .= "\n"; |
|
| 106 | + $colField=$this->eq($colMetadata["table"]); |
|
| 107 | + $code.="\t<com:TTextBox ID=$colField />\n"; |
|
| 108 | + $code.="\n"; |
|
| 109 | 109 | // TWsatBaseGenerator::pr($tableInfo); |
| 110 | 110 | } |
| 111 | - $code .= "\t<com:TButton Text=\"Accept\" />\n"; |
|
| 111 | + $code.="\t<com:TButton Text=\"Accept\" />\n"; |
|
| 112 | 112 | |
| 113 | 113 | case self::SHOW_TYPE: |
| 114 | 114 | break; |
@@ -118,22 +118,22 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | private function generateControl($colMetadata) |
| 120 | 120 | { |
| 121 | - $controlType = "TTextBox"; |
|
| 122 | - switch ($colMetadata->DbType) |
|
| 121 | + $controlType="TTextBox"; |
|
| 122 | + switch($colMetadata->DbType) |
|
| 123 | 123 | { |
| 124 | 124 | |
| 125 | 125 | } |
| 126 | - $controlId = $colMetadata->ColumnId; |
|
| 126 | + $controlId=$colMetadata->ColumnId; |
|
| 127 | 127 | return "\t<com:$controlType ID=\"$controlId\" />\n"; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | private function generateValidators($colMetadata) |
| 131 | 131 | { |
| 132 | - $controlId = $colMetadata->ColumnId; |
|
| 133 | - $code = ""; |
|
| 134 | - if (!$colMetadata->AllowNull) |
|
| 132 | + $controlId=$colMetadata->ColumnId; |
|
| 133 | + $code=""; |
|
| 134 | + if(!$colMetadata->AllowNull) |
|
| 135 | 135 | { |
| 136 | - $code .= "\t<com:TRequiredFieldValidator ControlToValidate=$controlId ValidationGroup=\"addGroup\" Text=\"Field $controlId is required.\" Display=\"Dynamic\" />\n"; |
|
| 136 | + $code.="\t<com:TRequiredFieldValidator ControlToValidate=$controlId ValidationGroup=\"addGroup\" Text=\"Field $controlId is required.\" Display=\"Dynamic\" />\n"; |
|
| 137 | 137 | } |
| 138 | 138 | return $code; |
| 139 | 139 | } |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | // <editor-fold defaultstate="collapsed" desc="Code Behind Generation"> |
| 144 | 144 | private function generateClass($classname) |
| 145 | 145 | { |
| 146 | - $date = date('Y-m-d h:i:s'); |
|
| 147 | - $env_user = getenv("username"); |
|
| 146 | + $date=date('Y-m-d h:i:s'); |
|
| 147 | + $env_user=getenv("username"); |
|
| 148 | 148 | return <<<EOD |
| 149 | 149 | <?php |
| 150 | 150 | /** |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | private function validateSecurity() |
| 18 | 18 | { |
| 19 | - if ($this->Session["wsat_password"] !== $this->getService()->getPassword()) |
|
| 19 | + if($this->Session["wsat_password"]!==$this->getService()->getPassword()) |
|
| 20 | 20 | { |
| 21 | - if (!$this->getPage() instanceof TWsatLogin) |
|
| 21 | + if(!$this->getPage() instanceof TWsatLogin) |
|
| 22 | 22 | { |
| 23 | - $url = $this->Service->constructUrl('TWsatLogin'); |
|
| 23 | + $url=$this->Service->constructUrl('TWsatLogin'); |
|
| 24 | 24 | $this->Response->redirect($url); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function logout() |
| 30 | 30 | { |
| 31 | - $this->Session["wsat_password"] = ""; |
|
| 32 | - $url = $this->Service->constructUrl('TWsatLogin'); |
|
| 31 | + $this->Session["wsat_password"]=""; |
|
| 32 | + $url=$this->Service->constructUrl('TWsatLogin'); |
|
| 33 | 33 | $this->Response->redirect($url); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -14,19 +14,19 @@ |
||
| 14 | 14 | |
| 15 | 15 | public function login() |
| 16 | 16 | { |
| 17 | - if ($this->IsValid) |
|
| 17 | + if($this->IsValid) |
|
| 18 | 18 | { |
| 19 | - $this->Session["wsat_password"] = $this->getService()->getPassword(); |
|
| 20 | - $url = $this->Service->constructUrl('TWsatHome'); |
|
| 19 | + $this->Session["wsat_password"]=$this->getService()->getPassword(); |
|
| 20 | + $url=$this->Service->constructUrl('TWsatHome'); |
|
| 21 | 21 | $this->Response->redirect($url); |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function validatePassword($sender, $param) |
| 26 | 26 | { |
| 27 | - $config_pass = $this->Service->Password; |
|
| 28 | - $user_pass = $this->password->Text; |
|
| 29 | - $param->IsValid = $user_pass === $config_pass; |
|
| 27 | + $config_pass=$this->Service->Password; |
|
| 28 | + $user_pass=$this->password->Text; |
|
| 29 | + $param->IsValid=$user_pass===$config_pass; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | private function startVisual() |
| 24 | 24 | { |
| 25 | - $scf_generator = new TWsatScaffoldingGenerator(); |
|
| 26 | - foreach ($scf_generator->getAllTableNames() as $tableName) |
|
| 25 | + $scf_generator=new TWsatScaffoldingGenerator(); |
|
| 26 | + foreach($scf_generator->getAllTableNames() as $tableName) |
|
| 27 | 27 | { |
| 28 | - $dynChb = new TCheckBox(); |
|
| 29 | - $dynChb->ID = "cb_$tableName"; |
|
| 30 | - $dynChb->Text = ucfirst($tableName); |
|
| 31 | - $dynChb->Checked = true; |
|
| 28 | + $dynChb=new TCheckBox(); |
|
| 29 | + $dynChb->ID="cb_$tableName"; |
|
| 30 | + $dynChb->Text=ucfirst($tableName); |
|
| 31 | + $dynChb->Checked=true; |
|
| 32 | 32 | $this->registerObject("cb_$tableName", $dynChb); |
| 33 | 33 | $this->tableNames->getControls()->add($dynChb); |
| 34 | 34 | $this->tableNames->getControls()->add("</br>"); |
@@ -41,30 +41,30 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function generate($sender) |
| 43 | 43 | { |
| 44 | - if ($this->IsValid) |
|
| 44 | + if($this->IsValid) |
|
| 45 | 45 | { |
| 46 | 46 | try |
| 47 | 47 | { |
| 48 | - $scf_generator = new TWsatScaffoldingGenerator(); |
|
| 48 | + $scf_generator=new TWsatScaffoldingGenerator(); |
|
| 49 | 49 | $scf_generator->setOpFile($this->output_folder->Text); |
| 50 | - foreach ($scf_generator->getAllTableNames() as $tableName) |
|
| 50 | + foreach($scf_generator->getAllTableNames() as $tableName) |
|
| 51 | 51 | { |
| 52 | - $id = "cb_$tableName"; |
|
| 53 | - $obj = $this->tableNames->findControl($id); |
|
| 52 | + $id="cb_$tableName"; |
|
| 53 | + $obj=$this->tableNames->findControl($id); |
|
| 54 | 54 | if($obj!==null && $obj->Checked) |
| 55 | 55 | { |
| 56 | 56 | $scf_generator->generateCRUD($tableName); |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $this->feedback_panel->CssClass = "green_panel"; |
|
| 61 | - $this->generation_msg->Text = "The code has been generated successfully."; |
|
| 62 | - } catch (Exception $ex) |
|
| 60 | + $this->feedback_panel->CssClass="green_panel"; |
|
| 61 | + $this->generation_msg->Text="The code has been generated successfully."; |
|
| 62 | + } catch(Exception $ex) |
|
| 63 | 63 | { |
| 64 | - $this->feedback_panel->CssClass = "red_panel"; |
|
| 65 | - $this->generation_msg->Text = $ex->getMessage(); |
|
| 64 | + $this->feedback_panel->CssClass="red_panel"; |
|
| 65 | + $this->generation_msg->Text=$ex->getMessage(); |
|
| 66 | 66 | } |
| 67 | - $this->feedback_panel->Visible = true; |
|
| 67 | + $this->feedback_panel->Visible=true; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // $scf_generator->renderAllTablesInformation(); |
@@ -16,36 +16,36 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function generate($sender) |
| 18 | 18 | { |
| 19 | - if ($this->IsValid) |
|
| 19 | + if($this->IsValid) |
|
| 20 | 20 | { |
| 21 | - $tableName = $this->table_name->Text; |
|
| 22 | - $outputFolderNs = $this->output_folder->Text; |
|
| 23 | - $classPrefix = $this->class_prefix->Text; |
|
| 24 | - $classSuffix = $this->class_suffix->Text; |
|
| 21 | + $tableName=$this->table_name->Text; |
|
| 22 | + $outputFolderNs=$this->output_folder->Text; |
|
| 23 | + $classPrefix=$this->class_prefix->Text; |
|
| 24 | + $classSuffix=$this->class_suffix->Text; |
|
| 25 | 25 | |
| 26 | 26 | try |
| 27 | 27 | { |
| 28 | - $ar_generator = new TWsatARGenerator(); |
|
| 28 | + $ar_generator=new TWsatARGenerator(); |
|
| 29 | 29 | $ar_generator->setOpFile($outputFolderNs); |
| 30 | 30 | $ar_generator->setClasPrefix($classPrefix); |
| 31 | 31 | $ar_generator->setClassSufix($classSuffix); |
| 32 | 32 | |
| 33 | - if ($this->build_rel->Checked) |
|
| 33 | + if($this->build_rel->Checked) |
|
| 34 | 34 | $ar_generator->buildRelations(); |
| 35 | 35 | |
| 36 | - if ($tableName != "*") |
|
| 36 | + if($tableName!="*") |
|
| 37 | 37 | $ar_generator->generate($tableName); |
| 38 | 38 | else |
| 39 | 39 | $ar_generator->generateAll(); |
| 40 | 40 | |
| 41 | - $this->feedback_panel->CssClass = "green_panel"; |
|
| 42 | - $this->generation_msg->Text = "The code has been generated successfully."; |
|
| 43 | - } catch (Exception $ex) |
|
| 41 | + $this->feedback_panel->CssClass="green_panel"; |
|
| 42 | + $this->generation_msg->Text="The code has been generated successfully."; |
|
| 43 | + } catch(Exception $ex) |
|
| 44 | 44 | { |
| 45 | - $this->feedback_panel->CssClass = "red_panel"; |
|
| 46 | - $this->generation_msg->Text = $ex->getMessage(); |
|
| 45 | + $this->feedback_panel->CssClass="red_panel"; |
|
| 46 | + $this->generation_msg->Text=$ex->getMessage(); |
|
| 47 | 47 | } |
| 48 | - $this->feedback_panel->Visible = true; |
|
| 48 | + $this->feedback_panel->Visible=true; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -36,14 +36,14 @@ discard block |
||
| 36 | 36 | class TWsatService extends TPageService |
| 37 | 37 | { |
| 38 | 38 | |
| 39 | - private $_pass = ''; |
|
| 39 | + private $_pass=''; |
|
| 40 | 40 | |
| 41 | 41 | public function init($config) |
| 42 | 42 | { |
| 43 | - if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) |
|
| 43 | + if($this->getApplication()->getMode()===TApplicationMode::Performance || $this->getApplication()->getMode()===TApplicationMode::Normal) |
|
| 44 | 44 | throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); |
| 45 | 45 | |
| 46 | - if (empty($this->_pass)) |
|
| 46 | + if(empty($this->_pass)) |
|
| 47 | 47 | throw new TConfigurationException("You need to specify the Password attribute."); |
| 48 | 48 | |
| 49 | 49 | $this->setDefaultPage("TWsatHome"); |
@@ -53,16 +53,16 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function getBasePath() |
| 55 | 55 | { |
| 56 | - $basePath = Prado::getPathOfNamespace("System.Wsat.pages"); |
|
| 56 | + $basePath=Prado::getPathOfNamespace("System.Wsat.pages"); |
|
| 57 | 57 | return realpath($basePath); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | private function _startThemeManager() |
| 61 | 61 | { |
| 62 | - $themeManager = new TThemeManager; |
|
| 63 | - $themeManager->BasePath = "System.Wsat.themes"; |
|
| 64 | - $url = Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); |
|
| 65 | - $themeManager->BaseUrl = "$url/themes"; |
|
| 62 | + $themeManager=new TThemeManager; |
|
| 63 | + $themeManager->BasePath="System.Wsat.themes"; |
|
| 64 | + $url=Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); |
|
| 65 | + $themeManager->BaseUrl="$url/themes"; |
|
| 66 | 66 | |
| 67 | 67 | $themeManager->init(null); |
| 68 | 68 | $this->setThemeManager($themeManager); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function setPassword($_pass) |
| 77 | 77 | { |
| 78 | - $this->_pass = $_pass; |
|
| 78 | + $this->_pass=$_pass; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | \ No newline at end of file |