Download the PHP package xynha/dicontainer without Composer
On this page you can find all versions of the php package xynha/dicontainer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xynha/dicontainer
More information about xynha/dicontainer
Files in xynha/dicontainer
Package dicontainer
Short Description PSR-11 compliant PHP dependency injection container
License Apache-2.0
Homepage https://github.com/pattisahusiwa/dicontainer
Informations about the package dicontainer
DiContainer
PSR-11 compliant PHP dependency injection container.
Table of Contents
- DiContainer
- Table of Contents
- Installation
- Usage
- DiContainer rules
- #
shared
:boolean
(defaultfalse
) - #
instanceOf
:string|object
(defaultnull
) - #
constructParams
:array
(defaultnull
) - #
substitutions
: associativearray
(defaultnull
) - #
getFrom
:array
(defaultnull
) - Use cases
- Changelog
- Contributing
- License
Installation
Use composer to install the library.
Usage
DiContainer
can be used with or without configuration.
All classes that do not required constructor arguments, can be created directly.
``
However, for complex initialization, you have to define DiContainer
rules and pass them to DiRuleList
.
``
DiContainer rules
General format of DiContainer
rules in JSON format:
`
Where:
rule_key
,another_rule_key
are a class or an interface namespace, andconfig_keys
are supported rule keys:shared
instanceOf
constructParams
substitutions
getFrom
# shared
: boolean
(default false
)
- Possible values:
true
, if the constructed instance can be shared betwen classes during execution,false
, otherwise.
- Example: `
# instanceOf
: string|object
(default null
)
- To override class or interface defined in
rule_key
. - Possible values:
string
: class namespaceobject
: already constructed instance.
- Example: ` Example of passing already constructed instance, ``
# constructParams
: array
(default null
)
constructParams
is a list of constructor argument values.- Example: `
- Construct params can also be retrieved from another class by using
CALL::OBJECT
andCALL::SCALAR
identifiers. CALL::SCALAR
is used to retrievearray
andscalar
valuesCALL::OBJECT
is used to retrieveobject
value.CALL::OBJECT
andCALL::SCALAR
format: `- Example:
\# if constructed manually,
# usingDiContainer
` `` - A constant can be passed to constructor arguments by using
CALL::CONSTANT
, for example `#
substitutions
: associativearray
(defaultnull
) - Substitute interface in the constructor argument with a substituted class.
- Example `
# getFrom
: array
(default null
)
- Get
rule_key
instance from a factory or a class. getFrom
format `- Example `
Use cases
Please check unit test configuration files in tests/Data/config
and the corresponding tests.
Changelog
See CHANGELOG.md
Contributing
All form of contributions are welcome. You can report issues, fork the repo and submit pull request.
For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Released under Apache-2.0 License. See LICENSE file for more details.
`