mirror of
https://github.com/flarum/core.git
synced 2025-08-09 09:57:06 +02:00
Broader support for callables in ContainerUtil (#2596)
It can be very annoying if we want to use something like boolval, but have to define an entire anonymous function to pass it in. This PR adds support for tpassing it in directly as a string, like is posible with User::registerPreference.
This commit is contained in:
committed by
GitHub
parent
a1254bc21a
commit
e7aed89e8f
@@ -18,12 +18,12 @@ class ContainerUtil
|
||||
*
|
||||
* @internal Backwards compatability not guaranteed.
|
||||
*
|
||||
* @param callable|string $callback: A callable, or a ::class attribute of an invokable class
|
||||
* @param callable|string $callback: A callable, global function, or a ::class attribute of an invokable class
|
||||
* @param Container $container
|
||||
*/
|
||||
public static function wrapCallback($callback, Container $container)
|
||||
{
|
||||
if (is_string($callback)) {
|
||||
if (is_string($callback) && ! is_callable($callback)) {
|
||||
$callback = function (&...$args) use ($container, $callback) {
|
||||
$callback = $container->make($callback);
|
||||
|
||||
|
Reference in New Issue
Block a user