@@ -145,6 +145,10 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public abstract function performAction($args); |
| 147 | 147 | |
| 148 | + /** |
|
| 149 | + * @param string $dir |
|
| 150 | + * @param integer $mask |
|
| 151 | + */ |
|
| 148 | 152 | protected function createDirectory($dir, $mask) |
| 149 | 153 | { |
| 150 | 154 | if(!is_dir($dir)) |
@@ -156,6 +160,9 @@ discard block |
||
| 156 | 160 | chmod($dir, $mask); |
| 157 | 161 | } |
| 158 | 162 | |
| 163 | + /** |
|
| 164 | + * @param string $filename |
|
| 165 | + */ |
|
| 159 | 166 | protected function createFile($filename, $content) |
| 160 | 167 | { |
| 161 | 168 | if(!is_file($filename)) |
@@ -304,6 +311,9 @@ discard block |
||
| 304 | 311 | '; |
| 305 | 312 | } |
| 306 | 313 | |
| 314 | + /** |
|
| 315 | + * @param string $appName |
|
| 316 | + */ |
|
| 307 | 317 | protected function renderConfigFile($appName) |
| 308 | 318 | { |
| 309 | 319 | return <<<EOD |
@@ -500,6 +510,9 @@ discard block |
||
| 500 | 510 | require_once($TEST_TOOLS.'/simpletest/reporter.php'); |
| 501 | 511 | } |
| 502 | 512 | |
| 513 | + /** |
|
| 514 | + * @param string $dir |
|
| 515 | + */ |
|
| 503 | 516 | protected function runUnitTests($dir, $args) |
| 504 | 517 | { |
| 505 | 518 | $app_dir = $this->getAppDir($dir); |
@@ -538,6 +551,9 @@ discard block |
||
| 538 | 551 | return realpath($dir.'/tests/unit/'); |
| 539 | 552 | } |
| 540 | 553 | |
| 554 | + /** |
|
| 555 | + * @param string $dir |
|
| 556 | + */ |
|
| 541 | 557 | protected function getUnitTestCases($dir,$args) |
| 542 | 558 | { |
| 543 | 559 | $matches = null; |
@@ -549,6 +565,9 @@ discard block |
||
| 549 | 565 | return $test; |
| 550 | 566 | } |
| 551 | 567 | |
| 568 | + /** |
|
| 569 | + * @param GroupTest $test |
|
| 570 | + */ |
|
| 552 | 571 | protected function addTests($test,$path,$recursive=true,$match=null) |
| 553 | 572 | { |
| 554 | 573 | $dir=opendir($path); |
@@ -565,6 +584,9 @@ discard block |
||
| 565 | 584 | closedir($dir); |
| 566 | 585 | } |
| 567 | 586 | |
| 587 | + /** |
|
| 588 | + * @param string $entry |
|
| 589 | + */ |
|
| 568 | 590 | protected function hasMatch($match,$entry) |
| 569 | 591 | { |
| 570 | 592 | $file = strtolower(substr($entry,0,strrpos($entry,'.'))); |
@@ -630,6 +652,9 @@ discard block |
||
| 630 | 652 | return false; |
| 631 | 653 | } |
| 632 | 654 | |
| 655 | + /** |
|
| 656 | + * @param string $app_dir |
|
| 657 | + */ |
|
| 633 | 658 | protected function getActiveRecordConfig($app_dir) |
| 634 | 659 | { |
| 635 | 660 | if(false === ($xml=$this->getXmlFile($app_dir))) |
@@ -645,6 +670,9 @@ discard block |
||
| 645 | 670 | return false; |
| 646 | 671 | } |
| 647 | 672 | |
| 673 | + /** |
|
| 674 | + * @param string $app_dir |
|
| 675 | + */ |
|
| 648 | 676 | protected function getOutputFile($app_dir, $namespace) |
| 649 | 677 | { |
| 650 | 678 | if(is_file($namespace) && strpos($namespace, $app_dir)===0) |
@@ -659,6 +687,9 @@ discard block |
||
| 659 | 687 | return false; |
| 660 | 688 | } |
| 661 | 689 | |
| 690 | + /** |
|
| 691 | + * @param TActiveRecordConfig $config |
|
| 692 | + */ |
|
| 662 | 693 | protected function generateActiveRecord($config, $tablename, $output) |
| 663 | 694 | { |
| 664 | 695 | $manager = TActiveRecordManager::getInstance(); |
@@ -706,6 +737,9 @@ discard block |
||
| 706 | 737 | return $prop; |
| 707 | 738 | } |
| 708 | 739 | |
| 740 | + /** |
|
| 741 | + * @param string $class |
|
| 742 | + */ |
|
| 709 | 743 | protected function generateClass($properties, $tablename, $class) |
| 710 | 744 | { |
| 711 | 745 | $props = implode("\n", $properties); |
@@ -799,6 +833,9 @@ discard block |
||
| 799 | 833 | return false; |
| 800 | 834 | } |
| 801 | 835 | |
| 836 | + /** |
|
| 837 | + * @param string $app_dir |
|
| 838 | + */ |
|
| 802 | 839 | protected function getActiveRecordConfig($app_dir) { |
| 803 | 840 | if (false === ($xml = $this->getXmlFile($app_dir))) |
| 804 | 841 | return false; |
@@ -842,6 +879,9 @@ discard block |
||
| 842 | 879 | } |
| 843 | 880 | } |
| 844 | 881 | |
| 882 | + /** |
|
| 883 | + * @param string $l |
|
| 884 | + */ |
|
| 845 | 885 | public function generate($l) |
| 846 | 886 | { |
| 847 | 887 | $input = explode(" ", trim($l)); |
@@ -9,8 +9,9 @@ discard block |
||
| 9 | 9 | * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if(!isset($_SERVER['argv']) || php_sapi_name()!=='cli') |
|
| 12 | +if(!isset($_SERVER['argv']) || php_sapi_name()!=='cli') { |
|
| 13 | 13 | die('Must be run from the command line'); |
| 14 | +} |
|
| 14 | 15 | |
| 15 | 16 | $frameworkPath = realpath(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR; |
| 16 | 17 | |
@@ -32,7 +33,9 @@ discard block |
||
| 32 | 33 | { |
| 33 | 34 | function __shell_print_var($shell,$var) |
| 34 | 35 | { |
| 35 | - if(!$shell->has_semicolon) echo Prado::varDump($var); |
|
| 36 | + if(!$shell->has_semicolon) { |
|
| 37 | + echo Prado::varDump($var); |
|
| 38 | + } |
|
| 36 | 39 | } |
| 37 | 40 | include_once($frameworkPath.'/3rdParty/PhpShell/php-shell-init.php'); |
| 38 | 41 | } |
@@ -80,8 +83,9 @@ discard block |
||
| 80 | 83 | public static function getInstance() |
| 81 | 84 | { |
| 82 | 85 | static $instance; |
| 83 | - if($instance === null) |
|
| 84 | - $instance = new self; |
|
| 86 | + if($instance === null) { |
|
| 87 | + $instance = new self; |
|
| 88 | + } |
|
| 85 | 89 | return $instance; |
| 86 | 90 | } |
| 87 | 91 | |
@@ -96,8 +100,9 @@ discard block |
||
| 96 | 100 | */ |
| 97 | 101 | public function run($args) |
| 98 | 102 | { |
| 99 | - if(count($args) > 1) |
|
| 100 | - array_shift($args); |
|
| 103 | + if(count($args) > 1) { |
|
| 104 | + array_shift($args); |
|
| 105 | + } |
|
| 101 | 106 | $valid = false; |
| 102 | 107 | foreach($this->_actions as $class => $action) |
| 103 | 108 | { |
@@ -105,14 +110,14 @@ discard block |
||
| 105 | 110 | { |
| 106 | 111 | $valid |= $action->performAction($args); |
| 107 | 112 | break; |
| 108 | - } |
|
| 109 | - else |
|
| 113 | + } else |
|
| 110 | 114 | { |
| 111 | 115 | $valid = false; |
| 112 | 116 | } |
| 113 | 117 | } |
| 114 | - if(!$valid) |
|
| 115 | - $this->printHelp(); |
|
| 118 | + if(!$valid) { |
|
| 119 | + $this->printHelp(); |
|
| 120 | + } |
|
| 116 | 121 | } |
| 117 | 122 | |
| 118 | 123 | /** |
@@ -125,8 +130,9 @@ discard block |
||
| 125 | 130 | echo "usage: php prado-cli.php action <parameter> [optional]\n"; |
| 126 | 131 | echo "example: php prado-cli.php -c mysite\n\n"; |
| 127 | 132 | echo "actions:\n"; |
| 128 | - foreach($this->_actions as $action) |
|
| 129 | - echo $action->renderHelp(); |
|
| 133 | + foreach($this->_actions as $action) { |
|
| 134 | + echo $action->renderHelp(); |
|
| 135 | + } |
|
| 130 | 136 | } |
| 131 | 137 | } |
| 132 | 138 | |
@@ -152,8 +158,9 @@ discard block |
||
| 152 | 158 | mkdir($dir); |
| 153 | 159 | echo "creating $dir\n"; |
| 154 | 160 | } |
| 155 | - if(is_dir($dir)) |
|
| 156 | - chmod($dir, $mask); |
|
| 161 | + if(is_dir($dir)) { |
|
| 162 | + chmod($dir, $mask); |
|
| 163 | + } |
|
| 157 | 164 | } |
| 158 | 165 | |
| 159 | 166 | protected function createFile($filename, $content) |
@@ -174,16 +181,19 @@ discard block |
||
| 174 | 181 | public function renderHelp() |
| 175 | 182 | { |
| 176 | 183 | $params = array(); |
| 177 | - foreach($this->parameters as $v) |
|
| 178 | - $params[] = '<'.$v.'>'; |
|
| 184 | + foreach($this->parameters as $v) { |
|
| 185 | + $params[] = '<'.$v.'>'; |
|
| 186 | + } |
|
| 179 | 187 | $parameters = join($params, ' '); |
| 180 | 188 | $options = array(); |
| 181 | - foreach($this->optional as $v) |
|
| 182 | - $options[] = '['.$v.']'; |
|
| 189 | + foreach($this->optional as $v) { |
|
| 190 | + $options[] = '['.$v.']'; |
|
| 191 | + } |
|
| 183 | 192 | $optional = (strlen($parameters) ? ' ' : ''). join($options, ' '); |
| 184 | 193 | $description=''; |
| 185 | - foreach(explode("\n", wordwrap($this->description,65)) as $line) |
|
| 186 | - $description .= ' '.$line."\n"; |
|
| 194 | + foreach(explode("\n", wordwrap($this->description,65)) as $line) { |
|
| 195 | + $description .= ' '.$line."\n"; |
|
| 196 | + } |
|
| 187 | 197 | return <<<EOD |
| 188 | 198 | {$this->action} {$parameters}{$optional} |
| 189 | 199 | {$description} |
@@ -207,8 +217,7 @@ discard block |
||
| 207 | 217 | } |
| 208 | 218 | |
| 209 | 219 | return Prado::getApplication(); |
| 210 | - } |
|
| 211 | - else |
|
| 220 | + } else |
|
| 212 | 221 | { |
| 213 | 222 | PradoCommandLineInterpreter::printGreeting(); |
| 214 | 223 | echo '+'.str_repeat('-',77)."+\n"; |
@@ -245,15 +254,17 @@ discard block |
||
| 245 | 254 | */ |
| 246 | 255 | protected function createNewPradoProject($dir) |
| 247 | 256 | { |
| 248 | - if(strlen(trim($dir)) == 0) |
|
| 249 | - return; |
|
| 257 | + if(strlen(trim($dir)) == 0) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 250 | 260 | |
| 251 | 261 | $rootPath = realpath(dirname(trim($dir))); |
| 252 | 262 | |
| 253 | - if(basename($dir)!=='.') |
|
| 254 | - $basePath = $rootPath.DIRECTORY_SEPARATOR.basename($dir); |
|
| 255 | - else |
|
| 256 | - $basePath = $rootPath; |
|
| 263 | + if(basename($dir)!=='.') { |
|
| 264 | + $basePath = $rootPath.DIRECTORY_SEPARATOR.basename($dir); |
|
| 265 | + } else { |
|
| 266 | + $basePath = $rootPath; |
|
| 267 | + } |
|
| 257 | 268 | $appName = basename($basePath); |
| 258 | 269 | $assetPath = $basePath.DIRECTORY_SEPARATOR.'assets'; |
| 259 | 270 | $protectedPath = $basePath.DIRECTORY_SEPARATOR.'protected'; |
@@ -392,8 +403,9 @@ discard block |
||
| 392 | 403 | |
| 393 | 404 | protected function createTestFixtures($dir) |
| 394 | 405 | { |
| 395 | - if(strlen(trim($dir)) == 0) |
|
| 396 | - return; |
|
| 406 | + if(strlen(trim($dir)) == 0) { |
|
| 407 | + return; |
|
| 408 | + } |
|
| 397 | 409 | |
| 398 | 410 | $rootPath = realpath(dirname(trim($dir))); |
| 399 | 411 | $basePath = $rootPath.'/'.basename($dir); |
@@ -459,8 +471,9 @@ discard block |
||
| 459 | 471 | |
| 460 | 472 | public function performAction($args) |
| 461 | 473 | { |
| 462 | - if(count($args) > 1) |
|
| 463 | - $app = $this->initializePradoApplication($args[1]); |
|
| 474 | + if(count($args) > 1) { |
|
| 475 | + $app = $this->initializePradoApplication($args[1]); |
|
| 476 | + } |
|
| 464 | 477 | return true; |
| 465 | 478 | } |
| 466 | 479 | } |
@@ -483,10 +496,11 @@ discard block |
||
| 483 | 496 | public function performAction($args) |
| 484 | 497 | { |
| 485 | 498 | $dir = realpath($args[1]); |
| 486 | - if($dir !== false && is_dir($dir)) |
|
| 487 | - $this->runUnitTests($dir,$args); |
|
| 488 | - else |
|
| 489 | - echo '** Unable to find directory "'.$args[1]."\".\n"; |
|
| 499 | + if($dir !== false && is_dir($dir)) { |
|
| 500 | + $this->runUnitTests($dir,$args); |
|
| 501 | + } else { |
|
| 502 | + echo '** Unable to find directory "'.$args[1]."\".\n"; |
|
| 503 | + } |
|
| 490 | 504 | return true; |
| 491 | 505 | } |
| 492 | 506 | |
@@ -503,8 +517,9 @@ discard block |
||
| 503 | 517 | protected function runUnitTests($dir, $args) |
| 504 | 518 | { |
| 505 | 519 | $app_dir = $this->getAppDir($dir); |
| 506 | - if($app_dir !== false) |
|
| 507 | - $this->initializePradoApplication($app_dir.'/../'); |
|
| 520 | + if($app_dir !== false) { |
|
| 521 | + $this->initializePradoApplication($app_dir.'/../'); |
|
| 522 | + } |
|
| 508 | 523 | |
| 509 | 524 | $this->initializeTestRunner(); |
| 510 | 525 | $test_dir = $this->getTestDir($dir); |
@@ -514,8 +529,7 @@ discard block |
||
| 514 | 529 | $running_dir = substr(str_replace(realpath('./'),'',$test_dir),1); |
| 515 | 530 | echo 'Running unit tests in directory "'.$running_dir."\":\n"; |
| 516 | 531 | $test->run(new TextReporter()); |
| 517 | - } |
|
| 518 | - else |
|
| 532 | + } else |
|
| 519 | 533 | { |
| 520 | 534 | $running_dir = substr(str_replace(realpath('./'),'',$dir),1); |
| 521 | 535 | echo '** Unable to find test directory "'.$running_dir.'/unit" or "'.$running_dir.'/tests/unit".'."\n"; |
@@ -525,24 +539,27 @@ discard block |
||
| 525 | 539 | protected function getAppDir($dir) |
| 526 | 540 | { |
| 527 | 541 | $app_dir = realpath($dir.'/protected'); |
| 528 | - if($app_dir !== false && is_dir($app_dir)) |
|
| 529 | - return $app_dir; |
|
| 542 | + if($app_dir !== false && is_dir($app_dir)) { |
|
| 543 | + return $app_dir; |
|
| 544 | + } |
|
| 530 | 545 | return realpath($dir.'/../protected'); |
| 531 | 546 | } |
| 532 | 547 | |
| 533 | 548 | protected function getTestDir($dir) |
| 534 | 549 | { |
| 535 | 550 | $test_dir = realpath($dir.'/unit'); |
| 536 | - if($test_dir !== false && is_dir($test_dir)) |
|
| 537 | - return $test_dir; |
|
| 551 | + if($test_dir !== false && is_dir($test_dir)) { |
|
| 552 | + return $test_dir; |
|
| 553 | + } |
|
| 538 | 554 | return realpath($dir.'/tests/unit/'); |
| 539 | 555 | } |
| 540 | 556 | |
| 541 | 557 | protected function getUnitTestCases($dir,$args) |
| 542 | 558 | { |
| 543 | 559 | $matches = null; |
| 544 | - if(count($args) > 2) |
|
| 545 | - $matches = array_slice($args,2); |
|
| 560 | + if(count($args) > 2) { |
|
| 561 | + $matches = array_slice($args,2); |
|
| 562 | + } |
|
| 546 | 563 | $test=new GroupTest(' '); |
| 547 | 564 | $this->addTests($test,$dir,true,$matches); |
| 548 | 565 | $test->setLabel(implode(' ',$this->matches)); |
@@ -556,11 +573,13 @@ discard block |
||
| 556 | 573 | { |
| 557 | 574 | if(is_file($path.'/'.$entry) && (preg_match('/[^\s]*test[^\s]*\.php/', strtolower($entry)))) |
| 558 | 575 | { |
| 559 | - if($match==null||($match!=null && $this->hasMatch($match,$entry))) |
|
| 560 | - $test->addTestFile($path.'/'.$entry); |
|
| 576 | + if($match==null||($match!=null && $this->hasMatch($match,$entry))) { |
|
| 577 | + $test->addTestFile($path.'/'.$entry); |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + if($entry!=='.' && $entry!=='..' && is_dir($path.'/'.$entry) && $recursive) { |
|
| 581 | + $this->addTests($test,$path.'/'.$entry,$recursive,$match); |
|
| 561 | 582 | } |
| 562 | - if($entry!=='.' && $entry!=='..' && is_dir($path.'/'.$entry) && $recursive) |
|
| 563 | - $this->addTests($test,$path.'/'.$entry,$recursive,$match); |
|
| 564 | 583 | } |
| 565 | 584 | closedir($dir); |
| 566 | 585 | } |
@@ -602,44 +621,51 @@ discard block |
||
| 602 | 621 | { |
| 603 | 622 | $config = $this->getActiveRecordConfig($app_dir); |
| 604 | 623 | $output = $this->getOutputFile($app_dir, $args[2]); |
| 605 | - if(is_file($output)) |
|
| 606 | - echo "** File $output already exists, skiping. \n"; |
|
| 607 | - else if($config !== false && $output !== false) |
|
| 608 | - $this->generateActiveRecord($config, $args[1], $output); |
|
| 624 | + if(is_file($output)) { |
|
| 625 | + echo "** File $output already exists, skiping. \n"; |
|
| 626 | + } else if($config !== false && $output !== false) { |
|
| 627 | + $this->generateActiveRecord($config, $args[1], $output); |
|
| 628 | + } |
|
| 609 | 629 | } |
| 610 | 630 | return true; |
| 611 | 631 | } |
| 612 | 632 | |
| 613 | 633 | protected function getAppDir($dir=".") |
| 614 | 634 | { |
| 615 | - if(is_dir($dir)) |
|
| 616 | - return realpath($dir); |
|
| 617 | - if(false !== ($app_dir = realpath($dir.'/protected/')) && is_dir($app_dir)) |
|
| 618 | - return $app_dir; |
|
| 635 | + if(is_dir($dir)) { |
|
| 636 | + return realpath($dir); |
|
| 637 | + } |
|
| 638 | + if(false !== ($app_dir = realpath($dir.'/protected/')) && is_dir($app_dir)) { |
|
| 639 | + return $app_dir; |
|
| 640 | + } |
|
| 619 | 641 | echo '** Unable to find directory "'.$dir."\".\n"; |
| 620 | 642 | return false; |
| 621 | 643 | } |
| 622 | 644 | |
| 623 | 645 | protected function getXmlFile($app_dir) |
| 624 | 646 | { |
| 625 | - if(false !== ($xml = realpath($app_dir.'/application.xml')) && is_file($xml)) |
|
| 626 | - return $xml; |
|
| 627 | - if(false !== ($xml = realpath($app_dir.'/protected/application.xml')) && is_file($xml)) |
|
| 628 | - return $xml; |
|
| 647 | + if(false !== ($xml = realpath($app_dir.'/application.xml')) && is_file($xml)) { |
|
| 648 | + return $xml; |
|
| 649 | + } |
|
| 650 | + if(false !== ($xml = realpath($app_dir.'/protected/application.xml')) && is_file($xml)) { |
|
| 651 | + return $xml; |
|
| 652 | + } |
|
| 629 | 653 | echo '** Unable to find application.xml in '.$app_dir."\n"; |
| 630 | 654 | return false; |
| 631 | 655 | } |
| 632 | 656 | |
| 633 | 657 | protected function getActiveRecordConfig($app_dir) |
| 634 | 658 | { |
| 635 | - if(false === ($xml=$this->getXmlFile($app_dir))) |
|
| 636 | - return false; |
|
| 659 | + if(false === ($xml=$this->getXmlFile($app_dir))) { |
|
| 660 | + return false; |
|
| 661 | + } |
|
| 637 | 662 | if(false !== ($app=$this->initializePradoApplication($app_dir))) |
| 638 | 663 | { |
| 639 | 664 | Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
| 640 | - foreach($app->getModules() as $module) |
|
| 641 | - if($module instanceof TActiveRecordConfig) |
|
| 665 | + foreach($app->getModules() as $module) { |
|
| 666 | + if($module instanceof TActiveRecordConfig) |
|
| 642 | 667 | return $module; |
| 668 | + } |
|
| 643 | 669 | echo '** Unable to find TActiveRecordConfig module in '.$xml."\n"; |
| 644 | 670 | } |
| 645 | 671 | return false; |
@@ -647,13 +673,15 @@ discard block |
||
| 647 | 673 | |
| 648 | 674 | protected function getOutputFile($app_dir, $namespace) |
| 649 | 675 | { |
| 650 | - if(is_file($namespace) && strpos($namespace, $app_dir)===0) |
|
| 651 | - return $namespace; |
|
| 676 | + if(is_file($namespace) && strpos($namespace, $app_dir)===0) { |
|
| 677 | + return $namespace; |
|
| 678 | + } |
|
| 652 | 679 | $file = Prado::getPathOfNamespace($namespace, ".php"); |
| 653 | 680 | if($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) |
| 654 | 681 | { |
| 655 | - if(strpos($path, $app_dir)===0) |
|
| 656 | - return $file; |
|
| 682 | + if(strpos($path, $app_dir)===0) { |
|
| 683 | + return $file; |
|
| 684 | + } |
|
| 657 | 685 | } |
| 658 | 686 | echo '** Output file '.$file.' must be within directory '.$app_dir."\n"; |
| 659 | 687 | return false; |
@@ -669,12 +697,12 @@ discard block |
||
| 669 | 697 | { |
| 670 | 698 | echo '** Unable to find table or view "'.$tablename.'" in "'.$manager->getDbConnection()->getConnectionString()."\".\n"; |
| 671 | 699 | return false; |
| 672 | - } |
|
| 673 | - else |
|
| 700 | + } else |
|
| 674 | 701 | { |
| 675 | 702 | $properties = array(); |
| 676 | - foreach($tableInfo->getColumns() as $field=>$column) |
|
| 677 | - $properties[] = $this->generateProperty($field,$column); |
|
| 703 | + foreach($tableInfo->getColumns() as $field=>$column) { |
|
| 704 | + $properties[] = $this->generateProperty($field,$column); |
|
| 705 | + } |
|
| 678 | 706 | } |
| 679 | 707 | |
| 680 | 708 | $classname = basename($output, '.php'); |
@@ -782,43 +810,51 @@ discard block |
||
| 782 | 810 | } |
| 783 | 811 | |
| 784 | 812 | protected function getAppDir($dir=".") { |
| 785 | - if (is_dir($dir)) |
|
| 786 | - return realpath($dir); |
|
| 787 | - if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) |
|
| 788 | - return $app_dir; |
|
| 813 | + if (is_dir($dir)) { |
|
| 814 | + return realpath($dir); |
|
| 815 | + } |
|
| 816 | + if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) { |
|
| 817 | + return $app_dir; |
|
| 818 | + } |
|
| 789 | 819 | echo '** Unable to find directory "' . $dir . "\".\n"; |
| 790 | 820 | return false; |
| 791 | 821 | } |
| 792 | 822 | |
| 793 | 823 | protected function getXmlFile($app_dir) { |
| 794 | - if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) |
|
| 795 | - return $xml; |
|
| 796 | - if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) |
|
| 797 | - return $xml; |
|
| 824 | + if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) { |
|
| 825 | + return $xml; |
|
| 826 | + } |
|
| 827 | + if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) { |
|
| 828 | + return $xml; |
|
| 829 | + } |
|
| 798 | 830 | echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
| 799 | 831 | return false; |
| 800 | 832 | } |
| 801 | 833 | |
| 802 | 834 | protected function getActiveRecordConfig($app_dir) { |
| 803 | - if (false === ($xml = $this->getXmlFile($app_dir))) |
|
| 804 | - return false; |
|
| 835 | + if (false === ($xml = $this->getXmlFile($app_dir))) { |
|
| 836 | + return false; |
|
| 837 | + } |
|
| 805 | 838 | if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
| 806 | 839 | Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
| 807 | - foreach ($app->getModules() as $module) |
|
| 808 | - if ($module instanceof TActiveRecordConfig) |
|
| 840 | + foreach ($app->getModules() as $module) { |
|
| 841 | + if ($module instanceof TActiveRecordConfig) |
|
| 809 | 842 | return $module; |
| 843 | + } |
|
| 810 | 844 | echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
| 811 | 845 | } |
| 812 | 846 | return false; |
| 813 | 847 | } |
| 814 | 848 | |
| 815 | 849 | protected function getOutputFile($app_dir, $namespace) { |
| 816 | - if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
| 817 | - return $namespace; |
|
| 850 | + if (is_file($namespace) && strpos($namespace, $app_dir) === 0) { |
|
| 851 | + return $namespace; |
|
| 852 | + } |
|
| 818 | 853 | $file = Prado::getPathOfNamespace($namespace, ""); |
| 819 | 854 | if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
| 820 | - if (strpos($path, $app_dir) === 0) |
|
| 821 | - return $file; |
|
| 855 | + if (strpos($path, $app_dir) === 0) { |
|
| 856 | + return $file; |
|
| 857 | + } |
|
| 822 | 858 | } |
| 823 | 859 | echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
| 824 | 860 | return false; |
@@ -848,15 +884,16 @@ discard block |
||
| 848 | 884 | if(count($input) > 2) |
| 849 | 885 | { |
| 850 | 886 | $app_dir = '.'; |
| 851 | - if(Prado::getApplication()!==null) |
|
| 852 | - $app_dir = dirname(Prado::getApplication()->getBasePath()); |
|
| 887 | + if(Prado::getApplication()!==null) { |
|
| 888 | + $app_dir = dirname(Prado::getApplication()->getBasePath()); |
|
| 889 | + } |
|
| 853 | 890 | $args = array($input[0],$input[1], $input[2],$app_dir); |
| 854 | - if(count($input)>3) |
|
| 855 | - $args = array($input[0],$input[1], $input[2],$app_dir,'soap'); |
|
| 891 | + if(count($input)>3) { |
|
| 892 | + $args = array($input[0],$input[1], $input[2],$app_dir,'soap'); |
|
| 893 | + } |
|
| 856 | 894 | $cmd = new PradoCommandLineActiveRecordGen; |
| 857 | 895 | $cmd->performAction($args); |
| 858 | - } |
|
| 859 | - else |
|
| 896 | + } else |
|
| 860 | 897 | { |
| 861 | 898 | echo "\n Usage: generate table_name Application.pages.RecordClassName\n"; |
| 862 | 899 | } |
@@ -233,6 +233,7 @@ discard block |
||
| 233 | 233 | * Returns formatted profiling information. |
| 234 | 234 | * |
| 235 | 235 | * @param string output format (auto, plain or html), default auto |
| 236 | + * @param string $format |
|
| 236 | 237 | * @see display() |
| 237 | 238 | * @access private |
| 238 | 239 | */ |
@@ -363,6 +364,7 @@ discard block |
||
| 363 | 364 | * Enters code section. |
| 364 | 365 | * |
| 365 | 366 | * @param string name of the code section |
| 367 | + * @param string $name |
|
| 366 | 368 | * @see start(), leaveSection() |
| 367 | 369 | * @access public |
| 368 | 370 | */ |
@@ -398,6 +400,7 @@ discard block |
||
| 398 | 400 | * Leaves code section. |
| 399 | 401 | * |
| 400 | 402 | * @param string name of the marker to be set |
| 403 | + * @param string $name |
|
| 401 | 404 | * @see stop(), enterSection() |
| 402 | 405 | * @access public |
| 403 | 406 | */ |
@@ -436,7 +439,7 @@ discard block |
||
| 436 | 439 | /** |
| 437 | 440 | * Wrapper for microtime(). |
| 438 | 441 | * |
| 439 | - * @return float |
|
| 442 | + * @return string |
|
| 440 | 443 | * @access private |
| 441 | 444 | * @since 1.3.0 |
| 442 | 445 | */ |
@@ -308,7 +308,7 @@ |
||
| 308 | 308 | /** |
| 309 | 309 | * Wrapper for microtime(). |
| 310 | 310 | * |
| 311 | - * @return float |
|
| 311 | + * @return string |
|
| 312 | 312 | * @access private |
| 313 | 313 | * @since 1.3.0 |
| 314 | 314 | */ |
@@ -67,6 +67,9 @@ discard block |
||
| 67 | 67 | $this->displayTreeInternal(array_keys($this->_baseClasses),0); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + /** |
|
| 71 | + * @param integer $level |
|
| 72 | + */ |
|
| 70 | 73 | public function displayTreeInternal($classNames,$level) |
| 71 | 74 | { |
| 72 | 75 | foreach($classNames as $className) |
@@ -153,6 +156,9 @@ discard block |
||
| 153 | 156 | } |
| 154 | 157 | } |
| 155 | 158 | |
| 159 | + /** |
|
| 160 | + * @param string $path |
|
| 161 | + */ |
|
| 156 | 162 | protected function isValidPath($path) |
| 157 | 163 | { |
| 158 | 164 | if(is_dir($path)) |
@@ -161,6 +167,9 @@ discard block |
||
| 161 | 167 | return basename($path)!==basename($path,'.php') && !isset($this->_exclusions[basename($path)]); |
| 162 | 168 | } |
| 163 | 169 | |
| 170 | + /** |
|
| 171 | + * @param string $path |
|
| 172 | + */ |
|
| 164 | 173 | public function getSourceFiles($path) |
| 165 | 174 | { |
| 166 | 175 | $files=array(); |
@@ -227,6 +236,9 @@ discard block |
||
| 227 | 236 | |
| 228 | 237 | } |
| 229 | 238 | |
| 239 | + /** |
|
| 240 | + * @param PradoVTMDocument $doc |
|
| 241 | + */ |
|
| 230 | 242 | private function processObjectType($objectType,$objectInfo,$prefix,$doc) |
| 231 | 243 | { |
| 232 | 244 | foreach($objectInfo['Properties'] as $name=>$property) |
@@ -35,24 +35,27 @@ discard block |
||
| 35 | 35 | $this->_exclusions=array(); |
| 36 | 36 | foreach($exclusions as $exclusion) |
| 37 | 37 | { |
| 38 | - if($exclusion[0]==='/') |
|
| 39 | - $this->_exclusions[realpath($frameworkPath.'/'.$exclusion)]=true; |
|
| 40 | - else |
|
| 41 | - $this->_exclusions[$exclusion]=true; |
|
| 38 | + if($exclusion[0]==='/') { |
|
| 39 | + $this->_exclusions[realpath($frameworkPath.'/'.$exclusion)]=true; |
|
| 40 | + } else { |
|
| 41 | + $this->_exclusions[$exclusion]=true; |
|
| 42 | + } |
|
| 42 | 43 | } |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | public function buildTree() |
| 46 | 47 | { |
| 47 | 48 | $sourceFiles=$this->getSourceFiles($this->_frameworkPath); |
| 48 | - foreach($sourceFiles as $sourceFile) |
|
| 49 | - $this->parseFile($sourceFile); |
|
| 49 | + foreach($sourceFiles as $sourceFile) { |
|
| 50 | + $this->parseFile($sourceFile); |
|
| 51 | + } |
|
| 50 | 52 | ksort($this->_classes); |
| 51 | 53 | foreach(array_keys($this->_classes) as $className) |
| 52 | 54 | { |
| 53 | 55 | $parentClass=$this->_classes[$className]['ParentClass']; |
| 54 | - if(isset($this->_classes[$parentClass])) |
|
| 55 | - $this->_classes[$parentClass]['ChildClasses'][]=$className; |
|
| 56 | + if(isset($this->_classes[$parentClass])) { |
|
| 57 | + $this->_classes[$parentClass]['ChildClasses'][]=$className; |
|
| 58 | + } |
|
| 56 | 59 | } |
| 57 | 60 | echo "\nClass tree built successfully. Total ".count($this->_classes)." classes found.\n"; |
| 58 | 61 | } |
@@ -83,16 +86,18 @@ discard block |
||
| 83 | 86 | $classFile=strtr(substr($sourceFile,strlen($this->_frameworkPath)),'\\','/'); |
| 84 | 87 | echo "Parsing $classFile...\n"; |
| 85 | 88 | $content=file_get_contents($sourceFile); |
| 86 | - if(preg_match('/@package\s+([\w\.]+)\s*/msS',$content,$matches)>0) |
|
| 87 | - $package=$matches[1]; |
|
| 88 | - else |
|
| 89 | - $package=''; |
|
| 89 | + if(preg_match('/@package\s+([\w\.]+)\s*/msS',$content,$matches)>0) { |
|
| 90 | + $package=$matches[1]; |
|
| 91 | + } else { |
|
| 92 | + $package=''; |
|
| 93 | + } |
|
| 90 | 94 | $n=preg_match_all(self::REGEX_RULES,$content,$matches,PREG_SET_ORDER); |
| 91 | 95 | for($i=0;$i<$n;++$i) |
| 92 | 96 | { |
| 93 | 97 | $className=$matches[$i][2]; |
| 94 | - if(isset($this->_classes[$className])) |
|
| 95 | - throw new Exception("Class $className is defined in both $sourceFile and ".$this->_classes[$className]->ClassFile); |
|
| 98 | + if(isset($this->_classes[$className])) { |
|
| 99 | + throw new Exception("Class $className is defined in both $sourceFile and ".$this->_classes[$className]->ClassFile); |
|
| 100 | + } |
|
| 96 | 101 | $c=new TComponentReflection($className); |
| 97 | 102 | $properties=$c->getProperties(); |
| 98 | 103 | $this->parseMethodComments($properties); |
@@ -130,35 +135,38 @@ discard block |
||
| 130 | 135 | $pos2=strpos($s,'.'); |
| 131 | 136 | if($pos1===false) |
| 132 | 137 | { |
| 133 | - if($pos2!==false) |
|
| 134 | - $method['comments']=substr($s,0,$pos2); |
|
| 135 | - else |
|
| 136 | - $method['comments']=$s; |
|
| 137 | - } |
|
| 138 | - else if($pos1>0) |
|
| 138 | + if($pos2!==false) { |
|
| 139 | + $method['comments']=substr($s,0,$pos2); |
|
| 140 | + } else { |
|
| 141 | + $method['comments']=$s; |
|
| 142 | + } |
|
| 143 | + } else if($pos1>0) |
|
| 139 | 144 | { |
| 140 | - if($pos2 && $pos2<$pos1) // use the first line as comment |
|
| 145 | + if($pos2 && $pos2<$pos1) { |
|
| 146 | + // use the first line as comment |
|
| 141 | 147 | $method['comments']=substr($s,0,$pos2); |
| 142 | - else |
|
| 143 | - $method['comments']=substr($s,0,$pos1); |
|
| 144 | - } |
|
| 145 | - else |
|
| 148 | + } else { |
|
| 149 | + $method['comments']=substr($s,0,$pos1); |
|
| 150 | + } |
|
| 151 | + } else |
|
| 146 | 152 | { |
| 147 | 153 | $matches=array(); |
| 148 | - if(preg_match('/@return\s+[\w\|]+\s+([^\.]*)/',$s,$matches)>0) |
|
| 149 | - $method['comments']=$matches[1]; |
|
| 150 | - else |
|
| 151 | - $method['comments']=''; |
|
| 154 | + if(preg_match('/@return\s+[\w\|]+\s+([^\.]*)/',$s,$matches)>0) { |
|
| 155 | + $method['comments']=$matches[1]; |
|
| 156 | + } else { |
|
| 157 | + $method['comments']=''; |
|
| 158 | + } |
|
| 152 | 159 | } |
| 153 | 160 | } |
| 154 | 161 | } |
| 155 | 162 | |
| 156 | 163 | protected function isValidPath($path) |
| 157 | 164 | { |
| 158 | - if(is_dir($path)) |
|
| 159 | - return !isset($this->_exclusions[basename($path)]) && !isset($this->_exclusions[$path]); |
|
| 160 | - else |
|
| 161 | - return basename($path)!==basename($path,'.php') && !isset($this->_exclusions[basename($path)]); |
|
| 165 | + if(is_dir($path)) { |
|
| 166 | + return !isset($this->_exclusions[basename($path)]) && !isset($this->_exclusions[$path]); |
|
| 167 | + } else { |
|
| 168 | + return basename($path)!==basename($path,'.php') && !isset($this->_exclusions[basename($path)]); |
|
| 169 | + } |
|
| 162 | 170 | } |
| 163 | 171 | |
| 164 | 172 | public function getSourceFiles($path) |
@@ -167,15 +175,17 @@ discard block |
||
| 167 | 175 | $folder=opendir($path); |
| 168 | 176 | while($file=readdir($folder)) |
| 169 | 177 | { |
| 170 | - if($file==='.' || $file==='..') |
|
| 171 | - continue; |
|
| 178 | + if($file==='.' || $file==='..') { |
|
| 179 | + continue; |
|
| 180 | + } |
|
| 172 | 181 | $fullPath=realpath($path.'/'.$file); |
| 173 | 182 | if($this->isValidPath($fullPath)) |
| 174 | 183 | { |
| 175 | - if(is_file($fullPath)) |
|
| 176 | - $files[]=$fullPath; |
|
| 177 | - else |
|
| 178 | - $files=array_merge($files,$this->getSourceFiles($fullPath)); |
|
| 184 | + if(is_file($fullPath)) { |
|
| 185 | + $files[]=$fullPath; |
|
| 186 | + } else { |
|
| 187 | + $files=array_merge($files,$this->getSourceFiles($fullPath)); |
|
| 188 | + } |
|
| 179 | 189 | } |
| 180 | 190 | } |
| 181 | 191 | closedir($folder); |
@@ -207,12 +217,15 @@ discard block |
||
| 207 | 217 | foreach($classInfo['Properties'] as $name=>$property) |
| 208 | 218 | { |
| 209 | 219 | $type=$property['type']; |
| 210 | - if(isset($this->_classes[$type]) && ($type==='TFont' || strrpos($type,'Style')===strlen($type)-5 && $type!=='TStyle')) |
|
| 211 | - $this->processObjectType($type,$this->_classes[$type],$name,$docVTM); |
|
| 212 | - if($property['readonly'] || $property['protected']) |
|
| 213 | - continue; |
|
| 214 | - if(($type=$this->checkType($className,$name,$property['type']))!=='') |
|
| 215 | - $docVTM->addAttribute($name,$type); |
|
| 220 | + if(isset($this->_classes[$type]) && ($type==='TFont' || strrpos($type,'Style')===strlen($type)-5 && $type!=='TStyle')) { |
|
| 221 | + $this->processObjectType($type,$this->_classes[$type],$name,$docVTM); |
|
| 222 | + } |
|
| 223 | + if($property['readonly'] || $property['protected']) { |
|
| 224 | + continue; |
|
| 225 | + } |
|
| 226 | + if(($type=$this->checkType($className,$name,$property['type']))!=='') { |
|
| 227 | + $docVTM->addAttribute($name,$type); |
|
| 228 | + } |
|
| 216 | 229 | } |
| 217 | 230 | foreach($classInfo['Events'] as $name=>$event) |
| 218 | 231 | { |
@@ -231,25 +244,32 @@ discard block |
||
| 231 | 244 | { |
| 232 | 245 | foreach($objectInfo['Properties'] as $name=>$property) |
| 233 | 246 | { |
| 234 | - if($property['type']==='TFont') |
|
| 235 | - $this->processObjectType('TFont',$this->_classes['TFont'],$prefix.'.'.$name,$doc); |
|
| 236 | - if($property['readonly'] || $property['protected']) |
|
| 237 | - continue; |
|
| 238 | - if(($type=$this->checkType($objectType,$name,$property['type']))!=='') |
|
| 239 | - $doc->addAttribute($prefix.'.'.$name,$type); |
|
| 247 | + if($property['type']==='TFont') { |
|
| 248 | + $this->processObjectType('TFont',$this->_classes['TFont'],$prefix.'.'.$name,$doc); |
|
| 249 | + } |
|
| 250 | + if($property['readonly'] || $property['protected']) { |
|
| 251 | + continue; |
|
| 252 | + } |
|
| 253 | + if(($type=$this->checkType($objectType,$name,$property['type']))!=='') { |
|
| 254 | + $doc->addAttribute($prefix.'.'.$name,$type); |
|
| 255 | + } |
|
| 240 | 256 | } |
| 241 | 257 | } |
| 242 | 258 | |
| 243 | 259 | private function checkType($className,$propertyName,$type) |
| 244 | 260 | { |
| 245 | - if(strrpos($propertyName,'Color')===strlen($propertyName)-5) |
|
| 246 | - return 'color'; |
|
| 247 | - if($propertyName==='Style') |
|
| 248 | - return 'style'; |
|
| 249 | - if($type==='boolean') |
|
| 250 | - return array('true','false'); |
|
| 251 | - if($type==='string' || $type==='integer' || $type==='ITemplate') |
|
| 252 | - return 'text'; |
|
| 261 | + if(strrpos($propertyName,'Color')===strlen($propertyName)-5) { |
|
| 262 | + return 'color'; |
|
| 263 | + } |
|
| 264 | + if($propertyName==='Style') { |
|
| 265 | + return 'style'; |
|
| 266 | + } |
|
| 267 | + if($type==='boolean') { |
|
| 268 | + return array('true','false'); |
|
| 269 | + } |
|
| 270 | + if($type==='string' || $type==='integer' || $type==='ITemplate') { |
|
| 271 | + return 'text'; |
|
| 272 | + } |
|
| 253 | 273 | return ''; |
| 254 | 274 | } |
| 255 | 275 | } |
@@ -100,6 +100,9 @@ |
||
| 100 | 100 | private $_filesElement; |
| 101 | 101 | private $_document; |
| 102 | 102 | |
| 103 | + /** |
|
| 104 | + * @param string $version |
|
| 105 | + */ |
|
| 103 | 106 | public function __construct($version) |
| 104 | 107 | { |
| 105 | 108 | $this->_document = new DOMDocument('1.0', 'utf-8'); |
@@ -63,8 +63,7 @@ |
||
| 63 | 63 | $option->setAttribute('caption',''); |
| 64 | 64 | $attrib->appendChild($option); |
| 65 | 65 | } |
| 66 | - } |
|
| 67 | - else if($attribType!=='') |
|
| 66 | + } else if($attribType!=='') |
|
| 68 | 67 | { |
| 69 | 68 | $attrib->setAttribute('type',$attribType); |
| 70 | 69 | } |
@@ -10,6 +10,9 @@ |
||
| 10 | 10 | private $_index; |
| 11 | 11 | private $_api; |
| 12 | 12 | |
| 13 | + /** |
|
| 14 | + * @param string $api |
|
| 15 | + */ |
|
| 13 | 16 | public function __construct($index_file, $api) |
| 14 | 17 | { |
| 15 | 18 | $this->_api = $api; |
@@ -62,8 +62,9 @@ |
||
| 62 | 62 | while (false !== ($entry = $d->read())) |
| 63 | 63 | { |
| 64 | 64 | $filepath = $path.'/'.$entry; |
| 65 | - if(is_file($filepath) && strpos($entry, 'class-')===0) |
|
| 66 | - $files[] = realpath($filepath); |
|
| 65 | + if(is_file($filepath) && strpos($entry, 'class-')===0) { |
|
| 66 | + $files[] = realpath($filepath); |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | 69 | $d->close(); |
| 69 | 70 | return $files; |
@@ -8,6 +8,10 @@ discard block |
||
| 8 | 8 | private $_base; |
| 9 | 9 | private $_source; |
| 10 | 10 | |
| 11 | + /** |
|
| 12 | + * @param string $base |
|
| 13 | + * @param string $source |
|
| 14 | + */ |
|
| 11 | 15 | public function __construct($index_file, $base, $source) |
| 12 | 16 | { |
| 13 | 17 | $this->_index = new Zend_Search_Lucene($index_file, true); |
@@ -37,6 +41,10 @@ discard block |
||
| 37 | 41 | echo "\n {$count} files indexed.\n"; |
| 38 | 42 | } |
| 39 | 43 | |
| 44 | + /** |
|
| 45 | + * @param string $content |
|
| 46 | + * @param integer $mtime |
|
| 47 | + */ |
|
| 40 | 48 | public function add($content, $section, $mtime) |
| 41 | 49 | { |
| 42 | 50 | foreach($this->split_headings($content) as $headers) |
@@ -71,6 +71,9 @@ |
||
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $filename |
|
| 76 | + */ |
|
| 74 | 77 | function include_figure($info, $filename) |
| 75 | 78 | { |
| 76 | 79 | $width = sprintf('%0.2f', $info[0]/(135/2.54)); |
@@ -115,16 +115,14 @@ discard block |
||
| 115 | 115 | $target = $this->get_current_path().'/'.substr($matches[1],1); |
| 116 | 116 | return '\hyperlink{'.$target.'}{'.$matches[2].'}'; |
| 117 | 117 | } |
| 118 | - } |
|
| 119 | - else |
|
| 118 | + } else |
|
| 120 | 119 | { |
| 121 | 120 | $page = strtolower(str_replace('?page=', '', $matches[1])); |
| 122 | 121 | $page = str_replace('.','/',$page); |
| 123 | 122 | $page = str_replace('#','.page/',$page); |
| 124 | 123 | return '\hyperlink{'.$page.'}{'.$matches[2].'}'; |
| 125 | 124 | } |
| 126 | - } |
|
| 127 | - else if(is_int(strpos($matches[1],'?'))) |
|
| 125 | + } else if(is_int(strpos($matches[1],'?'))) |
|
| 128 | 126 | { |
| 129 | 127 | $page = str_replace('?page=','',$matches[1]); |
| 130 | 128 | return '\hyperlink{'.$page.'}{'.$matches[2].'}'; |
@@ -257,10 +255,11 @@ discard block |
||
| 257 | 255 | function table_column($matches) |
| 258 | 256 | { |
| 259 | 257 | $width = $this->_tabular_widths[$this->_tabular_col]; |
| 260 | - if($this->_tabular_col >= $this->_tabular_total-1) |
|
| 261 | - $this->_tabular_col = 0; |
|
| 262 | - else |
|
| 263 | - $this->_tabular_col++; |
|
| 258 | + if($this->_tabular_col >= $this->_tabular_total-1) { |
|
| 259 | + $this->_tabular_col = 0; |
|
| 260 | + } else { |
|
| 261 | + $this->_tabular_col++; |
|
| 262 | + } |
|
| 264 | 263 | return '\begin{minipage}{'.$width.'\textwidth}\vspace{3mm}'. |
| 265 | 264 | $matches[1].'\vspace{3mm}\end{minipage} & '; |
| 266 | 265 | } |
@@ -325,12 +324,10 @@ discard block |
||
| 325 | 324 | $code = preg_replace('/id="code-(\d+)"/', 'id="code_$1"', $matches[0]); |
| 326 | 325 | //var_dump($code); |
| 327 | 326 | return $code; |
| 328 | - } |
|
| 329 | - else if(preg_match('/id="[^"]+"/i', $matches[1])) |
|
| 327 | + } else if(preg_match('/id="[^"]+"/i', $matches[1])) |
|
| 330 | 328 | { |
| 331 | 329 | return $matches[0]; |
| 332 | - } |
|
| 333 | - else |
|
| 330 | + } else |
|
| 334 | 331 | { |
| 335 | 332 | $changes = str_replace('"source"', '"source block-content" id="code-'.$id.'"', $matches[0]); |
| 336 | 333 | return $changes; |
@@ -48,6 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Fetches posts from database with offset and limit. |
| 51 | + * @param double $offset |
|
| 51 | 52 | */ |
| 52 | 53 | protected function getPosts($offset, $limit) |
| 53 | 54 | { |
@@ -10,10 +10,12 @@ discard block |
||
| 10 | 10 | public function onInit($param) |
| 11 | 11 | { |
| 12 | 12 | parent::onInit($param); |
| 13 | - if(!$this->IsPostBack) // if the page is requested the first time |
|
| 13 | + if(!$this->IsPostBack) { |
|
| 14 | + // if the page is requested the first time |
|
| 14 | 15 | { |
| 15 | 16 | // get the total number of posts available |
| 16 | 17 | $this->Repeater->VirtualItemCount=PostRecord::finder()->count(); |
| 18 | + } |
|
| 17 | 19 | // populates post data into the repeater |
| 18 | 20 | $this->populateData(); |
| 19 | 21 | } |
@@ -40,8 +42,9 @@ discard block |
||
| 40 | 42 | { |
| 41 | 43 | $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize; |
| 42 | 44 | $limit=$this->Repeater->PageSize; |
| 43 | - if($offset+$limit>$this->Repeater->VirtualItemCount) |
|
| 44 | - $limit=$this->Repeater->VirtualItemCount-$offset; |
|
| 45 | + if($offset+$limit>$this->Repeater->VirtualItemCount) { |
|
| 46 | + $limit=$this->Repeater->VirtualItemCount-$offset; |
|
| 47 | + } |
|
| 45 | 48 | $this->Repeater->DataSource=$this->getPosts($offset,$limit); |
| 46 | 49 | $this->Repeater->dataBind(); |
| 47 | 50 | } |