| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * $Id: phpcoverage.remote.top.inc.php 14666 2005-03-23 19:39:55Z npac $ 4 * 5 * Copyright(c) 2004-2005, SpikeSource Inc. All Rights Reserved. 6 * Licensed under the Open Source License version 2.1 7 * (See http://www.spikesource.com/license.html) 8 */ 9 ?> 10 <?php 11 if(isset($_REQUEST)){ 12 $debug = false; 13 // Uncomment the line below to permanently turn on debugging. 14 // Alternatively, export a variable called phpcoverage-debug before 15 // starting the web server. 16 $debug = true; 17 if(isset($_REQUEST["phpcoverage-debug"]) || 18 isset($_SERVER["phpcoverage-debug"]) || 19 isset($_ENV["phpcoverage-debug"])) { 20 $debug = true; 21 } 22 if($debug) error_log("[phpcoverage.remote.top.inc.php] ################## START ###################"); 23 24 $PHPCOVERAGE_HOME = false; 25 global $PHPCOVERAGE_HOME; 26 27 $basedir = dirname(__FILE__); 28 $this_script = basename(__FILE__); 29 $called_script = basename($_SERVER["SCRIPT_FILENAME"]); 30 31 if(!empty($_REQUEST["PHPCOVERAGE_HOME"])) { 32 $PHPCOVERAGE_HOME = $_REQUEST["PHPCOVERAGE_HOME"]; 33 } 34 if(empty($PHPCOVERAGE_HOME)) { 35 $env_var = getenv("PHPCOVERAGE_HOME"); 36 if(empty($env_var)) { 37 $share_home = getenv("LOCAL_CACHE"); 38 $PHPCOVERAGE_HOME = $share_home . "/common/spikephpcoverage/src/"; 39 } 40 else { 41 $PHPCOVERAGE_HOME = $env_var; 42 } 43 } 44 45 if(empty($PHPCOVERAGE_HOME) || !is_dir($PHPCOVERAGE_HOME)) { 46 $msg = "ERROR: Could not locate PHPCOVERAGE_HOME [$PHPCOVERAGE_HOME]. "; 47 $msg .= "Use 'php <filename> PHPCOVERAGE_HOME=/path/to/coverage/home'\n"; 48 die($msg); 49 } 50 51 52 // Fallback 53 if(!defined("PHPCOVERAGE_HOME")) { 54 $include_path = get_include_path(); 55 set_include_path($PHPCOVERAGE_HOME. ":" . $include_path); 56 define('PHPCOVERAGE_HOME', $PHPCOVERAGE_HOME); 57 } 58 59 if($debug) error_log("[phpcoverage.remote.top.inc.php] PHPCOVERAGE_HOME=" . $PHPCOVERAGE_HOME); 60 61 // Register the shutdown function to get code coverage results before 62 // script exits abnormally. 63 register_shutdown_function('spikephpcoverage_before_shutdown'); 64 require_once PHPCOVERAGE_HOME . "/conf/phpcoverage.conf.php"; 65 require_once PHPCOVERAGE_HOME . "/util/Utility.php"; 66 require_once PHPCOVERAGE_HOME . "/remote/RemoteCoverageRecorder.php"; 67 require_once PHPCOVERAGE_HOME . "/reporter/HtmlCoverageReporter.php"; 68 69 global $util; 70 $logger = $util->getLogger(); 71 72 // Create a distinct hash (may or may not be unique) 73 $session_id = md5($_SERVER["REMOTE_ADDR"] . $_SERVER["SERVER_NAME"]); 74 $tmpFile = $util->getTmpDir() . "/phpcoverage.session." . $session_id; 75 $logger->info("[phpcoverage.remote.top.inc.php] Session id: " . $session_id . " Saved in: " . $tmpFile, 76 __FILE__, __LINE__); 77 if(file_exists($tmpFile)) { 78 $object = file_get_contents($tmpFile); 79 $cov = unserialize($object); 80 $logger->info("[phpcoverage.remote.top.inc.php] Coverage object found: " . $cov, 81 __FILE__, __LINE__); 82 } 83 else { 84 $covReporter = new HtmlCoverageReporter( 85 "PHPCoverage report", 86 "", 87 $util->getTmpDir() . "/php-coverage-report" 88 ); 89 $cov = new RemoteCoverageRecorder(array(), array(), $covReporter); 90 $object = serialize($cov); 91 file_put_contents($tmpFile, $object); 92 $logger->info("[phpcoverage.remote.top.inc.php] Stored coverage object: " . $cov, 93 __FILE__, __LINE__); 94 } 95 96 if(!empty($_REQUEST["phpcoverage-action"])) { 97 $logger->info("[phpcoverage.remote.top.inc.php] phpcoverage-action=" . strtolower($_REQUEST["phpcoverage-action"]), 98 __FILE__, __LINE__); 99 switch(strtolower($_REQUEST["phpcoverage-action"])) { 100 case "init": 101 if(!empty($_REQUEST["tmp-dir"])) { 102 $cov->setTmpDir($_REQUEST["tmp-dir"]); 103 } 104 $cov->setCoverageFileName($_REQUEST["cov-file-name"]); 105 if(!$cov->cleanCoverageFile()) { 106 die("Cannot delete existing coverage data."); 107 } 108 break; 109 110 case "instrument": 111 break; 112 113 case "get-coverage-xml": 114 $cov->getCoverageXml(); 115 break; 116 117 case "cleanup": 118 if(file_exists($tmpFile) && is_writable($tmpFile)) { 119 unlink($tmpFile); 120 unset($cov); 121 $logger->info("[phpcoverage.remote.top.inc.php] Cleaned up!", 122 __FILE__, __LINE__); 123 return; 124 } 125 else { 126 $logger->error("[phpcoverage.remote.top.inc.php] Error deleting file: " . $tmpFile, 127 __FILE__, __LINE__); 128 } 129 break; 130 } 131 } 132 133 $cov->startInstrumentation(); 134 $logger->info("[phpcoverage.remote.top.inc.php] Instrumentation turned on.", 135 __FILE__, __LINE__); 136 $object = serialize($cov); 137 file_put_contents($tmpFile, $object); 138 $logger->info("[phpcoverage.remote.top.inc.php] BEGIN: " . $called_script, 139 __FILE__, __LINE__); 140 } 141 142 function spikephpcoverage_before_shutdown() { 143 global $cov, $logger; 144 $logger->debug("[phpcoverage.remote.top.inc.php::before_shutdown()] Getting code coverage before shutdown: START", 145 __FILE__, __LINE__); 146 require dirname(__FILE__) . "/phpcoverage.remote.bottom.inc.php"; 147 $logger->debug("[phpcoverage.remote.top.inc.php::before_shutdown()] Getting code coverage before shutdown: FINISH", 148 __FILE__, __LINE__); 149 } 150 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 7 05:02:03 2008 | Cross-referenced by PHPXref 0.7 |