2017 © Pedro Peláez
 

library container

Simple PHP DI Container.

image

amber/container

Simple PHP DI Container.

  • Thursday, July 26, 2018
  • by systemson
  • Repository
  • 1 Watchers
  • 3 Stars
  • 121 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 3933 % Grown

The README.md

GitHub last commit Latest Stable Version Latest Beta Version PHP from Packagist Build Status Coverage Status Total Downloads GitHub, (*1)

Container

Simple PHP DI Container., (*2)

Instalation

composer require amber/container

API (Draft)

Basic Usage (PSR-11 compliance)

use Amber\Container\Container;

$container = new Container();

bind()

Binds an item to the Container's map by a unique key.

bind(string $key, mixed $value) : boolean, (*3)

param string $key The unique item's key., (*4)

param mixed $value The value of the item., (*5)

return bool True on success. False if key already exists., (*6)

Bind an Service to the container by a unique key., (*7)

$container->bind($key, $value);

Or bind a class like this., (*8)

$container->bind($class);

get()

Gets an item from the Container's map by its unique key

get(string $key): mixed, (*9)

param string $key *The unique item's key., (*10)

return mixed The value of the item., (*11)

$container->get($key);

has()

Checks for the existance of an item on the Container's map by its unique key.

has(string $key): bool param string $key *The unique item's key. return bool, (*12)

$container->has($key);

unbind()

Unbinds an item from the Container's map by its unique key.

unbind(string $key): bool, (*13)

param string $key *The unique item's key., (*14)

return bool true on success, false on failure., (*15)

$container->unbind($key);

Multiple actions

bindMultiple()

$container->bindMultiple([$key => $value]);

getMultiple()

$container->getMultiple($keys);

unbindMultiple()

$container->unbindMultiple($keys);

Advanced Usage

make()

Binds and Gets a Service from the Container's map by its unique key.

make(string $class): mixed, (*16)

param string $class The item's class., (*17)

return mixed The value of the item., (*18)

$container->make($class);

register()

Binds an class to the Container and return the ServiceClass.

register(string $class, string $alias = null): ServiceClass, (*19)

param string $class The item's class., (*20)

param string $alias The item's alias., (*21)

return ServiceClass, (*22)

$container->register($class);

singleton()

Binds an class to the Container as singleton and return theServiceClassservice.

singleton(string $class, string $alias = null): ServiceClass, (*23)

param string $class The item's class., (*24)

param string $alias The item's alias., (*25)

return ServiceClass, (*26)

$container->singleton($class);

getClosureFor()

Gets a closure for a method of the provided class.

getClosureFor(string $class, string $method, array $binds = []): Closure, (*27)

param string $class The class to instantiate., (*28)

param string $method The class method to call., (*29)

param array $binds The arguments for the service., (*30)

return Closure, (*31)

$container->getClosureFor($class, $method);

More coming soon..., (*32)

The Versions

26/07 2018

dev-master

9999999-dev

Simple PHP DI Container.

  Sources   Download

GPL-3.0-or-later

The Requires

 

The Development Requires

by Deivi Peña