3 namespace Org\Mxchange\CoreFramework\Output\Debug;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Debug\Debugger;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
9 use Org\Mxchange\CoreFramework\Output\Debug\BaseDebugOutput;
10 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
13 * A debug output class for PHP's error_log() command
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStreamer {
36 * Protected constructor
40 private function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
46 * Creates an instance of this class
48 * @return $debugInstance The prepared debug instance
50 public static final function createDebugErrorLogOutput () {
52 $debugInstance = new DebugErrorLogOutput();
55 return $debugInstance;
59 * Outputs the given data without HTML tags, ignores $stripTags
61 * @param $output The HTML'ed output
62 * @param $stripTags Whether HTML tags shall be stripped out
65 public final function outputStream (string $output, bool $stripTags = false) {
66 // Split multiple lines into and array to put them out line-by-line
67 $errorLines = explode(chr(10), $output);
69 // "Walk" through all lines
70 foreach ($errorLines as $err) {
71 // Trim any spaces, \n, \r etc. out
74 // Log only none-empty lines
77 error_log(html_entity_decode(strip_tags($err)), 0);
85 * @param $outStream Stream to output
86 * @param $stripTags Whether HTML tags shall be stripped out
89 public final function output (string $outStream = '', bool $stripTags = false) {
90 // Empty output will be silently ignored
91 if (!empty($outStream)) {
92 $this->outputStream($outStream);
97 * Streams the data and maybe does something to it
99 * @param $data The data (string mostly) to "stream"
100 * @return $data The data (string mostly) to "stream"
101 * @throws UnsupportedOperationException If this method is called
103 public function streamData (string $data) {
104 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
105 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);