Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Definitions

Definitions Laravel Package

yiisoft/definitions

Minimalistic definitions container for PHP apps. Build and compose object definitions for DI: map IDs to classes, factories, values and params, with autowiring-friendly configuration. Designed to work smoothly with Yii and other PSR-based projects.

View on GitHub
Deep Wiki
Context7

The package provides definition syntax

Frequently asked questions about Definitions
Can I use yiisoft/definitions with Laravel’s built-in service container?
Yes, but you’ll need to manually integrate it. The package doesn’t replace Laravel’s container but works alongside it. Load definitions via a service provider or boot method, then resolve them using Laravel’s container. For example, bind a definition to a class in `register()` and resolve it in `boot()`.
What Laravel versions support yiisoft/definitions?
The package supports PHP 8.1–8.5, aligning with Laravel 10.x (PHP 8.1+) and future Laravel 11.x/12.x (PHP 8.5+). No breaking changes exist for Laravel 10.x, but PHP 8.5 features could enable stricter type validation in future integrations.
How do I define services in YAML/array format for Laravel?
Use the package’s declarative syntax to define services in YAML or PHP arrays. For example, map a class to a factory or inject parameters. Then, load the definitions into Laravel’s container via a provider. Example: `definitions.yaml` with `services: { MyService: { class: App\Services\MyService, params: { key: value } } }`.
Does yiisoft/definitions support autowiring in Laravel?
Yes, but indirectly. The package provides autowiring-friendly configurations (e.g., class names, parameters). Laravel’s native autowiring will still resolve dependencies, but definitions let you externalize complex configurations. Use `params` or `factory` keys to control instantiation logic.
What’s the performance impact of using definitions in Laravel?
Minimal overhead. Definitions are resolved once and cached by Laravel’s container. PHP 8.5’s JIT compiler may further optimize parsing, but benchmarks show negligible differences for typical Laravel apps. For high-throughput apps, cache definitions explicitly using Laravel’s cache system.
Can I mix yiisoft/definitions with Laravel’s `bind()` and `singleton()`?
Absolutely. Use definitions for externalized configs (e.g., YAML) and Laravel’s methods for runtime bindings. For example, bind a definition-resolved service in `register()`: `$container->bind(MyService::class, fn($c) => $definitions->resolve('MyService', $c));`.
Are there Laravel-specific adapters or helpers for this package?
No official Laravel adapters exist, but you can create a `DefinitionsServiceProvider` to streamline integration. Example: Load definitions in `boot()` and bind them to Laravel’s container. Community packages like `spatie/laravel-yaml-config` may also complement this workflow.
How do I validate definitions before runtime in Laravel?
Use the package’s built-in validation (e.g., `DefinitionValidator`). For stricter checks, leverage PHP 8.5’s typed properties or custom attributes. Example: Add `#[SensitiveParameter]` to mark private params, then validate with `DefinitionValidator::validate($definitions, $container)`.
What alternatives exist for declarative DI in Laravel?
Consider `php-di/php-di` (PHP-DI) for PSR-11 containers, `illuminate/container` (Laravel’s native container), or `league/container` for lightweight alternatives. `yiisoft/definitions` stands out for YAML/array configs and YiiSoft ecosystem integration, but PHP-DI offers more Laravel-native tooling.
How do I test definitions in Laravel’s testing environment?
Mock the `Definitions` container in tests. Use Laravel’s `MockContainer` or `createMock(ContainerInterface::class)` to inject fake definitions. Example: `$definitions = $this->createMock(Definitions::class); $definitions->method('resolve')->willReturn(new MyService());` in your test’s `setUp()`.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope