2018-08-17 19:41:46 +00:00
|
|
|
<?php
|
2024-08-24 12:31:41 +00:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-08-17 19:41:46 +00:00
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
|
|
|
use php_user_filter;
|
|
|
|
|
|
|
|
/**
|
2023-03-22 04:07:55 +00:00
|
|
|
* Output Interceptor for STDOUT to prevent outputting to the console
|
2018-08-17 19:41:46 +00:00
|
|
|
* Instead the $cache variable will get filled with the output
|
|
|
|
*
|
|
|
|
* @package Friendica\Test\Util
|
|
|
|
*/
|
|
|
|
class Intercept extends php_user_filter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string The cache which holds the current output of STDOUT
|
|
|
|
*/
|
|
|
|
public static $cache = '';
|
|
|
|
|
2020-10-18 18:31:57 +00:00
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection */
|
2023-07-05 20:20:52 +00:00
|
|
|
public function filter($in, $out, &$consumed, $closing): int
|
2018-08-17 19:41:46 +00:00
|
|
|
{
|
|
|
|
while ($bucket = stream_bucket_make_writeable($in)) {
|
|
|
|
self::$cache .= $bucket->data;
|
|
|
|
$consumed += $bucket->datalen;
|
|
|
|
stream_bucket_append($out, $bucket);
|
|
|
|
}
|
|
|
|
return PSFS_FEED_ME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the interceptor and prevents therefore the output to STDOUT
|
|
|
|
*/
|
|
|
|
public static function setUp() {
|
|
|
|
stream_filter_register("intercept", Intercept::class);
|
|
|
|
stream_filter_append(STDOUT, "intercept");
|
|
|
|
stream_filter_append(STDERR, "intercept");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the cache
|
|
|
|
*/
|
|
|
|
public static function reset() {
|
|
|
|
self::$cache = '';
|
|
|
|
}
|
|
|
|
}
|