@@ -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)); |
@@ -740,89 +740,89 @@ discard block |
||
| 740 | 740 | */ |
| 741 | 741 | class PradoCommandLineActiveRecordGenAll extends PradoCommandLineAction { |
| 742 | 742 | |
| 743 | - protected $action = 'generateAll'; |
|
| 744 | - protected $parameters = array('output'); |
|
| 745 | - protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix'); |
|
| 746 | - protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files."; |
|
| 747 | - private $_soap = false; |
|
| 748 | - private $_prefix = ''; |
|
| 749 | - private $_postfix = ''; |
|
| 750 | - private $_overwrite = false; |
|
| 751 | - |
|
| 752 | - public function performAction($args) { |
|
| 753 | - $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir(); |
|
| 754 | - $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false; |
|
| 755 | - $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false; |
|
| 756 | - $this->_prefix = count($args) > 5 ? $args[5] : ''; |
|
| 757 | - $this->_postfix = count($args) > 6 ? $args[6] : ''; |
|
| 758 | - |
|
| 759 | - if ($app_dir !== false) { |
|
| 760 | - $config = $this->getActiveRecordConfig($app_dir); |
|
| 761 | - |
|
| 762 | - $manager = TActiveRecordManager::getInstance(); |
|
| 763 | - $con = $manager->getDbConnection(); |
|
| 764 | - $con->Active = true; |
|
| 765 | - $command = $con->createCommand("Show Tables"); |
|
| 766 | - $dataReader = $command->query(); |
|
| 767 | - $dataReader->bindColumn(1, $table); |
|
| 768 | - $generator = new PHP_Shell_Extensions_ActiveRecord(); |
|
| 769 | - $tables = array(); |
|
| 770 | - while ($dataReader->read() !== false) { |
|
| 771 | - $tables[] = $table; |
|
| 772 | - } |
|
| 773 | - $con->Active = False; |
|
| 774 | - foreach ($tables as $key => $table) { |
|
| 775 | - $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix; |
|
| 776 | - if ($config !== false && $output !== false) { |
|
| 777 | - $generator->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite); |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - return true; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - 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; |
|
| 789 | - echo '** Unable to find directory "' . $dir . "\".\n"; |
|
| 790 | - return false; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - 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; |
|
| 798 | - echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
|
| 799 | - return false; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - protected function getActiveRecordConfig($app_dir) { |
|
| 803 | - if (false === ($xml = $this->getXmlFile($app_dir))) |
|
| 804 | - return false; |
|
| 805 | - if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
|
| 806 | - Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
|
| 807 | - foreach ($app->getModules() as $module) |
|
| 808 | - if ($module instanceof TActiveRecordConfig) |
|
| 809 | - return $module; |
|
| 810 | - echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
|
| 811 | - } |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - protected function getOutputFile($app_dir, $namespace) { |
|
| 816 | - if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
| 817 | - return $namespace; |
|
| 818 | - $file = Prado::getPathOfNamespace($namespace, ""); |
|
| 819 | - if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
|
| 820 | - if (strpos($path, $app_dir) === 0) |
|
| 821 | - return $file; |
|
| 822 | - } |
|
| 823 | - echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 743 | + protected $action = 'generateAll'; |
|
| 744 | + protected $parameters = array('output'); |
|
| 745 | + protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix'); |
|
| 746 | + protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files."; |
|
| 747 | + private $_soap = false; |
|
| 748 | + private $_prefix = ''; |
|
| 749 | + private $_postfix = ''; |
|
| 750 | + private $_overwrite = false; |
|
| 751 | + |
|
| 752 | + public function performAction($args) { |
|
| 753 | + $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir(); |
|
| 754 | + $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false; |
|
| 755 | + $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false; |
|
| 756 | + $this->_prefix = count($args) > 5 ? $args[5] : ''; |
|
| 757 | + $this->_postfix = count($args) > 6 ? $args[6] : ''; |
|
| 758 | + |
|
| 759 | + if ($app_dir !== false) { |
|
| 760 | + $config = $this->getActiveRecordConfig($app_dir); |
|
| 761 | + |
|
| 762 | + $manager = TActiveRecordManager::getInstance(); |
|
| 763 | + $con = $manager->getDbConnection(); |
|
| 764 | + $con->Active = true; |
|
| 765 | + $command = $con->createCommand("Show Tables"); |
|
| 766 | + $dataReader = $command->query(); |
|
| 767 | + $dataReader->bindColumn(1, $table); |
|
| 768 | + $generator = new PHP_Shell_Extensions_ActiveRecord(); |
|
| 769 | + $tables = array(); |
|
| 770 | + while ($dataReader->read() !== false) { |
|
| 771 | + $tables[] = $table; |
|
| 772 | + } |
|
| 773 | + $con->Active = False; |
|
| 774 | + foreach ($tables as $key => $table) { |
|
| 775 | + $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix; |
|
| 776 | + if ($config !== false && $output !== false) { |
|
| 777 | + $generator->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite); |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + return true; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + 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; |
|
| 789 | + echo '** Unable to find directory "' . $dir . "\".\n"; |
|
| 790 | + return false; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + 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; |
|
| 798 | + echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
|
| 799 | + return false; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + protected function getActiveRecordConfig($app_dir) { |
|
| 803 | + if (false === ($xml = $this->getXmlFile($app_dir))) |
|
| 804 | + return false; |
|
| 805 | + if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
|
| 806 | + Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
|
| 807 | + foreach ($app->getModules() as $module) |
|
| 808 | + if ($module instanceof TActiveRecordConfig) |
|
| 809 | + return $module; |
|
| 810 | + echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
|
| 811 | + } |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + protected function getOutputFile($app_dir, $namespace) { |
|
| 816 | + if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
| 817 | + return $namespace; |
|
| 818 | + $file = Prado::getPathOfNamespace($namespace, ""); |
|
| 819 | + if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
|
| 820 | + if (strpos($path, $app_dir) === 0) |
|
| 821 | + return $file; |
|
| 822 | + } |
|
| 823 | + echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | 827 | } |
| 828 | 828 | |
@@ -830,20 +830,20 @@ discard block |
||
| 830 | 830 | if(class_exists('PHP_Shell_Commands', false)) |
| 831 | 831 | { |
| 832 | 832 | class PHP_Shell_Extensions_ActiveRecord implements PHP_Shell_Extension { |
| 833 | - public function register() |
|
| 834 | - { |
|
| 833 | + public function register() |
|
| 834 | + { |
|
| 835 | 835 | |
| 836 | - $cmd = PHP_Shell_Commands::getInstance(); |
|
| 836 | + $cmd = PHP_Shell_Commands::getInstance(); |
|
| 837 | 837 | if(Prado::getApplication() !== null) |
| 838 | 838 | { |
| 839 | - $cmd->registerCommand('#^generate#', $this, 'generate', 'generate <table> <output> [soap]', |
|
| 840 | - 'Generate Active Record skeleton for <table> to <output> file using'.PHP_EOL. |
|
| 841 | - ' application.xml in [directory]. May also generate [soap] properties.'); |
|
| 839 | + $cmd->registerCommand('#^generate#', $this, 'generate', 'generate <table> <output> [soap]', |
|
| 840 | + 'Generate Active Record skeleton for <table> to <output> file using'.PHP_EOL. |
|
| 841 | + ' application.xml in [directory]. May also generate [soap] properties.'); |
|
| 842 | 842 | } |
| 843 | - } |
|
| 843 | + } |
|
| 844 | 844 | |
| 845 | - public function generate($l) |
|
| 846 | - { |
|
| 845 | + public function generate($l) |
|
| 846 | + { |
|
| 847 | 847 | $input = explode(" ", trim($l)); |
| 848 | 848 | if(count($input) > 2) |
| 849 | 849 | { |
@@ -860,12 +860,12 @@ discard block |
||
| 860 | 860 | { |
| 861 | 861 | echo "\n Usage: generate table_name Application.pages.RecordClassName\n"; |
| 862 | 862 | } |
| 863 | - } |
|
| 863 | + } |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | $__shell_exts = PHP_Shell_Extensions::getInstance(); |
| 867 | 867 | $__shell_exts->registerExtensions(array( |
| 868 | - "active-record" => new PHP_Shell_Extensions_ActiveRecord)); /* the :set command */ |
|
| 868 | + "active-record" => new PHP_Shell_Extensions_ActiveRecord)); /* the :set command */ |
|
| 869 | 869 | |
| 870 | 870 | include_once(realpath(dirname(dirname(__FILE__))).'/framework/3rdParty/PhpShell/php-shell-cmd.php'); |
| 871 | 871 | } |
@@ -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 | */ |
@@ -77,371 +77,371 @@ |
||
| 77 | 77 | * @since 1.2.0 |
| 78 | 78 | */ |
| 79 | 79 | class Benchmark_Profiler extends PEAR { |
| 80 | - /** |
|
| 81 | - * Contains the total ex. time of each section |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - * @access private |
|
| 85 | - */ |
|
| 86 | - var $_sections = array(); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Calling stack |
|
| 90 | - * |
|
| 91 | - * @var array |
|
| 92 | - * @access private |
|
| 93 | - */ |
|
| 94 | - var $_stack = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Notes how often a section was entered |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - * @access private |
|
| 101 | - */ |
|
| 102 | - var $_numberOfCalls = array(); |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Notes for each section how much time is spend in sub-sections |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - * @access private |
|
| 109 | - */ |
|
| 110 | - var $_subSectionsTime = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Notes for each section how often it calls which section |
|
| 114 | - * |
|
| 115 | - * @var array |
|
| 116 | - * @access private |
|
| 117 | - */ |
|
| 118 | - var $_calls = array(); |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Notes for each section how often it was called by which section |
|
| 122 | - * |
|
| 123 | - * @var array |
|
| 124 | - * @access private |
|
| 125 | - */ |
|
| 126 | - var $_callers = array(); |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Auto-starts and stops profiler |
|
| 130 | - * |
|
| 131 | - * @var boolean |
|
| 132 | - * @access private |
|
| 133 | - */ |
|
| 134 | - var $_auto = FALSE; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Max marker name length for non-html output |
|
| 138 | - * |
|
| 139 | - * @var integer |
|
| 140 | - * @access private |
|
| 141 | - */ |
|
| 142 | - var $_maxStringLength = 0; |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Constructor, starts profiling recording |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - */ |
|
| 149 | - function Benchmark_Profiler($auto = FALSE) { |
|
| 150 | - $this->_auto = $auto; |
|
| 151 | - |
|
| 152 | - if ($this->_auto) { |
|
| 153 | - $this->start(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $this->PEAR(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Destructor, stops profiling recording |
|
| 161 | - * |
|
| 162 | - * @access private |
|
| 163 | - */ |
|
| 164 | - function _Benchmark_Profiler() { |
|
| 165 | - if (isset($this->_auto) && $this->_auto) { |
|
| 166 | - $this->stop(); |
|
| 167 | - $this->display(); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Returns profiling informations for a given section. |
|
| 173 | - * |
|
| 174 | - * @param string $section |
|
| 175 | - * @return array |
|
| 176 | - * @access public |
|
| 177 | - */ |
|
| 178 | - function getSectionInformations($section = 'Global') { |
|
| 179 | - if (isset($this->_sections[$section])) { |
|
| 180 | - $calls = array(); |
|
| 181 | - |
|
| 182 | - if (isset($this->_calls[$section])) { |
|
| 183 | - $calls = $this->_calls[$section]; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $callers = array(); |
|
| 187 | - |
|
| 188 | - if (isset($this->_callers[$section])) { |
|
| 189 | - $callers = $this->_callers[$section]; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $informations = array(); |
|
| 193 | - |
|
| 194 | - $informations['time'] = $this->_sections[$section]; |
|
| 195 | - if (isset($this->_sections['Global'])) { |
|
| 196 | - $informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', ''); |
|
| 197 | - } else { |
|
| 198 | - $informations['percentage'] = 'N/A'; |
|
| 199 | - } |
|
| 200 | - $informations['calls'] = $calls; |
|
| 201 | - $informations['num_calls'] = $this->_numberOfCalls[$section]; |
|
| 202 | - $informations['callers'] = $callers; |
|
| 203 | - |
|
| 204 | - if (isset($this->_subSectionsTime[$section])) { |
|
| 205 | - $informations['netto_time'] = $this->_sections[$section] - $this->_subSectionsTime[$section]; |
|
| 206 | - } else { |
|
| 207 | - $informations['netto_time'] = $this->_sections[$section]; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $informations; |
|
| 211 | - } else { |
|
| 212 | - $this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Returns profiling informations for all sections. |
|
| 218 | - * |
|
| 219 | - * @return array |
|
| 220 | - * @access public |
|
| 221 | - */ |
|
| 222 | - function getAllSectionsInformations() { |
|
| 223 | - $informations = array(); |
|
| 224 | - |
|
| 225 | - foreach($this->_sections as $section => $time) { |
|
| 226 | - $informations[$section] = $this->getSectionInformations($section); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $informations; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Returns formatted profiling information. |
|
| 234 | - * |
|
| 235 | - * @param string output format (auto, plain or html), default auto |
|
| 236 | - * @see display() |
|
| 237 | - * @access private |
|
| 238 | - */ |
|
| 239 | - function _getOutput($format) { |
|
| 80 | + /** |
|
| 81 | + * Contains the total ex. time of each section |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + * @access private |
|
| 85 | + */ |
|
| 86 | + var $_sections = array(); |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Calling stack |
|
| 90 | + * |
|
| 91 | + * @var array |
|
| 92 | + * @access private |
|
| 93 | + */ |
|
| 94 | + var $_stack = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Notes how often a section was entered |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + * @access private |
|
| 101 | + */ |
|
| 102 | + var $_numberOfCalls = array(); |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Notes for each section how much time is spend in sub-sections |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + * @access private |
|
| 109 | + */ |
|
| 110 | + var $_subSectionsTime = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Notes for each section how often it calls which section |
|
| 114 | + * |
|
| 115 | + * @var array |
|
| 116 | + * @access private |
|
| 117 | + */ |
|
| 118 | + var $_calls = array(); |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Notes for each section how often it was called by which section |
|
| 122 | + * |
|
| 123 | + * @var array |
|
| 124 | + * @access private |
|
| 125 | + */ |
|
| 126 | + var $_callers = array(); |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Auto-starts and stops profiler |
|
| 130 | + * |
|
| 131 | + * @var boolean |
|
| 132 | + * @access private |
|
| 133 | + */ |
|
| 134 | + var $_auto = FALSE; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Max marker name length for non-html output |
|
| 138 | + * |
|
| 139 | + * @var integer |
|
| 140 | + * @access private |
|
| 141 | + */ |
|
| 142 | + var $_maxStringLength = 0; |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Constructor, starts profiling recording |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + */ |
|
| 149 | + function Benchmark_Profiler($auto = FALSE) { |
|
| 150 | + $this->_auto = $auto; |
|
| 151 | + |
|
| 152 | + if ($this->_auto) { |
|
| 153 | + $this->start(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $this->PEAR(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Destructor, stops profiling recording |
|
| 161 | + * |
|
| 162 | + * @access private |
|
| 163 | + */ |
|
| 164 | + function _Benchmark_Profiler() { |
|
| 165 | + if (isset($this->_auto) && $this->_auto) { |
|
| 166 | + $this->stop(); |
|
| 167 | + $this->display(); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Returns profiling informations for a given section. |
|
| 173 | + * |
|
| 174 | + * @param string $section |
|
| 175 | + * @return array |
|
| 176 | + * @access public |
|
| 177 | + */ |
|
| 178 | + function getSectionInformations($section = 'Global') { |
|
| 179 | + if (isset($this->_sections[$section])) { |
|
| 180 | + $calls = array(); |
|
| 181 | + |
|
| 182 | + if (isset($this->_calls[$section])) { |
|
| 183 | + $calls = $this->_calls[$section]; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $callers = array(); |
|
| 187 | + |
|
| 188 | + if (isset($this->_callers[$section])) { |
|
| 189 | + $callers = $this->_callers[$section]; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $informations = array(); |
|
| 193 | + |
|
| 194 | + $informations['time'] = $this->_sections[$section]; |
|
| 195 | + if (isset($this->_sections['Global'])) { |
|
| 196 | + $informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', ''); |
|
| 197 | + } else { |
|
| 198 | + $informations['percentage'] = 'N/A'; |
|
| 199 | + } |
|
| 200 | + $informations['calls'] = $calls; |
|
| 201 | + $informations['num_calls'] = $this->_numberOfCalls[$section]; |
|
| 202 | + $informations['callers'] = $callers; |
|
| 203 | + |
|
| 204 | + if (isset($this->_subSectionsTime[$section])) { |
|
| 205 | + $informations['netto_time'] = $this->_sections[$section] - $this->_subSectionsTime[$section]; |
|
| 206 | + } else { |
|
| 207 | + $informations['netto_time'] = $this->_sections[$section]; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $informations; |
|
| 211 | + } else { |
|
| 212 | + $this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Returns profiling informations for all sections. |
|
| 218 | + * |
|
| 219 | + * @return array |
|
| 220 | + * @access public |
|
| 221 | + */ |
|
| 222 | + function getAllSectionsInformations() { |
|
| 223 | + $informations = array(); |
|
| 224 | + |
|
| 225 | + foreach($this->_sections as $section => $time) { |
|
| 226 | + $informations[$section] = $this->getSectionInformations($section); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $informations; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Returns formatted profiling information. |
|
| 234 | + * |
|
| 235 | + * @param string output format (auto, plain or html), default auto |
|
| 236 | + * @see display() |
|
| 237 | + * @access private |
|
| 238 | + */ |
|
| 239 | + function _getOutput($format) { |
|
| 240 | 240 | |
| 241 | - /* Quickly find out the maximun length: Ineffecient, but will do for now! */ |
|
| 242 | - $informations = $this->getAllSectionsInformations(); |
|
| 243 | - $names = array_keys($informations); |
|
| 241 | + /* Quickly find out the maximun length: Ineffecient, but will do for now! */ |
|
| 242 | + $informations = $this->getAllSectionsInformations(); |
|
| 243 | + $names = array_keys($informations); |
|
| 244 | 244 | |
| 245 | - $maxLength = 0; |
|
| 246 | - foreach ($names as $name) |
|
| 247 | - { |
|
| 248 | - if ($maxLength < strlen($name)) { |
|
| 249 | - $maxLength = strlen($name); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - $this->_maxStringLength = $maxLength; |
|
| 253 | - |
|
| 254 | - if ($format == 'auto') { |
|
| 255 | - if (function_exists('version_compare') && |
|
| 256 | - version_compare(phpversion(), '4.1', 'ge')) { |
|
| 257 | - $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 258 | - } else { |
|
| 259 | - global $HTTP_SERVER_VARS; |
|
| 260 | - $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($format == 'html') { |
|
| 265 | - $out = '<table style="border: 1px solid #000000; ">'."\n"; |
|
| 266 | - $out .= |
|
| 267 | - '<tr><td> </td><td align="center"><b>total ex. time</b></td>'. |
|
| 268 | - '<td align="center"><b>netto ex. time</b></td>'. |
|
| 269 | - '<td align="center"><b>#calls</b></td><td align="center"><b>%</b></td>'. |
|
| 270 | - '<td align="center"><b>calls</b></td><td align="center"><b>callers</b></td></tr>'. |
|
| 271 | - "\n"; |
|
| 272 | - } else { |
|
| 273 | - $dashes = $out = str_pad("\n", ($this->_maxStringLength + 75), '-', STR_PAD_LEFT); |
|
| 274 | - $out .= str_pad('Section', $this->_maxStringLength + 10); |
|
| 275 | - $out .= str_pad("Total Ex Time", 22); |
|
| 276 | - $out .= str_pad("Netto Ex Time", 22); |
|
| 277 | - $out .= str_pad("#Calls", 10); |
|
| 278 | - $out .= "Percentage\n"; |
|
| 279 | - $out .= $dashes; |
|
| 280 | - } |
|
| 245 | + $maxLength = 0; |
|
| 246 | + foreach ($names as $name) |
|
| 247 | + { |
|
| 248 | + if ($maxLength < strlen($name)) { |
|
| 249 | + $maxLength = strlen($name); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + $this->_maxStringLength = $maxLength; |
|
| 253 | + |
|
| 254 | + if ($format == 'auto') { |
|
| 255 | + if (function_exists('version_compare') && |
|
| 256 | + version_compare(phpversion(), '4.1', 'ge')) { |
|
| 257 | + $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 258 | + } else { |
|
| 259 | + global $HTTP_SERVER_VARS; |
|
| 260 | + $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($format == 'html') { |
|
| 265 | + $out = '<table style="border: 1px solid #000000; ">'."\n"; |
|
| 266 | + $out .= |
|
| 267 | + '<tr><td> </td><td align="center"><b>total ex. time</b></td>'. |
|
| 268 | + '<td align="center"><b>netto ex. time</b></td>'. |
|
| 269 | + '<td align="center"><b>#calls</b></td><td align="center"><b>%</b></td>'. |
|
| 270 | + '<td align="center"><b>calls</b></td><td align="center"><b>callers</b></td></tr>'. |
|
| 271 | + "\n"; |
|
| 272 | + } else { |
|
| 273 | + $dashes = $out = str_pad("\n", ($this->_maxStringLength + 75), '-', STR_PAD_LEFT); |
|
| 274 | + $out .= str_pad('Section', $this->_maxStringLength + 10); |
|
| 275 | + $out .= str_pad("Total Ex Time", 22); |
|
| 276 | + $out .= str_pad("Netto Ex Time", 22); |
|
| 277 | + $out .= str_pad("#Calls", 10); |
|
| 278 | + $out .= "Percentage\n"; |
|
| 279 | + $out .= $dashes; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - foreach($informations as $name => $values) { |
|
| 283 | - $percentage = $values['percentage']; |
|
| 284 | - $calls_str = ""; |
|
| 285 | - |
|
| 286 | - foreach($values['calls'] as $key => $val) { |
|
| 287 | - if ($calls_str) { |
|
| 288 | - $calls_str .= ", "; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $calls_str .= "$key ($val)"; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $callers_str = ""; |
|
| 295 | - |
|
| 296 | - foreach($values['callers'] as $key => $val) { |
|
| 297 | - if ($callers_str) { |
|
| 298 | - $callers_str .= ", "; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $callers_str .= "$key ($val)"; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($format == 'html') { |
|
| 305 | - $out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>"; |
|
| 306 | - if (is_numeric($values['percentage'])) { |
|
| 307 | - $out .= "<td align=\"right\">{$values['percentage']}%</td>\n"; |
|
| 308 | - } else { |
|
| 309 | - $out .= "<td align=\"right\">{$values['percentage']}</td>\n"; |
|
| 310 | - } |
|
| 311 | - $out .= "<td>$calls_str</td><td>$callers_str</td></tr>"; |
|
| 312 | - } else { |
|
| 313 | - $out .= str_pad($name, $this->_maxStringLength + 10); |
|
| 314 | - $out .= str_pad($values['time'], 22); |
|
| 315 | - $out .= str_pad($values['netto_time'], 22); |
|
| 316 | - $out .= str_pad($values['num_calls'], 10); |
|
| 317 | - if (is_numeric($values['percentage'])) { |
|
| 318 | - $out .= str_pad($values['percentage']."%\n", 8, ' ', STR_PAD_LEFT); |
|
| 319 | - } else { |
|
| 320 | - $out .= str_pad($values['percentage']."\n", 8, ' ', STR_PAD_LEFT); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 282 | + foreach($informations as $name => $values) { |
|
| 283 | + $percentage = $values['percentage']; |
|
| 284 | + $calls_str = ""; |
|
| 285 | + |
|
| 286 | + foreach($values['calls'] as $key => $val) { |
|
| 287 | + if ($calls_str) { |
|
| 288 | + $calls_str .= ", "; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $calls_str .= "$key ($val)"; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $callers_str = ""; |
|
| 295 | + |
|
| 296 | + foreach($values['callers'] as $key => $val) { |
|
| 297 | + if ($callers_str) { |
|
| 298 | + $callers_str .= ", "; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $callers_str .= "$key ($val)"; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($format == 'html') { |
|
| 305 | + $out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>"; |
|
| 306 | + if (is_numeric($values['percentage'])) { |
|
| 307 | + $out .= "<td align=\"right\">{$values['percentage']}%</td>\n"; |
|
| 308 | + } else { |
|
| 309 | + $out .= "<td align=\"right\">{$values['percentage']}</td>\n"; |
|
| 310 | + } |
|
| 311 | + $out .= "<td>$calls_str</td><td>$callers_str</td></tr>"; |
|
| 312 | + } else { |
|
| 313 | + $out .= str_pad($name, $this->_maxStringLength + 10); |
|
| 314 | + $out .= str_pad($values['time'], 22); |
|
| 315 | + $out .= str_pad($values['netto_time'], 22); |
|
| 316 | + $out .= str_pad($values['num_calls'], 10); |
|
| 317 | + if (is_numeric($values['percentage'])) { |
|
| 318 | + $out .= str_pad($values['percentage']."%\n", 8, ' ', STR_PAD_LEFT); |
|
| 319 | + } else { |
|
| 320 | + $out .= str_pad($values['percentage']."\n", 8, ' ', STR_PAD_LEFT); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - if ($format == 'html') { |
|
| 326 | - return $out . '</table>'; |
|
| 327 | - } else { |
|
| 328 | - return $out; |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Returns formatted profiling information. |
|
| 334 | - * |
|
| 335 | - * @param string output format (auto, plain or html), default auto |
|
| 336 | - * @access public |
|
| 337 | - */ |
|
| 338 | - function display($format = 'auto') { |
|
| 339 | - echo $this->_getOutput($format); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Enters "Global" section. |
|
| 344 | - * |
|
| 345 | - * @see enterSection(), stop() |
|
| 346 | - * @access public |
|
| 347 | - */ |
|
| 348 | - function start() { |
|
| 349 | - $this->enterSection('Global'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Leaves "Global" section. |
|
| 354 | - * |
|
| 355 | - * @see leaveSection(), start() |
|
| 356 | - * @access public |
|
| 357 | - */ |
|
| 358 | - function stop() { |
|
| 359 | - $this->leaveSection('Global'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Enters code section. |
|
| 364 | - * |
|
| 365 | - * @param string name of the code section |
|
| 366 | - * @see start(), leaveSection() |
|
| 367 | - * @access public |
|
| 368 | - */ |
|
| 369 | - function enterSection($name) { |
|
| 370 | - if (count($this->_stack)) { |
|
| 371 | - if (isset($this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]])) { |
|
| 372 | - $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]]++; |
|
| 373 | - } else { |
|
| 374 | - $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) { |
|
| 378 | - $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++; |
|
| 379 | - } else { |
|
| 380 | - $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1; |
|
| 381 | - } |
|
| 382 | - } else { |
|
| 383 | - if ($name != 'Global') { |
|
| 384 | - $this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (isset($this->_numberOfCalls[$name])) { |
|
| 389 | - $this->_numberOfCalls[$name]++; |
|
| 390 | - } else { |
|
| 391 | - $this->_numberOfCalls[$name] = 1; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime())); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Leaves code section. |
|
| 399 | - * |
|
| 400 | - * @param string name of the marker to be set |
|
| 401 | - * @see stop(), enterSection() |
|
| 402 | - * @access public |
|
| 403 | - */ |
|
| 404 | - function leaveSection($name) { |
|
| 405 | - $microtime = $this->_getMicrotime(); |
|
| 406 | - |
|
| 407 | - if (!count($this->_stack)) { |
|
| 408 | - $this->raiseError("tried to leave section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $x = array_pop($this->_stack); |
|
| 412 | - |
|
| 413 | - if ($x["name"] != $name) { |
|
| 414 | - $this->raiseError("reached end of section $name but expecting end of " . $x["name"]."\n", NULL, PEAR_ERROR_DIE); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - if (isset($this->_sections[$name])) { |
|
| 418 | - $this->_sections[$name] += $microtime - $x["time"]; |
|
| 419 | - } else { |
|
| 420 | - $this->_sections[$name] = $microtime - $x["time"]; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $parent = array_pop($this->_stack); |
|
| 424 | - |
|
| 425 | - if (isset($parent)) { |
|
| 426 | - if (isset($this->_subSectionsTime[$parent['name']])) { |
|
| 427 | - $this->_subSectionsTime[$parent['name']] += $microtime - $x['time']; |
|
| 428 | - } else { |
|
| 429 | - $this->_subSectionsTime[$parent['name']] = $microtime - $x['time']; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - array_push($this->_stack, $parent); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Wrapper for microtime(). |
|
| 438 | - * |
|
| 439 | - * @return float |
|
| 440 | - * @access private |
|
| 441 | - * @since 1.3.0 |
|
| 442 | - */ |
|
| 443 | - function _getMicrotime() { |
|
| 444 | - $microtime = explode(' ', microtime()); |
|
| 445 | - return $microtime[1] . substr($microtime[0], 1); |
|
| 446 | - } |
|
| 325 | + if ($format == 'html') { |
|
| 326 | + return $out . '</table>'; |
|
| 327 | + } else { |
|
| 328 | + return $out; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Returns formatted profiling information. |
|
| 334 | + * |
|
| 335 | + * @param string output format (auto, plain or html), default auto |
|
| 336 | + * @access public |
|
| 337 | + */ |
|
| 338 | + function display($format = 'auto') { |
|
| 339 | + echo $this->_getOutput($format); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Enters "Global" section. |
|
| 344 | + * |
|
| 345 | + * @see enterSection(), stop() |
|
| 346 | + * @access public |
|
| 347 | + */ |
|
| 348 | + function start() { |
|
| 349 | + $this->enterSection('Global'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Leaves "Global" section. |
|
| 354 | + * |
|
| 355 | + * @see leaveSection(), start() |
|
| 356 | + * @access public |
|
| 357 | + */ |
|
| 358 | + function stop() { |
|
| 359 | + $this->leaveSection('Global'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Enters code section. |
|
| 364 | + * |
|
| 365 | + * @param string name of the code section |
|
| 366 | + * @see start(), leaveSection() |
|
| 367 | + * @access public |
|
| 368 | + */ |
|
| 369 | + function enterSection($name) { |
|
| 370 | + if (count($this->_stack)) { |
|
| 371 | + if (isset($this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]])) { |
|
| 372 | + $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]]++; |
|
| 373 | + } else { |
|
| 374 | + $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) { |
|
| 378 | + $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++; |
|
| 379 | + } else { |
|
| 380 | + $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1; |
|
| 381 | + } |
|
| 382 | + } else { |
|
| 383 | + if ($name != 'Global') { |
|
| 384 | + $this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (isset($this->_numberOfCalls[$name])) { |
|
| 389 | + $this->_numberOfCalls[$name]++; |
|
| 390 | + } else { |
|
| 391 | + $this->_numberOfCalls[$name] = 1; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime())); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Leaves code section. |
|
| 399 | + * |
|
| 400 | + * @param string name of the marker to be set |
|
| 401 | + * @see stop(), enterSection() |
|
| 402 | + * @access public |
|
| 403 | + */ |
|
| 404 | + function leaveSection($name) { |
|
| 405 | + $microtime = $this->_getMicrotime(); |
|
| 406 | + |
|
| 407 | + if (!count($this->_stack)) { |
|
| 408 | + $this->raiseError("tried to leave section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $x = array_pop($this->_stack); |
|
| 412 | + |
|
| 413 | + if ($x["name"] != $name) { |
|
| 414 | + $this->raiseError("reached end of section $name but expecting end of " . $x["name"]."\n", NULL, PEAR_ERROR_DIE); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + if (isset($this->_sections[$name])) { |
|
| 418 | + $this->_sections[$name] += $microtime - $x["time"]; |
|
| 419 | + } else { |
|
| 420 | + $this->_sections[$name] = $microtime - $x["time"]; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $parent = array_pop($this->_stack); |
|
| 424 | + |
|
| 425 | + if (isset($parent)) { |
|
| 426 | + if (isset($this->_subSectionsTime[$parent['name']])) { |
|
| 427 | + $this->_subSectionsTime[$parent['name']] += $microtime - $x['time']; |
|
| 428 | + } else { |
|
| 429 | + $this->_subSectionsTime[$parent['name']] = $microtime - $x['time']; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + array_push($this->_stack, $parent); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Wrapper for microtime(). |
|
| 438 | + * |
|
| 439 | + * @return float |
|
| 440 | + * @access private |
|
| 441 | + * @since 1.3.0 |
|
| 442 | + */ |
|
| 443 | + function _getMicrotime() { |
|
| 444 | + $microtime = explode(' ', microtime()); |
|
| 445 | + return $microtime[1] . substr($microtime[0], 1); |
|
| 446 | + } |
|
| 447 | 447 | } |
@@ -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 | */ |
@@ -58,262 +58,262 @@ |
||
| 58 | 58 | * @package Benchmark |
| 59 | 59 | */ |
| 60 | 60 | class Benchmark_Timer extends PEAR { |
| 61 | - /** |
|
| 62 | - * Contains the markers. |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - * @access private |
|
| 66 | - */ |
|
| 67 | - var $markers = array(); |
|
| 61 | + /** |
|
| 62 | + * Contains the markers. |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + * @access private |
|
| 66 | + */ |
|
| 67 | + var $markers = array(); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Auto-start and stop timer. |
|
| 71 | - * |
|
| 72 | - * @var boolean |
|
| 73 | - * @access private |
|
| 74 | - */ |
|
| 75 | - var $auto = FALSE; |
|
| 69 | + /** |
|
| 70 | + * Auto-start and stop timer. |
|
| 71 | + * |
|
| 72 | + * @var boolean |
|
| 73 | + * @access private |
|
| 74 | + */ |
|
| 75 | + var $auto = FALSE; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Max marker name length for non-html output. |
|
| 79 | - * |
|
| 80 | - * @var integer |
|
| 81 | - * @access private |
|
| 82 | - */ |
|
| 83 | - var $maxStringLength = 0; |
|
| 77 | + /** |
|
| 78 | + * Max marker name length for non-html output. |
|
| 79 | + * |
|
| 80 | + * @var integer |
|
| 81 | + * @access private |
|
| 82 | + */ |
|
| 83 | + var $maxStringLength = 0; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Constructor. |
|
| 87 | - * |
|
| 88 | - * @param boolean $auto |
|
| 89 | - * @access public |
|
| 90 | - */ |
|
| 91 | - function Benchmark_Timer($auto = FALSE) { |
|
| 92 | - $this->auto = $auto; |
|
| 85 | + /** |
|
| 86 | + * Constructor. |
|
| 87 | + * |
|
| 88 | + * @param boolean $auto |
|
| 89 | + * @access public |
|
| 90 | + */ |
|
| 91 | + function Benchmark_Timer($auto = FALSE) { |
|
| 92 | + $this->auto = $auto; |
|
| 93 | 93 | |
| 94 | - if ($this->auto) { |
|
| 95 | - $this->start(); |
|
| 96 | - } |
|
| 94 | + if ($this->auto) { |
|
| 95 | + $this->start(); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $this->PEAR(); |
|
| 99 | - } |
|
| 98 | + $this->PEAR(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Destructor. |
|
| 103 | - * |
|
| 104 | - * @access private |
|
| 105 | - */ |
|
| 106 | - function _Benchmark_Timer() { |
|
| 107 | - if ($this->auto) { |
|
| 108 | - $this->stop(); |
|
| 109 | - $this->display(); |
|
| 110 | - } |
|
| 111 | - } |
|
| 101 | + /** |
|
| 102 | + * Destructor. |
|
| 103 | + * |
|
| 104 | + * @access private |
|
| 105 | + */ |
|
| 106 | + function _Benchmark_Timer() { |
|
| 107 | + if ($this->auto) { |
|
| 108 | + $this->stop(); |
|
| 109 | + $this->display(); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Set "Start" marker. |
|
| 115 | - * |
|
| 116 | - * @see setMarker(), stop() |
|
| 117 | - * @access public |
|
| 118 | - */ |
|
| 119 | - function start() { |
|
| 120 | - $this->setMarker('Start'); |
|
| 121 | - } |
|
| 113 | + /** |
|
| 114 | + * Set "Start" marker. |
|
| 115 | + * |
|
| 116 | + * @see setMarker(), stop() |
|
| 117 | + * @access public |
|
| 118 | + */ |
|
| 119 | + function start() { |
|
| 120 | + $this->setMarker('Start'); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Set "Stop" marker. |
|
| 125 | - * |
|
| 126 | - * @see setMarker(), start() |
|
| 127 | - * @access public |
|
| 128 | - */ |
|
| 129 | - function stop() { |
|
| 130 | - $this->setMarker('Stop'); |
|
| 131 | - } |
|
| 123 | + /** |
|
| 124 | + * Set "Stop" marker. |
|
| 125 | + * |
|
| 126 | + * @see setMarker(), start() |
|
| 127 | + * @access public |
|
| 128 | + */ |
|
| 129 | + function stop() { |
|
| 130 | + $this->setMarker('Stop'); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Set marker. |
|
| 135 | - * |
|
| 136 | - * @param string $name Name of the marker to be set. |
|
| 137 | - * @see start(), stop() |
|
| 138 | - * @access public |
|
| 139 | - */ |
|
| 140 | - function setMarker($name) { |
|
| 141 | - $this->markers[$name] = $this->_getMicrotime(); |
|
| 142 | - } |
|
| 133 | + /** |
|
| 134 | + * Set marker. |
|
| 135 | + * |
|
| 136 | + * @param string $name Name of the marker to be set. |
|
| 137 | + * @see start(), stop() |
|
| 138 | + * @access public |
|
| 139 | + */ |
|
| 140 | + function setMarker($name) { |
|
| 141 | + $this->markers[$name] = $this->_getMicrotime(); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Returns the time elapsed betweens two markers. |
|
| 146 | - * |
|
| 147 | - * @param string $start start marker, defaults to "Start" |
|
| 148 | - * @param string $end end marker, defaults to "Stop" |
|
| 149 | - * @return double $time_elapsed time elapsed between $start and $end |
|
| 150 | - * @access public |
|
| 151 | - */ |
|
| 152 | - function timeElapsed($start = 'Start', $end = 'Stop') { |
|
| 153 | - if ($end == 'Stop' && !isset($this->markers['Stop'])) { |
|
| 154 | - $this->markers['Stop'] = $this->_getMicrotime(); |
|
| 155 | - } |
|
| 144 | + /** |
|
| 145 | + * Returns the time elapsed betweens two markers. |
|
| 146 | + * |
|
| 147 | + * @param string $start start marker, defaults to "Start" |
|
| 148 | + * @param string $end end marker, defaults to "Stop" |
|
| 149 | + * @return double $time_elapsed time elapsed between $start and $end |
|
| 150 | + * @access public |
|
| 151 | + */ |
|
| 152 | + function timeElapsed($start = 'Start', $end = 'Stop') { |
|
| 153 | + if ($end == 'Stop' && !isset($this->markers['Stop'])) { |
|
| 154 | + $this->markers['Stop'] = $this->_getMicrotime(); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - if (extension_loaded('bcmath')) { |
|
| 158 | - return bcsub($this->markers[$end], $this->markers[$start], 6); |
|
| 159 | - } else { |
|
| 160 | - return $this->markers[$end] - $this->markers[$start]; |
|
| 161 | - } |
|
| 162 | - } |
|
| 157 | + if (extension_loaded('bcmath')) { |
|
| 158 | + return bcsub($this->markers[$end], $this->markers[$start], 6); |
|
| 159 | + } else { |
|
| 160 | + return $this->markers[$end] - $this->markers[$start]; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Returns profiling information. |
|
| 166 | - * |
|
| 167 | - * $profiling[x]['name'] = name of marker x |
|
| 168 | - * $profiling[x]['time'] = time index of marker x |
|
| 169 | - * $profiling[x]['diff'] = execution time from marker x-1 to this marker x |
|
| 170 | - * $profiling[x]['total'] = total execution time up to marker x |
|
| 171 | - * |
|
| 172 | - * @return array |
|
| 173 | - * @access public |
|
| 174 | - */ |
|
| 175 | - function getProfiling() { |
|
| 176 | - $i = $total = 0; |
|
| 177 | - $result = array(); |
|
| 178 | - $temp = reset($this->markers); |
|
| 179 | - $this->maxStringLength = 0; |
|
| 164 | + /** |
|
| 165 | + * Returns profiling information. |
|
| 166 | + * |
|
| 167 | + * $profiling[x]['name'] = name of marker x |
|
| 168 | + * $profiling[x]['time'] = time index of marker x |
|
| 169 | + * $profiling[x]['diff'] = execution time from marker x-1 to this marker x |
|
| 170 | + * $profiling[x]['total'] = total execution time up to marker x |
|
| 171 | + * |
|
| 172 | + * @return array |
|
| 173 | + * @access public |
|
| 174 | + */ |
|
| 175 | + function getProfiling() { |
|
| 176 | + $i = $total = 0; |
|
| 177 | + $result = array(); |
|
| 178 | + $temp = reset($this->markers); |
|
| 179 | + $this->maxStringLength = 0; |
|
| 180 | 180 | |
| 181 | - foreach ($this->markers as $marker => $time) { |
|
| 182 | - if (extension_loaded('bcmath')) { |
|
| 183 | - $diff = bcsub($time, $temp, 6); |
|
| 184 | - $total = bcadd($total, $diff, 6); |
|
| 185 | - } else { |
|
| 186 | - $diff = $time - $temp; |
|
| 187 | - $total = $total + $diff; |
|
| 188 | - } |
|
| 181 | + foreach ($this->markers as $marker => $time) { |
|
| 182 | + if (extension_loaded('bcmath')) { |
|
| 183 | + $diff = bcsub($time, $temp, 6); |
|
| 184 | + $total = bcadd($total, $diff, 6); |
|
| 185 | + } else { |
|
| 186 | + $diff = $time - $temp; |
|
| 187 | + $total = $total + $diff; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - $result[$i]['name'] = $marker; |
|
| 191 | - $result[$i]['time'] = $time; |
|
| 192 | - $result[$i]['diff'] = $diff; |
|
| 193 | - $result[$i]['total'] = $total; |
|
| 190 | + $result[$i]['name'] = $marker; |
|
| 191 | + $result[$i]['time'] = $time; |
|
| 192 | + $result[$i]['diff'] = $diff; |
|
| 193 | + $result[$i]['total'] = $total; |
|
| 194 | 194 | |
| 195 | - $this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength); |
|
| 195 | + $this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength); |
|
| 196 | 196 | |
| 197 | - $temp = $time; |
|
| 198 | - $i++; |
|
| 199 | - } |
|
| 197 | + $temp = $time; |
|
| 198 | + $i++; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $result[0]['diff'] = '-'; |
|
| 202 | - $result[0]['total'] = '-'; |
|
| 203 | - $this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength); |
|
| 204 | - $this->maxStringLength += 2; |
|
| 201 | + $result[0]['diff'] = '-'; |
|
| 202 | + $result[0]['total'] = '-'; |
|
| 203 | + $this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength); |
|
| 204 | + $this->maxStringLength += 2; |
|
| 205 | 205 | |
| 206 | - return $result; |
|
| 207 | - } |
|
| 206 | + return $result; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Return formatted profiling information. |
|
| 211 | - * |
|
| 212 | - * @param boolean $showTotal Optionnaly includes total in output, default no |
|
| 213 | - * @param string $format output format (auto, plain or html), default auto |
|
| 214 | - * @return string |
|
| 215 | - * @see getProfiling() |
|
| 216 | - * @access public |
|
| 217 | - */ |
|
| 218 | - function getOutput($showTotal = FALSE, $format = 'auto') { |
|
| 219 | - if ($format == 'auto') { |
|
| 220 | - if (function_exists('version_compare') && |
|
| 221 | - version_compare(phpversion(), '4.1', 'ge')) |
|
| 222 | - { |
|
| 223 | - $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 224 | - } else { |
|
| 225 | - global $HTTP_SERVER_VARS; |
|
| 226 | - $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 227 | - } |
|
| 228 | - } |
|
| 209 | + /** |
|
| 210 | + * Return formatted profiling information. |
|
| 211 | + * |
|
| 212 | + * @param boolean $showTotal Optionnaly includes total in output, default no |
|
| 213 | + * @param string $format output format (auto, plain or html), default auto |
|
| 214 | + * @return string |
|
| 215 | + * @see getProfiling() |
|
| 216 | + * @access public |
|
| 217 | + */ |
|
| 218 | + function getOutput($showTotal = FALSE, $format = 'auto') { |
|
| 219 | + if ($format == 'auto') { |
|
| 220 | + if (function_exists('version_compare') && |
|
| 221 | + version_compare(phpversion(), '4.1', 'ge')) |
|
| 222 | + { |
|
| 223 | + $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 224 | + } else { |
|
| 225 | + global $HTTP_SERVER_VARS; |
|
| 226 | + $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain'; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - $total = $this->TimeElapsed(); |
|
| 231 | - $result = $this->getProfiling(); |
|
| 232 | - $dashes = ''; |
|
| 230 | + $total = $this->TimeElapsed(); |
|
| 231 | + $result = $this->getProfiling(); |
|
| 232 | + $dashes = ''; |
|
| 233 | 233 | |
| 234 | - if ($format == 'html') { |
|
| 235 | - $out = '<table border="1">'."\n"; |
|
| 236 | - $out .= '<tr><td> </td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'. |
|
| 237 | - ($showTotal ? |
|
| 238 | - '<td align="center"><b>elapsed</b></td><td align="center"><b>%</b></td>' |
|
| 239 | - : '')."</tr>\n"; |
|
| 240 | - } else { |
|
| 241 | - $dashes = $out = str_pad("\n", |
|
| 242 | - $this->maxStringLength + ($showTotal ? 70 : 45), '-', STR_PAD_LEFT); |
|
| 243 | - $out .= str_pad('marker', $this->maxStringLength) . |
|
| 244 | - str_pad("time index", 22) . |
|
| 245 | - str_pad("ex time", 16) . |
|
| 246 | - str_pad("perct ", 8) . |
|
| 247 | - ($showTotal ? ' '.str_pad("elapsed", 16)."perct" : '')."\n" . |
|
| 248 | - $dashes; |
|
| 249 | - } |
|
| 234 | + if ($format == 'html') { |
|
| 235 | + $out = '<table border="1">'."\n"; |
|
| 236 | + $out .= '<tr><td> </td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'. |
|
| 237 | + ($showTotal ? |
|
| 238 | + '<td align="center"><b>elapsed</b></td><td align="center"><b>%</b></td>' |
|
| 239 | + : '')."</tr>\n"; |
|
| 240 | + } else { |
|
| 241 | + $dashes = $out = str_pad("\n", |
|
| 242 | + $this->maxStringLength + ($showTotal ? 70 : 45), '-', STR_PAD_LEFT); |
|
| 243 | + $out .= str_pad('marker', $this->maxStringLength) . |
|
| 244 | + str_pad("time index", 22) . |
|
| 245 | + str_pad("ex time", 16) . |
|
| 246 | + str_pad("perct ", 8) . |
|
| 247 | + ($showTotal ? ' '.str_pad("elapsed", 16)."perct" : '')."\n" . |
|
| 248 | + $dashes; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - foreach ($result as $k => $v) { |
|
| 252 | - $perc = (($v['diff'] * 100) / $total); |
|
| 253 | - $tperc = (($v['total'] * 100) / $total); |
|
| 251 | + foreach ($result as $k => $v) { |
|
| 252 | + $perc = (($v['diff'] * 100) / $total); |
|
| 253 | + $tperc = (($v['total'] * 100) / $total); |
|
| 254 | 254 | |
| 255 | - if ($format == 'html') { |
|
| 256 | - $out .= "<tr><td><b>" . $v['name'] . |
|
| 257 | - "</b></td><td>" . $v['time'] . |
|
| 258 | - "</td><td>" . $v['diff'] . |
|
| 259 | - "</td><td align=\"right\">" . number_format($perc, 2, '.', '') . |
|
| 260 | - "%</td>". |
|
| 261 | - ($showTotal ? |
|
| 262 | - "<td>" . $v['total'] . |
|
| 263 | - "</td><td align=\"right\">" . |
|
| 264 | - number_format($tperc, 2, '.', '') . |
|
| 265 | - "%</td>" : ''). |
|
| 266 | - "</tr>\n"; |
|
| 267 | - } else { |
|
| 268 | - $out .= str_pad($v['name'], $this->maxStringLength, ' ') . |
|
| 269 | - str_pad($v['time'], 22) . |
|
| 270 | - str_pad($v['diff'], 14) . |
|
| 271 | - str_pad(number_format($perc, 2, '.', '')."%",8, ' ', STR_PAD_LEFT) . |
|
| 272 | - ($showTotal ? ' '. |
|
| 273 | - str_pad($v['total'], 14) . |
|
| 274 | - str_pad(number_format($tperc, 2, '.', '')."%", |
|
| 275 | - 8, ' ', STR_PAD_LEFT) : ''). |
|
| 276 | - "\n"; |
|
| 277 | - } |
|
| 255 | + if ($format == 'html') { |
|
| 256 | + $out .= "<tr><td><b>" . $v['name'] . |
|
| 257 | + "</b></td><td>" . $v['time'] . |
|
| 258 | + "</td><td>" . $v['diff'] . |
|
| 259 | + "</td><td align=\"right\">" . number_format($perc, 2, '.', '') . |
|
| 260 | + "%</td>". |
|
| 261 | + ($showTotal ? |
|
| 262 | + "<td>" . $v['total'] . |
|
| 263 | + "</td><td align=\"right\">" . |
|
| 264 | + number_format($tperc, 2, '.', '') . |
|
| 265 | + "%</td>" : ''). |
|
| 266 | + "</tr>\n"; |
|
| 267 | + } else { |
|
| 268 | + $out .= str_pad($v['name'], $this->maxStringLength, ' ') . |
|
| 269 | + str_pad($v['time'], 22) . |
|
| 270 | + str_pad($v['diff'], 14) . |
|
| 271 | + str_pad(number_format($perc, 2, '.', '')."%",8, ' ', STR_PAD_LEFT) . |
|
| 272 | + ($showTotal ? ' '. |
|
| 273 | + str_pad($v['total'], 14) . |
|
| 274 | + str_pad(number_format($tperc, 2, '.', '')."%", |
|
| 275 | + 8, ' ', STR_PAD_LEFT) : ''). |
|
| 276 | + "\n"; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - $out .= $dashes; |
|
| 280 | - } |
|
| 279 | + $out .= $dashes; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - if ($format == 'html') { |
|
| 283 | - $out .= "<tr style='background: silver;'><td><b>total</b></td><td>-</td><td>${total}</td><td>100.00%</td>".($showTotal ? "<td>-</td><td>-</td>" : "")."</tr>\n"; |
|
| 284 | - $out .= "</table>\n"; |
|
| 285 | - } else { |
|
| 286 | - $out .= str_pad('total', $this->maxStringLength); |
|
| 287 | - $out .= str_pad('-', 22); |
|
| 288 | - $out .= str_pad($total, 15); |
|
| 289 | - $out .= "100.00%\n"; |
|
| 290 | - $out .= $dashes; |
|
| 291 | - } |
|
| 282 | + if ($format == 'html') { |
|
| 283 | + $out .= "<tr style='background: silver;'><td><b>total</b></td><td>-</td><td>${total}</td><td>100.00%</td>".($showTotal ? "<td>-</td><td>-</td>" : "")."</tr>\n"; |
|
| 284 | + $out .= "</table>\n"; |
|
| 285 | + } else { |
|
| 286 | + $out .= str_pad('total', $this->maxStringLength); |
|
| 287 | + $out .= str_pad('-', 22); |
|
| 288 | + $out .= str_pad($total, 15); |
|
| 289 | + $out .= "100.00%\n"; |
|
| 290 | + $out .= $dashes; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return $out; |
|
| 294 | - } |
|
| 293 | + return $out; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Prints the information returned by getOutput(). |
|
| 298 | - * |
|
| 299 | - * @param boolean $showTotal Optionnaly includes total in output, default no |
|
| 300 | - * @param string $format output format (auto, plain or html), default auto |
|
| 301 | - * @see getOutput() |
|
| 302 | - * @access public |
|
| 303 | - */ |
|
| 304 | - function display($showTotal = FALSE, $format = 'auto') { |
|
| 305 | - print $this->getOutput($showTotal, $format); |
|
| 306 | - } |
|
| 296 | + /** |
|
| 297 | + * Prints the information returned by getOutput(). |
|
| 298 | + * |
|
| 299 | + * @param boolean $showTotal Optionnaly includes total in output, default no |
|
| 300 | + * @param string $format output format (auto, plain or html), default auto |
|
| 301 | + * @see getOutput() |
|
| 302 | + * @access public |
|
| 303 | + */ |
|
| 304 | + function display($showTotal = FALSE, $format = 'auto') { |
|
| 305 | + print $this->getOutput($showTotal, $format); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * Wrapper for microtime(). |
|
| 310 | - * |
|
| 311 | - * @return float |
|
| 312 | - * @access private |
|
| 313 | - * @since 1.3.0 |
|
| 314 | - */ |
|
| 315 | - function _getMicrotime() { |
|
| 316 | - $microtime = explode(' ', microtime()); |
|
| 317 | - return $microtime[1] . substr($microtime[0], 1); |
|
| 318 | - } |
|
| 308 | + /** |
|
| 309 | + * Wrapper for microtime(). |
|
| 310 | + * |
|
| 311 | + * @return float |
|
| 312 | + * @access private |
|
| 313 | + * @since 1.3.0 |
|
| 314 | + */ |
|
| 315 | + function _getMicrotime() { |
|
| 316 | + $microtime = explode(' ', microtime()); |
|
| 317 | + return $microtime[1] . substr($microtime[0], 1); |
|
| 318 | + } |
|
| 319 | 319 | } |
@@ -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) |
@@ -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'); |
@@ -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; |
@@ -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)); |
@@ -167,10 +167,10 @@ |
||
| 167 | 167 | |
| 168 | 168 | //DocLink |
| 169 | 169 | $html = preg_replace('/<com:DocLink\s+ClassPath="([^"]*)[.]([^."]*)"\s+Text="([^"]+)"\s*\/>/', |
| 170 | - '\href{http://pradosoft.github.io/docs/manual/$1/$2.html}{$3}', $html); |
|
| 170 | + '\href{http://pradosoft.github.io/docs/manual/$1/$2.html}{$3}', $html); |
|
| 171 | 171 | |
| 172 | 172 | $html = preg_replace('/<com:DocLink\s+ClassPath="([^"]*)[.]([^.]*)"\s+\/>/', |
| 173 | - '\href{http://pradosoft.github.io/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html); |
|
| 173 | + '\href{http://pradosoft.github.io/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html); |
|
| 174 | 174 | |
| 175 | 175 | //text modifiers |
| 176 | 176 | $html = preg_replace('/<(b|strong)[^>]*>([^<]*)<\/(b|strong)>/', '\textbf{$2}', $html); |
@@ -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 | { |