phpfox/container

A simple DI container for the PHPFox framework

Fund package maintenance!
JustSteveKing

0.3.0 2022-01-31 11:30 UTC

This package is auto-updated.

Last update: 2024-11-29 06:16:44 UTC


README

GitHub release (latest by date) tests Total Downloads GitHub

This is the repository for the DI Container used in the PHP-Fox framework.

Installation

You should not need to install this package when using the PHP-Fox framework, however if you wish to use this outside of the framework please use:

composer require phpfox/container

Usage

To use the container, all you need to do is:

$container = Container::getInstance();

$container->bind(
    abstract: Abstract::class,
    concrete: Concrete::class,
    shared: false, // defaults to false - true turns this into a singleton.
);

/**
 * @var bool
 */
$exists = $container->has(
    id: Abstract::class,
);

/**
 * @var Concrete
 */
$concrete = $container->make(
    abstract: Abstract::class,
);

Container implementation inspired by example repo from Jess Archer, which provides a great and simple base.