Download the PHP package genai/di without Composer
On this page you can find all versions of the php package genai/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package di
Short Description Popular DI attributes (#[Service], #[Repository], #[Configuration], #[Bean], #[Value]) and their processor, targeting GenAI\Container. Build-time (PHP 8).
License Apache-2.0
Informations about the package di
genai/di
Popular dependency-injection attributes and the processor that compiles them
into a genai/container definition file.
This is a build-time package (PHP 8): it's read by the genai/attribute
scanner during compilation. The container file it produces is PHP 5.3-safe,
like everything genai/container emits.
Attributes
| Attribute | Target | Effect |
|---|---|---|
#[Service] |
class | register the class as an autowired bean |
#[Repository] |
class | same — a stereotype for the persistence layer |
#[Configuration] |
class | register the class as a bean; its #[Bean] methods become factory beans |
#[Bean] |
method | a bean produced by calling the method on its (configuration) bean |
#[Value] |
parameter | inject a value into a constructor / factory parameter |
Service/Repository/Configuration all extend Component; one
ComponentProcessor handles them via ReflectionAttribute::IS_INSTANCEOF.
Usage
Point the scanner at your app plus this processor's namespace; it auto-registers
ComponentProcessor (by type) and dumps container.php:
#[Value] forms
${...} is resolved at compile time from the flat parameters map you pass to
Context (you populate it from your config source). A missing key fails the
build with a clear error.
#[Bean] id + the PHP 5.3 caveat
A #[Bean] method's id is, in order: the explicit #[Bean('id')] /
#[Bean(Type::class)], else the method's return type, else the method name.
A #[Bean] method is called at runtime (on the configuration bean). If your
runtime is PHP 5.3 it must not declare a : ReturnType (return types are
PHP 7+), so give the id explicitly:
On a PHP 7+/8 runtime you can use the return type and drop the explicit id.
Requires
php >=8.0, genai/attribute, genai/container (it bridges the two; the
runtime container it feeds stays PHP 5.3).