MDL-37286 add new combined_progress_trace

This type of trace should be useful when multiple trace outputs requested.
This commit is contained in:
Petr Škoda
2013-01-12 15:16:39 +01:00
parent 78048e15f2
commit e7259ec998
2 changed files with 60 additions and 1 deletions
+20
View File
@@ -297,4 +297,24 @@ class web_testcase extends advanced_testcase {
$trace->reset_buffer();
$this->assertSame('', $trace->get_buffer());
}
public function test_combined_progres_trace() {
$this->resetAfterTest(false);
$trace1 = new progress_trace_buffer(new html_progress_trace(), false);
$trace2 = new progress_trace_buffer(new text_progress_trace(), false);
$trace = new combined_progress_trace(array($trace1, $trace2));
ob_start();
$trace->output('do');
$trace->output('re', 1);
$trace->output('mi', 2);
$trace->finished();
$output = ob_get_contents();
ob_end_clean();
$this->assertSame('', $output);
$this->assertSame("<p>do</p>\n<p>&#160;&#160;re</p>\n<p>&#160;&#160;&#160;&#160;mi</p>\n", $trace1->get_buffer());
$this->assertSame("do\n re\n mi\n", $trace2->get_buffer());
}
}
+40 -1
View File
@@ -3297,7 +3297,7 @@ class error_log_progress_trace extends progress_trace {
}
/**
* Special type of traced that can be used for catching of
* Special type of trace that can be used for catching of
* output of other traces.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -3371,6 +3371,45 @@ class progress_trace_buffer extends progress_trace {
}
}
/**
* Special type of trace that can be used for redirecting to multiple
* other traces.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
*/
class combined_progress_trace extends progress_trace {
protected $traces;
/**
* @param array $traces multiple traces
*/
public function __construct(array $traces) {
$this->traces = $traces;
}
/**
* Output an progress message in whatever format.
*
* @param string $message the message to output.
* @param integer $depth indent depth for this message.
*/
public function output($message, $depth = 0) {
foreach($this->traces as $trace) {
$trace->output($message, $depth);
}
}
/**
* Called when the processing is finished.
*/
public function finished() {
foreach($this->traces as $trace) {
$trace->finished();
}
}
}
/**
* Returns a localized sentence in the current language summarizing the current password policy
*