1: <?php
2: /**
3: * COutputProcessor class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * COutputProcessor transforms the content into a different format.
13: *
14: * COutputProcessor captures the output generated by an action or a view fragment
15: * and passes it to its {@link onProcessOutput} event handlers for further processing.
16: *
17: * The event handler may process the output and store it back to the {@link COutputEvent::output}
18: * property. By setting the {@link CEvent::handled handled} property of the event parameter
19: * to true, the output will not be echoed anymore. Otherwise (by default), the output will be echoed.
20: *
21: * @author Qiang Xue <qiang.xue@gmail.com>
22: * @package system.web.widgets
23: * @since 1.0
24: */
25: class COutputProcessor extends CFilterWidget
26: {
27: /**
28: * Initializes the widget.
29: * This method starts the output buffering.
30: */
31: public function init()
32: {
33: ob_start();
34: ob_implicit_flush(false);
35: }
36:
37: /**
38: * Executes the widget.
39: * This method stops output buffering and processes the captured output.
40: */
41: public function run()
42: {
43: $output=ob_get_clean();
44: $this->processOutput($output);
45: }
46:
47: /**
48: * Processes the captured output.
49: *
50: * The default implementation raises an {@link onProcessOutput} event.
51: * If the event is not handled by any event handler, the output will be echoed.
52: *
53: * @param string $output the captured output to be processed
54: */
55: public function processOutput($output)
56: {
57: if($this->hasEventHandler('onProcessOutput'))
58: {
59: $event=new COutputEvent($this,$output);
60: $this->onProcessOutput($event);
61: if(!$event->handled)
62: echo $output;
63: }
64: else
65: echo $output;
66: }
67:
68: /**
69: * Raised when the output has been captured.
70: * @param COutputEvent $event event parameter
71: */
72: public function onProcessOutput($event)
73: {
74: $this->raiseEvent('onProcessOutput',$event);
75: }
76: }
77: