super-kernel / support
Dependency-free namespaced helpers for caller-owned short-lived SuperKernel instances.
Requires
- php: >=8.4.27 <8.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95.27
- phpunit/phpunit: ^13.4.5
- super-kernel/context: 1.0.0-alpha.2
- super-kernel/contract: 1.0.0-alpha.2
- super-kernel/di: 1.0.0-alpha.2
Suggests
- super-kernel/context: Provides the current application container for container-assisted construction.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 02:25:20 UTC
README
English | 中文文档
SuperKernel Support
super-kernel/support provides the make() function, which creates a new object that the caller owns and fills its constructor's dependencies from the application container.
Installation
composer require super-kernel/support
The package has no requirement beyond PHP. To fill dependencies from a container, install super-kernel/context, which supplies the application's container; without it, make() constructs with the given arguments only.
What it provides
make($class, $parameters), which returns a new instance on every call.- Constructor arguments by name or position, with the rest filled from the container by type, then from defaults and
null. - The same argument rules as
super-kernel/di, with any PSR-11 container thatsuper-kernel/contextholds. - Clear errors for a parameter that cannot be filled, an ambiguous type, and a by-reference parameter.
It does not:
- keep the created object in the container or return a container entry;
- apply
#[Provider]or#[FactoryProvider]mappings, property injection, or lifecycle hooks to the created object; - create a scope or a new copy of the dependencies: dependencies from the container stay shared.
Quick start
A service the container provides. Save it as src/Report/Formatter.php:
<?php declare(strict_types=1); namespace Src\Report; use function strtoupper; final class Formatter { public function format(string $format, string $title): string { return strtoupper($format) . ': ' . $title; } }
An object the caller owns, with a dependency and a setting. Save it as src/Report/Report.php:
<?php declare(strict_types=1); namespace Src\Report; final readonly class Report { public function __construct(public Formatter $formatter, public string $format = 'text') { } public function render(string $title): string { return $this->formatter->format($this->format, $title); } }
In an application created from super-kernel/skeleton, create two reports. Save the script as bin/report.php:
<?php declare(strict_types=1); use Src\Report\Report; use function SuperKernel\Support\make; require dirname(__DIR__) . '/vendor/autoload.php'; $json = make(Report::class, ['format' => 'json']); $text = make(Report::class); echo $json->render('Sales'), PHP_EOL; echo $text->render('Sales'), PHP_EOL; var_dump($json === $text, $json->formatter === $text->formatter);
Build the project and run the script:
skernel build php bin/report.php
It prints:
JSON: Sales
TEXT: Sales
bool(false)
bool(true)
Public surface
| Name | Kind | Purpose |
|---|---|---|
SuperKernel\Support\make |
Helper | Creates a new instance of a class, filling its constructor from the given parameters and the application container. |
Behavior to know
make()raisesInvalidArgumentExceptionwhen a parameter cannot be filled, such asUnable to resolve constructor parameter Src\Storage\Job::__construct($store) of type Src\Storage\Store., when more than one class or interface in a parameter's type has a container entry, and for a by-reference parameter.- A dependency is found only under the fully qualified name of a class or interface in the parameter's type. A container entry registered under another name, such as
mailer, is not used. - Exceptions of the container, of
super-kernel/context, and of the constructor pass through unchanged. - With
super-kernel/contextinstalled but no container set,make()lets the context create the default container from the build metadata, which needssuper-kernel/diandskernel build; set your own container first to use another one.
Documentation
The developer documentation describes the argument rules, other containers, use without SuperKernel, and the errors with complete examples: SuperKernel Support.
License
Released under the MIT License. See LICENSE.