sauber-php/container

The Container component for the Sauber PHP framework

Fund package maintenance!
juststeveking

dev-main 2022-05-27 11:47 UTC

This package is not auto-updated.

Last update: 2024-11-09 22:23:01 UTC


README

Container

GitHub release (latest by date) Tests Static Analysis Total Downloads GitHub

This is the repository for the DI Container used in the Sauber PHP Framework.

Installation

You should not need to install this package, as it comes pre-installed with the Sauber PHP Framework, however if you want to use this outside of the framework please use composer:

composer require sauber-php/container

Usage

To use the container, you can manually add definitions:

$container = new Container(
    definitions: [
        UserRepositoryInterface::class => UserRepository::class,
    ],
);

$repository = $container->get(
    id: UserRepositoryInterface::class,
);

To make a new container with injected callables:

$injectors = [
    UserRepositoryInterface::class => UserRepository::class,
];

$container = Container::make(
    injectors: $injectors,
);

$repository = $container->get(
    id: UserRepositoryInterface::class,
);

Testing

To run the tests:

./vendor/bin/pest

Static Analysis

To check the static analysis:

./vendor/bin/phpstan analyse

Changelog

Please see the Changelog for more information on what has changed recently.