Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.
/ container Public archive

PSR-11 container implementation for storing object instances

License

Notifications You must be signed in to change notification settings

NanoSector/container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSR-11 Object container

Build Status Scrutinizer Code Quality Scrutinizer Code Coverage Latest Stable Version Latest Unstable Version Total Downloads

Simple PSR-11 Container implementation for storing object instances.

Installation

You can install this class via composer:

composer require yoshi2889/container

Usage

First, instantiate a new ComponentContainer. This is the object which will keep references to the components you put in it.

For any class that may be added to the ComponentContainer, it must implement the ComponentInterface. Optionally, the ComponentTrait trait may be used to provide a ready-to-use means to implement the ComponentInterface.

After adding an instance to the container, it may be retrieved either by using the get method on the container while providing the full class name, or, more conveniently, via the static fromContainer method on the component.

An example of proper usage:

<?php

class ExampleClass implements \Yoshi2889\Container\ComponentInterface
{
	use \Yoshi2889\Container\ComponentTrait;
	
	public function test()
	{
		echo 'Hello world!';
	}
}

$componentContainer = new \Yoshi2889\Container\ComponentContainer();
$exampleClassInstance = new ExampleClass();

$componentContainer->add($exampleClassInstance);

// echoes 'Hello world!'
ExampleClass::fromContainer($componentContainer)->test();

License

This code is released under the MIT License. Please see LICENSE to read it.

About

PSR-11 container implementation for storing object instances

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages