PHPackages                             codeeverything/burlap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. codeeverything/burlap

ActiveLibrary

codeeverything/burlap
=====================

0.1(10y ago)330PHP

Since Apr 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/codeeverything/burlap)[ Packagist](https://packagist.org/packages/codeeverything/burlap)[ RSS](/packages/codeeverything-burlap/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/460bfe6842b1b42bb41f5d448d75c3e515ea3e2d08cdb9393e23ca36a0e3b6e5/68747470733a2f2f7472617669732d63692e6f72672f636f646565766572797468696e672f6275726c61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/codeeverything/burlap)

Burlap
======

[](#burlap)

Burlap is a simple Dependency Injection Container for PHP, inspired by [Fabien Potencier's](https://github.com/fabpot) [Twittee](https://github.com/fabpot/twittee) and [series on Dependency Injection](http://fabien.potencier.org/what-is-dependency-injection.html).

To play nice with others Burlap implements the ContainerInterface and Delegate Container policies from the [Container Interoperability standard](https://github.com/container-interop/container-interop).

### Contributions

[](#contributions)

**NB:** This is not intended to be production ready, but suggestions and PRs are welcomed! :)

### Installation

[](#installation)

Run `composer require codeeverything/burlap` in your terminal

### Testing

[](#testing)

Run `vendor/bin/phpunit` in your terminal from the root of the project

Example Usage
-------------

[](#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:

```
$sack = new Burlap();
$sack->mailer_user([function () {
    return 'username';
}]);

$sack->mailer_pass([function () {
    return 'password';
}]);
```

Create a `mailer_settings` service to grab these:

```
// when defined, a service receives the container as it's first argument and it's dependencies thereafter
$sack->mailer_settings(['mailer_user', 'mailer_pass', function ($c, $user, $pass) {
    $o = new stdclass();
    $o->user = $user . rand();
    $o->pass = $pass . rand();

    // return a single instance of the service by using Burlap's "share" function
    return $c->share('mailer_settings', $o);
}]);
```

Finally, create the `mailer` service, making use of the previously defined services/parameters as dependencies:

```
$sack->mailer(['mailer_settings', function ($c, $settings) {
    $o = new stdclass();
    $o->one = $settings->user;
    $o->two = $settings->pass;
    $o->three = rand() * 10;
    // return a single instance of the service by using Burlap's "share" function
    return $c->share('mailer', $o);
}]);
```

With the service defined, we can now make use of it:

```
// setup two mailers, since the service is shared these will be identical
$mailer1 = $sack->mailer();
$mailer2 = $sack->mailer();

// dump the list of defined services
var_dump($sack->container);
```

Container Interoperability
--------------------------

[](#container-interoperability)

Burlap tries to play nice and implements the [Container Interoperability standard](https://github.com/container-interop/container-interop).

This means we can also access our services in a more standardised way as below:

```
$mailer = $sack->get('mailer');
```

We can also check whether the container has a service of a given name:

```
$hasMailer = $sack->has('mailer');
```

### Delegate Container

[](#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:

```
// must implement the ContainerInterface
$delegate = new SomeOtherContainer();

$sack = new Burlap($delegate);
```

An example of working with dependencies:

```
// must implement the ContainerInterface
$delegate = new Burlap();

// add a service
$delegate->user([function ($c) {
    return '1234';
}]);

// create our Burlap sack, and pass the delegate container
$sack = new Burlap($delegate);

// define a service in Burlap which depends on the service defined in the delegate
// container and pull in the result of that service as $who
$sack->whoAmI(['user', function ($c, $who) {
    return "$who: I am not a number, I am a free man";
}]);
```

TODO
----

[](#todo)

- Update docs to show interop way of getting a service
- Remove magic `__call()` function and split into `add()` and `get()`, for performance
    - Kept for setting and backward compatible getting. But preference is to use -&gt;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... `$sack['param1'] = 'this is a param';`
- Allow "parameters" to be accessed from the container with ArrayAccess? `$sack['param1']`

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3696d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2cdd1eba43a056014e0c2d4e547adf782a52a142f4201608176bfb7ad996a97?d=identicon)[codeeverything](/maintainers/codeeverything)

---

Top Contributors

[![codeeverything](https://avatars.githubusercontent.com/u/9589226?v=4)](https://github.com/codeeverything "codeeverything (31 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeeverything-burlap/health.svg)

```
[![Health](https://phpackages.com/badges/codeeverything-burlap/health.svg)](https://phpackages.com/packages/codeeverything-burlap)
```

###  Alternatives

[laminas/laminas-mvc

Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins

17224.4M365](/packages/laminas-laminas-mvc)[laminas/laminas-mvc-i18n

Integration between laminas-mvc and laminas-i18n

144.5M44](/packages/laminas-laminas-mvc-i18n)[chadicus/slim-oauth2-middleware

OAuth2 middleware for use within a Slim Framework API

48411.9k1](/packages/chadicus-slim-oauth2-middleware)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.4M2](/packages/mouf-pimple-interop)[enlitepro/enlite-monolog

Monolog integration to Laminas

18641.6k](/packages/enlitepro-enlite-monolog)[maglnet/magl-markdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

22178.2k4](/packages/maglnet-magl-markdown)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
