-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
ContainerUtil.php
37 lines (31 loc) · 1.03 KB
/
ContainerUtil.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
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation;
use Illuminate\Contracts\Container\Container;
class ContainerUtil
{
/**
* Wraps a callback so that string-based invokable classes get resolved only when actually used.
*
* @param callable|class-string $callback : A callable, global function, or a ::class attribute of an invokable class
* @param Container $container
*
* @return callable
* @internal Backwards compatability not guaranteed.
*/
public static function wrapCallback(callable|string $callback, Container $container): callable
{
if (is_string($callback) && ! is_callable($callback)) {
$callback = function (&...$args) use ($container, $callback) {
$callback = $container->make($callback);
return $callback(...$args);
};
}
return $callback;
}
}