From 962fb661d298e7a39206f71643e0cd6128041641 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 10 Jun 2013 14:02:19 -0400
Subject: [PATCH] Use internal stdout and stderr objects for logging

Inside cli modules, use internal stdout and stderr objects rather than
writing directly to the PHP outputs. This will allow for significantly
easier regression testing integration.
---
 setup/cli/modules/class.module.php | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php
index 4ff5c7b1c..bfe32969b 100644
--- a/setup/cli/modules/class.module.php
+++ b/setup/cli/modules/class.module.php
@@ -80,6 +80,21 @@ class Option {
     }
 }
 
+class OutputStream {
+    var $stream;
+
+    function OutputStream() {
+        call_user_func_array(array($this, '__construct'), func_get_args());
+    }
+    function __construct($stream) {
+        $this->stream = fopen($stream, 'w');
+    }
+
+    function write($what) {
+        fwrite($this->stream, $what);
+    }
+}
+
 class Module {
 
     var $options = array();
@@ -89,6 +104,9 @@ class Module {
     var $usage = '$script [options] $args [arguments]';
     var $autohelp = true;
 
+    var $stdout;
+    var $stderr;
+
     var $_options;
     var $_args;
 
@@ -102,6 +120,8 @@ class Module {
             'help'=>"Display this help message");
         foreach ($this->options as &$opt)
             $opt = new Option($opt);
+        $this->stdout = new OutputStream('php://output');
+        $this->stderr = new OutputStream('php://stderr');
     }
 
     function showHelp() {
-- 
GitLab