From 000c6529d8044691332a5916d94d2db1fb203d6e Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 18 Nov 2014 11:12:07 -0800 Subject: [PATCH] Profiler: Explicitly convert output type to class name Follows-up b8d93fb4fd06. Change-Id: I50faa25fdc4fb980e0ff71014b8d1b2a5818af80 --- includes/profiler/Profiler.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 12e999b8da..d23c77771b 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -39,6 +39,15 @@ abstract class Profiler { /** @var TransactionProfiler */ protected $trxProfiler; + /** + * @var array Mapping of output type to class name + */ + private static $outputTypes = array( + 'db' => 'ProfilerOutputDb', + 'text' => 'ProfilerOutputText', + 'udp' => 'ProfilerOutputUdp', + ); + // @codingStandardsIgnoreStart PSR2.Classes.PropertyDeclaration.Underscore /** @var Profiler Do not call this outside Profiler and ProfileSection */ public static $__instance = null; @@ -131,6 +140,7 @@ abstract class Profiler { /** * Log the data to some store or even the page output * + * @throws MWException * @since 1.25 */ public function logData() { @@ -147,7 +157,12 @@ abstract class Profiler { } foreach ( $output as $outType ) { - $class = 'ProfilerOutput' . ucfirst( strtolower( $outType ) ); + if ( isset( self::$outputTypes[$outType] ) ) { + $class = self::$outputTypes[$outType]; + } else { + throw new MWException( "'$outType' is an invalid output type" ); + } + /** @var ProfilerOutput $profileOut */ $profileOut = new $class( $this, $this->params ); if ( $profileOut->canUse() ) { $profileOut->log(); -- 2.20.1