Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/spikephpcoverage/src/phpcoverage.remote.top.inc.php
Go to the documentation of this file.
00001 <?php
00002     die(); // This (unsecure MDL-26237) stuff isn't used by moodle at all
00003 /*
00004  *  $Id: phpcoverage.remote.top.inc.php,v 1.3 2011/02/02 13:20:28 moodlerobot Exp $
00005  *  
00006  *  Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
00007  *  Licensed under the Open Software License version 2.1
00008  *  (See http://www.spikesource.com/license.html)
00009  */
00010 ?>
00011 <?php
00012     if(isset($_REQUEST)){
00013         $debug = false;
00014         // Uncomment the line below to permanently turn on debugging.
00015         // Alternatively, export a variable called phpcoverage-debug before
00016         // starting the web server.
00017         $debug = true;
00018         if(isset($_REQUEST["phpcoverage-debug"]) || 
00019         isset($_SERVER["phpcoverage-debug"]) || 
00020         isset($_ENV["phpcoverage-debug"])) {
00021             $debug = true;
00022         }
00023         if($debug) error_log("[phpcoverage.remote.top.inc.php] ################## START ###################");
00024 
00025         $PHPCOVERAGE_HOME = false;
00026         global $PHPCOVERAGE_HOME;
00027 
00028         $basedir = dirname(__FILE__);
00029         $this_script = basename(__FILE__);
00030         $called_script = basename($_SERVER["SCRIPT_FILENAME"]);
00031 
00032         if(!empty($_REQUEST["PHPCOVERAGE_HOME"])) {
00033             $PHPCOVERAGE_HOME = $_REQUEST["PHPCOVERAGE_HOME"];
00034         }
00035         if(empty($PHPCOVERAGE_HOME)) {
00036             $env_var = getenv("PHPCOVERAGE_HOME");
00037             if(empty($env_var)) {
00038                 $msg = "Could not find PHPCOVERAGE_HOME. Please either export it in your environment before starting the web server. Or include PHPCOVERAGE_HOME=<path> in your HTTP request.";
00039                 error_log("[phpcoverage.remote.top.inc.php] FATAL: " . $msg);
00040                 die($msg);
00041             }
00042             else {
00043                 $PHPCOVERAGE_HOME = $env_var;
00044             }
00045         }
00046 
00047         if(empty($PHPCOVERAGE_HOME) || !is_dir($PHPCOVERAGE_HOME)) {
00048             $msg = "ERROR: Could not locate PHPCOVERAGE_HOME [$PHPCOVERAGE_HOME]. ";
00049             $msg .= "Use 'php <filename> PHPCOVERAGE_HOME=/path/to/coverage/home'\n";
00050             die($msg);
00051         }
00052 
00053 
00054         // Fallback
00055         if(!defined("PHPCOVERAGE_HOME")) {
00056             $include_path = get_include_path();
00057             set_include_path($PHPCOVERAGE_HOME. ":" . $include_path);
00058             define('PHPCOVERAGE_HOME', $PHPCOVERAGE_HOME);
00059         }
00060 
00061         if($debug) error_log("[phpcoverage.remote.top.inc.php] PHPCOVERAGE_HOME=" . $PHPCOVERAGE_HOME);
00062 
00063         // Register the shutdown function to get code coverage results before
00064         // script exits abnormally.
00065         register_shutdown_function('spikephpcoverage_before_shutdown');
00066         require_once PHPCOVERAGE_HOME . "/conf/phpcoverage.conf.php";
00067         require_once PHPCOVERAGE_HOME . "/util/Utility.php";
00068         require_once PHPCOVERAGE_HOME . "/remote/RemoteCoverageRecorder.php";
00069         require_once PHPCOVERAGE_HOME . "/reporter/HtmlCoverageReporter.php";
00070 
00071         global $util;
00072         $logger = $util->getLogger();
00073 
00074         // Create a distinct hash (may or may not be unique)
00075         $session_id = md5($_SERVER["REMOTE_ADDR"] . $_SERVER["SERVER_NAME"]);
00076         $tmpFile = $util->getTmpDir() . "/phpcoverage.session." . $session_id;
00077         $logger->info("[phpcoverage.remote.top.inc.php] Session id: " . $session_id . " Saved in: " . $tmpFile,
00078             __FILE__, __LINE__);
00079         if(file_exists($tmpFile)) {
00080             $object = file_get_contents($tmpFile);
00081             $cov = unserialize($object);
00082             $logger->info("[phpcoverage.remote.top.inc.php] Coverage object found." ,
00083                 __FILE__, __LINE__);
00084         }
00085         else {
00086             $covReporter = new HtmlCoverageReporter(
00087                 "PHPCoverage report",
00088                 "",
00089                 $util->getTmpDir() . "/php-coverage-report"
00090             );
00091             $cov = new RemoteCoverageRecorder(array(), array(), $covReporter);
00092             $object = serialize($cov);
00093             file_put_contents($tmpFile, $object);
00094             $logger->info("[phpcoverage.remote.top.inc.php] Stored coverage object found",
00095                 __FILE__, __LINE__);
00096         }
00097 
00098         if(!empty($_REQUEST["phpcoverage-action"])) {
00099             $logger->info("[phpcoverage.remote.top.inc.php] phpcoverage-action=" . strtolower($_REQUEST["phpcoverage-action"]),
00100                 __FILE__, __LINE__);
00101             switch(strtolower($_REQUEST["phpcoverage-action"])) {
00102             case "init":
00103                 if(!empty($_REQUEST["tmp-dir"])) {
00104                     $cov->setTmpDir($_REQUEST["tmp-dir"]);
00105                 }
00106                 $cov->setCoverageFileName($_REQUEST["cov-file-name"]);
00107                 if(!$cov->cleanCoverageFile()) {
00108                     die("Cannot delete existing coverage data.");
00109                 }
00110                 break;
00111 
00112             case "instrument":
00113                 break;
00114 
00115             case "get-coverage-xml":
00116                 $cov->getCoverageXml();
00117                 break;
00118 
00119             case "cleanup":
00120                 if(file_exists($tmpFile) && is_writable($tmpFile)) {
00121                     unlink($tmpFile);
00122                     unset($cov);
00123                     $logger->info("[phpcoverage.remote.top.inc.php] Cleaned up!",
00124                         __FILE__, __LINE__);
00125                     return;
00126                 }
00127                 else {
00128                     $logger->error("[phpcoverage.remote.top.inc.php] Error deleting file: " . $tmpFile,
00129                         __FILE__, __LINE__);
00130                 }
00131                 break;
00132             }
00133         }
00134 
00135         $cov->startInstrumentation();
00136         $logger->info("[phpcoverage.remote.top.inc.php] Instrumentation turned on.",
00137             __FILE__, __LINE__);
00138         $object = serialize($cov);
00139         file_put_contents($tmpFile, $object);
00140         $logger->info("[phpcoverage.remote.top.inc.php] BEGIN: " . $called_script,
00141             __FILE__, __LINE__);
00142     }
00143 
00144     function spikephpcoverage_before_shutdown() {
00145         global $cov, $logger;
00146         $logger->debug("[phpcoverage.remote.top.inc.php::before_shutdown()] Getting code coverage before shutdown: START",
00147             __FILE__, __LINE__);
00148         require dirname(__FILE__) . "/phpcoverage.remote.bottom.inc.php";
00149         $logger->debug("[phpcoverage.remote.top.inc.php::before_shutdown()] Getting code coverage before shutdown: FINISH",
00150             __FILE__, __LINE__);
00151     }
00152 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations