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

Container Laravel Package

league/container

league/container is a lightweight PSR-11 dependency injection container for PHP. Define entries, factories, and autowiring-friendly services to manage application dependencies cleanly, with modern PHP support and solid tooling for testing and analysis.

View on GitHub
Deep Wiki
Context7

layout: post title: Inflectors sections: Deprecation Notice: deprecation-notice Migration Guide: migration-guide Usage: usage

Deprecation Notice

DEPRECATED: Inflectors are deprecated as of v5.2 and will be removed in v6.0. Use afterResolve() or the event system instead.

Migration Guide

Using afterResolve() (recommended)

afterResolve() is a drop-in replacement for the most common inflector patterns. The callback receives the resolved object directly:

Callback form:

<?php

// Before
$container->inflector(LoggerAwareInterface::class, fn($obj) => $obj->setLogger($logger));

// After
$container->afterResolve(LoggerAwareInterface::class, fn($obj) => $obj->setLogger($logger));

Method invocation:

<?php

// Before
$container->inflector(LoggerAwareInterface::class)
    ->invokeMethod('setLogger', [Logger::class]);

// After
$container->afterResolve(LoggerAwareInterface::class, function (object $service) use ($container) {
    $service->setLogger($container->get(Logger::class));
});

Property setting:

<?php

// Before
$container->inflector(DatabaseAwareInterface::class)
    ->setProperty('connection', Database::class);

// After
$container->afterResolve(DatabaseAwareInterface::class, function (object $service) use ($container) {
    $service->connection = $container->get(Database::class);
});

Multiple method calls:

<?php

// Before
$container->inflector(TimestampableInterface::class)
    ->invokeMethods([
        'setCreatedAt' => [new DateTime()],
        'setUpdatedAt' => [new DateTime()]
    ]);

// After
$container->afterResolve(TimestampableInterface::class, function (object $service) {
    $service->setCreatedAt(new DateTime());
    $service->setUpdatedAt(new DateTime());
});

Using the full event API

For advanced use cases such as replacing resolved objects, use listen() directly:

<?php

use League\Container\Event\ServiceResolvedEvent;

$container->listen(ServiceResolvedEvent::class, function (ServiceResolvedEvent $event) {
    $event->setResolved(new CachedRepository($event->getResolved()));
})->forType(RepositoryInterface::class);

See the events documentation for the full API.


Usage

The following documents the deprecated inflector API for reference. New code should use afterResolve() instead.

Inflectors allow you to define the manipulation of an object of a specific type as the final step before it is returned by the container.

This is useful when you want to invoke a method on all objects that implement a specific interface.

<?php

$container = new League\Container\Container();

$container->add(Acme\Logger::class);
$container->add(Acme\LoggerAwareClass::class);
$container->add(Acme\Other\LoggerAwareClass::class);

$container
    ->inflector(LoggerAwareInterface::class)
    ->invokeMethod('setLogger', [Acme\Logger::class])
;

Now instead of adding a method call to each class individually we can simply define an inflector to invoke the method for every class of that type.

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.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony