Download the PHP package corpus/di without Composer
On this page you can find all versions of the php package corpus/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package di
Short Description Simple Yet Powerful PSR-11 Complaint Di Container
License MIT
Informations about the package di
Corpus Di
A Simple PSR-11 Complaint Di Container
Requirements
- php: >=7.4
- psr/container: ~1.0 || ~2.0
Installing
Install the latest version with:
Usage
Getting started with Di the three most important methods follow.
- The
set
method is used to set either the item to return or a lambda to lazily construct it, optionally taking constructor arguments. - The
get
method is used to retrieve values with memoization after the initial lazy loading. - The
getNew
is used to invoke the lazy loading creation lambda every call, optionally taking an array of constructor arguments as a second parameter.
Documentation
Class: \Corpus\Di\Di
Method: Di->getMany
Retrieve multiple item; cached if existing. For use with list()
Parameters:
- string[]
$ids
- The names/keys of the items
Returns:
- array
Method: Di->get
Finds an entry of the container by its identifier and returns it.
Parameters:
- string
$id
- Identifier of the entry to look for.
Throws: \Psr\Container\NotFoundExceptionInterface
- No entry was found for this identifier.
Throws: \Psr\Container\ContainerExceptionInterface
- Error while retrieving the entry.
Returns:
- mixed - Entry.
Method: Di->getManyNew
Retrieve multiple item. For use with list()
Parameters:
- array[]
$data
- The array of (names/keys / argument) pair tuple of the items
Throws: \InvalidArgumentException
Returns:
- array
Method: Di->getNew
Retrieve an item
Parameters:
- string
$id
- The name/key of the item - array
$args
Throws: \Corpus\Di\Exceptions\UndefinedIdentifierException
Method: Di->duplicate
Clone a given value into a second key
Parameters:
- string
$src
- The source - string
$dest
- The destination
Method: Di->set
Store a value via key to retrieve later
Parameters:
- string
$id
- The name/key of the item - mixed
$value
- The value to store
Method: Di->has
Returns true if the container can return an entry for the given identifier.
Returns false otherwise.
has($id)
returning true does not mean that get($id)
will not throw an exception.
It does however mean that get($id)
will not throw a NotFoundExceptionInterface
.
Parameters:
- string
$id
- Identifier of the entry to look for.
Returns:
- bool
Method: Di->raw
Parameters:
- string
$id
- The name/key to be retrieved
Throws: \Corpus\Di\Exceptions\UndefinedIdentifierException
Method: Di->constructFromReflectiveParams
Use reflection to execute a classes constructor with auto-populated parameters
Parameters:
- string
$className
- The class to construct - array
$initials
- An ordered list of arguments to populate initial arguments on constructor
Method: Di->callFromReflectiveParams
Use reflection to execute a callable with auto-populated parameters
Parameters:
- array
$initials
- An ordered list of arguments to populate initial arguments on callable
Returns:
- mixed - the return value of the callable.
Class: \Corpus\Di\Exceptions\UndefinedIdentifierException
Thrown when attempting to retrieve a key that does not exist.