By larowlan on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.2.x
Introduced in version:
10.2.0
Issue links:
Description:
A new CallableResolver service has been added to help standardize the developer experience and error handling for callbacks across various subsystems
The following code can be used to invoke a callable.
$result = \Drupal::service('callable_resolver')->getCallableFromDefinition($definition)();
Where $definition can be any of
| Type | Example definition |
|---|---|
| Inline function | function ($foo) { return $bar; } |
| First-class callable function | $this->method(...) |
| First-class callable static | static::staticMethod(...) |
| Arrow function | fn($foo) => $bar |
| Static method | 'MyClass::staticMethod' |
| Static method, array notation | [MyClass::class, 'staticMethod'] |
| Object method, array notation | [$this, 'method'] |
| Object method, instantiated by ClassResolver | MyClass::class . '::myMethod' |
Object method, instantiated by ClassResolver, container aware using ContainerInjectionInterface |
MyClassWithInjection::class . '::myMethod' |
| Service notation | 'my_service:method' |
Class with __invoke() method |
MyClass::class |
Impacts:
Module developers