Download the PHP package gres/dim without Composer
On this page you can find all versions of the php package gres/dim. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dim
Dim – PHP Dependency Injection Manager
Dim is a small, simple and powerful Dependency Injection Container for PHP:
Dim works with PHP 5.3 or later.
Installation
You may install the Dim with Composer.
-
Create a
composer.json
file in your project root and run thephp composer.phar install
command to install it: -
Add this line to your application’s index.php file:
- Instantiate the
Container
class:
Alternatively, you can download the archive and extract it.
Defining parameters
For objects you can omit the definition of names, in this case for names will be used class name of object, names of extended classes and interfaces and names of used traits.
Defining services
In first case for names will be used class name, names of extended classes and interfaces and names of used traits.
You can define arguments that will be passed to constructor of service class:
Keys should be identical to parameter names or their positions in constructor definition.
Defining aliases
If you need to add an additional name for defined parameter or service you can use alias
method:
Retrieving data
Also you can pass additional arguments to constructor of service class, they overwrite arguments with same keys passed
to Service
constructor:
Scopes
If you wish to limit the scope for dependencies you can use scopes:
Also you can group actions in scope:
Kinds of services
Service
Class: Dim\Service
Creates and returns new instance of class:
$foo1
and$foo2
are different instances.
Singleton
Class: Dim\Service\Singleton
Once creates an instance of class and always returns the same instance for all calls:
$foo1
and$foo2
are the same.
Factory
Class: Dim\Service\Factory
Returns new instance of class created by function or factory method:
Extension
Class: Dim\Service\Extension
Extends creation of instance by other service:
Other actions
Get raw data from container:
Method: Dim\Container::raw
$foo
will contains an instance ofService
class.
Check that parameter or service is defined:
Methods:
- Dim\Container::has
- Dim\Container::offsetExists
- Dim\Container::__isset
$foo
will containstrue
,$bar
will containsfalse
Remove parameter or service from container:
Methods:
- Dim\Container::remove
- Dim\Container::offsetUnset
- Dim\Container::__unset
Remove all parameters and services from container:
Method: Dim\Container::clear
Tests
To run the test suite, you need PHPUnit:
License
Dim is licensed under the MIT license.