-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvokerAware.php
48 lines (39 loc) · 976 Bytes
/
InvokerAware.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Qubus\Inheritance
*
* @link https://github.com/QubusPHP/inheritance
* @copyright 2022
* @author Joshua Parker <[email protected]>
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @since 2.0.1
*/
declare(strict_types=1);
namespace Qubus\Inheritance;
use Closure;
use function call_user_func_array;
use function ob_get_clean;
use function ob_start;
trait InvokerAware
{
/**
* Call the given Closure with buffering support.
*
* @param callable|Closure $closure
* @param array $parameters
* @param bool $buffer
* @return mixed
*/
public function call(callable|Closure $closure, array $parameters = [], bool $buffer = false): mixed
{
if ($buffer) {
ob_start();
}
$result = call_user_func_array($closure, $parameters);
if ($buffer) {
return ob_get_clean();
}
return $result;
}
}