Download the PHP package webiik/container without Composer
On this page you can find all versions of the php package webiik/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webiik/container
More information about webiik/container
Files in webiik/container
Package container
Short Description The Container adds handy methods to most common Pimple functions and then adds automatic injection of dependencies from container to class constructor.
License MIT
Homepage https://www.webiik.com
Informations about the package container
Container
The Container adds handy methods to most common Pimple functions and then adds automatic injection of dependencies from container to class constructor.
Installation
Example
Adding
addService
addService() ads service factory to container. It returns always same instance of service.
If you need to access container inside $factory:
addServiceFactory
addServiceFactory() ads service factory to container. It returns always new instance of service.
addParam
addParam() ads parameter to container.
addFunction
addFunction() ads function to container.
Check
isIn
isIn() checks if service, parameter or function is stored in container.
Getting
get
get() returns service, parameter or function from container.
Dependency Injection
Container provides automatic dependency injection from Container to class controller using the method injectTo(string $className): array
. However it requires to follow these naming conventions:
Inject Service by Class Name
-
Add service with same name as full name of underlying class:
-
Use full class name as type parameter in controller in your class:
Container will search for service with name
\Webiik\Arr\Arr
. - Inject dependencies to class:
Inject Service by Service Name
-
Add service with name matching the following regex
ws[A-Z]
: -
Add class name alias to your class:
-
Add doc block with parameter type to controller of your class:
Container will search for service with name
wsArray
. - Inject dependencies from container to your class:
php
$container->addFunction('myFnName', function() {
echo 'Hello!';
});
-
Use parameter name in constructor in your class:
Container will search for parameter with name
myParamName
. - Inject dependencies from container to your class:
Inject Container Itself
-
Use full Container class name as type parameter in constructor in your class:
- Inject dependencies from container to your class: