wiki.techinc.nl/includes/profiler/output/ProfilerOutput.php
Timo Tijhof 8a87ec2778 profiler: Centralise output responsibility from ProfilerOutputText to Profiler
Make it Profiler.php's responsibility to enforce this, based on the
existing signal from ProfilerOutput::logsToOutput().

The ProfilerOutputText class should not have to double-check this
a second time.

Long-term, I'd like even this check in Profiler::logDataPageOutputOnly
to be removed, because really the external caller of that should
know whether it is safe to output stuff or not rather than stashing
its own state inside Profiler::$allowOutput and then implicitly
reading it back out again later on. But, that's for another time.

Also:
* Remove use of deprecated Profiler::setTemplated while at it.
* Make 'visible' parameter explicit, as for other parameters.

Change-Id: Iaa3fc4ea25a059b90235d769db60c04b8f152f05
2019-08-28 16:07:18 +00:00

68 lines
1.8 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Profiler
*/
/**
* Base class for profiling output
*
* Since 1.25
*/
abstract class ProfilerOutput {
/** @var Profiler */
protected $collector;
/** @var array Configuration of $wgProfiler */
protected $params = [];
/**
* @param Profiler $collector The actual profiler
* @param array $params Configuration array, passed down from $wgProfiler
*/
public function __construct( Profiler $collector, array $params ) {
$this->collector = $collector;
$this->params = $params;
}
/**
* Can this output type be used?
* @return bool
*/
public function canUse() {
return true;
}
/**
* May the log() try to write to standard output?
* @return bool
* @since 1.33
*/
public function logsToOutput() {
return false;
}
/**
* Log MediaWiki-style profiling data.
*
* For classes that enable logsToOutput(), this must not
* be called unless Profiler::setAllowOutput is enabled.
*
* @param array $stats Result of Profiler::getFunctionStats()
*/
abstract public function log( array $stats );
}