Download the PHP package codeeverything/burlap without Composer
On this page you can find all versions of the php package codeeverything/burlap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package burlap
Burlap
Burlap is a simple Dependency Injection Container for PHP, inspired by Fabien Potencier's Twittee and series on Dependency Injection.
To play nice with others Burlap implements the ContainerInterface and Delegate Container policies from the Container Interoperability standard.
Contributions
NB: This is not intended to be production ready, but suggestions and PRs are welcomed! :)
Installation
Run in your terminal
Testing
Run in your terminal from the root of the project
Example Usage
Drawing upon Fabien Potencier's example in his dependency injection series, let's imagine setting up a mailer service.
Adding items to a Burlap container follows the same pattern as defining a service in AngularJS, where a single array argument is passed with the final element of this being the function to run, and all prior elements defining dependencies for that function. These dependencies should be services already registered with Burlap and are passed as arguments to the service being defined.
Create parameters for username and password:
Create a service to grab these:
Finally, create the service, making use of the previously defined services/parameters as dependencies:
With the service defined, we can now make use of it:
Container Interoperability
Burlap tries to play nice and implements the Container Interoperability standard.
This means we can also access our services in a more standardised way as below:
We can also check whether the container has a service of a given name:
Delegate Container
The Container Interoperability standard also defines a means of two containers working together, with one container living inside the other and acting solely to provide any necessary dependencies to the services defined in the other.
Burlap implements this by allowing you to pass the delegate container as a constructor argument:
An example of working with dependencies:
TODO
- [x] Update docs to show interop way of getting a service
- [x] Remove magic function and split into and , for performance
- Kept for setting and backward compatible getting. But preference is to use ->get(serviceID)
- [ ] Update tests to check for expected exceptions and test get() and has() methods
- [ ] Allow "parameters" to be set with ArrayAccess? Only non-callable items should be allowed...
- [ ] Allow "parameters" to be accessed from the container with ArrayAccess?