Invocation & Shortcuts#
The InvocationManager (which utilizes the ManagerProxy trait) provides a mini-helper API that goes beyond PSR-11
get() / has().
These helpers call things immediately so you can treat functions,
closures or whole classes as actions. The manager supports both fluent method chaining and array access.
As with other managers, ManagerProxy also enables direct container access through this manager ($inv->get(), $inv('id'), $inv['id']).
1 · call( callable|string $target , ?string $method )#
// (a) function with explicit args via registration metadata
$c->registration()->registerClosure('strlen.call', 'strlen', ['InterMix']);
$len = $c->call('strlen.call'); // → 8
// (b) invokable object or closure ------------------
$iso = $c->call(fn (DateTimeImmutable $now) => $now->format('c'));
// (c) class & method (autowired) -------------------
$c->call(JobProcessor::class, 'handle');
// Shortcut invocation manager helpers (via ManagerProxy)
$invoker = $c->invocation();
$job = $invoker(JobProcessor::class); // __invoke() -> get()
Rules
All parameters (including constructor params) are auto-resolved unless you provide explicit values through registration metadata.
$methodis optional; omit it for classes with an__invokeor the defaultMethod you set in Options & Feature Toggles.
2 · getReturn( string $id )#
Sometimes you register a method rather than rely on __invoke or a
default.
getReturn() hides the instance and returns only the method’s output:
$c->registration()
->registerClass(Mailer::class)
->registerMethod(Mailer::class, 'healthCheck');
$ok = $c->getReturn(Mailer::class); // ← returns bool, not Mailer
Internally the container:
Builds (or fetches) the Mailer singleton.
Executes healthCheck() with injected parameters.
Returns the result to you.
For singleton resolution paths, method execution happens when the entry is first resolved.
Later get() / getReturn() calls reuse cached singleton state (including the last returned value).
If you need a fresh method result on every call, use call() or make().
3 · make( string $class , string|bool $method = false )#
Always returns a brand-new instance (or the method’s output) and thus
skips the singleton cache used by get(). Perfect for factories or
stateless workers.
// just the object
$pdf = $c->make(PdfBuilder::class);
// build -> call render() (no explicit arg array in make())
$html = $c->make(PdfBuilder::class, 'render');
If render() needs explicit scalar arguments, register method metadata first via Registration Manager.
4 · When to use what?#
get() – retrieve a singleton service (most common).
call() – execute any callable with DI-resolved args.
getReturn() – “fire & forget” a registered method.
make() – obtain a fresh instance each time.
Tip: These helpers respect the same options (autowiring, attributes, environment overrides) you configured on the container—so your wiring rules apply everywhere.
Reference Table#
See also: Options & Feature Toggles (defaultMethod), Registration Manager
(for pre-registered class metadata).