learncorephp/container

The Core PHP Framework Container

dev-master 2019-05-21 20:03 UTC

This package is auto-updated.

Last update: 2024-04-22 06:59:02 UTC


README

This is the default container used in the Core PHP Framework. It is PSR-11 compatable.

Installation

Requirements

PHP >= 7.0.0

Via Composer

Installation via Composer is the recommended method of installation.

composer require learncorephp/container

Basic Usage

<?php

use Core\Container\Contracts;

// Create a new Container instance
$container = new Container;

// Add via Factory
$this->addFactory('SomeGreatProject', function() {
    return new Some\Great\Project;
});

// Add via Constructor
$this->addClass('SomeGreatProject', Some\Great\Project::class);

// Add via Setter
$this->addSetter('SomeGreatProject', 'Some\Great\Project', [
    'setName' => 'ThisIsHell'
]);

// Return a new instance
$awesome = $container->get('SomeGreatProject');