PHPackages                             stuartwakefield/platter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. stuartwakefield/platter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stuartwakefield/platter
=======================

Light-touch dependency injection

v0.1.1-alpha(11y ago)051MITPHPPHP &gt;=5.3.0

Since Aug 20Pushed 11y ago1 watchersCompare

[ Source](https://github.com/stuartwakefield/platter)[ Packagist](https://packagist.org/packages/stuartwakefield/platter)[ Docs](http://platter.stuartw.io)[ RSS](/packages/stuartwakefield-platter/feed)WikiDiscussions master Synced 5d ago

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

Platter
=======

[](#platter)

Light-touch dependency injection.

[![Build status](https://camo.githubusercontent.com/f342e4d0f1f678d8b65f648230a161b6129a440bd2bd460439210a6b3e77e892/68747470733a2f2f7472617669732d63692e6f72672f73747561727477616b656669656c642f706c61747465722e737667)](https://travis-ci.org/stuartwakefield/platter)

Usage
-----

[](#usage)

To install add to your composer.json:

```
"require": {
	"stuartwakefield/platter": "0.1.0"
}
```

After you have run `composer install` you will be able to use the `Platter` DI manager.

Create a new `Platter` instance with your definitions:

```
$factory = new Platter(array(
	'dbuser' => 'admin',
	'dbpassword' => 'password',
	'dbname' => 'test',
	'dbhost' => '0.0.0.0',
	'connectionstring' => function ($container) {
		return "mysql:dbname={$container->get('dbname')};host={$container->get('dbhost')}";
	},
	'pdo' => function ($container) {
		return new PDO(
			$container->get('connectionstring'),
			$container->get('dbuser'),
			$container->get('dbpassword')
		);
	},
	'repository' => function ($container) {
		return new Repository($container->get('pdo'));
	}
));
```

To retrieve an object from your container, just use the `get` method:

```
$repository = $factory->get('repository');
```

You can also link `Platter` containers together, one container is considered the child and the other the parent.

```
$parent = new Platter(array(
	'dbuser' => 'xyz',
	'dbpassword' => 'abc'
));

$factory = new Platter(array(
	'DataSource' => function ($container) {
		return new DataSource(
			$container->get('dbuser'),
			$container->get('dbpassword')
		);
	}
), $parent);

$ds = $factory->get('DataSource');
```

When resolving dependencies if the child does not have a definition for the dependency the dependency will be obtained from the parent.

**Note:** The direction in which dependencies are resolved is unidirectional, a parent will not check it's children for a dependency. Therefore, definitions attached to a container can only access other definitions within that container and it's parents but not it's children.

The following will not work:

```
$parent = new Platter(array(
	'DataSource' => function ($container) {
		return new DataSource(
			$container->get('dbuser'),
			$container->get('dbpassword')
		);
	}
));

$factory = new Platter(array(
	'dbuser' => 'xyz',
	'dbpassword' => 'abc'
), $parent);

$ds = $factory->get('DataSource'); // "Identifier 'dbuser' is not defined"
```

This may cause confusion if not understood:

```
$parent = new Platter(array(
	'name' => 'Joe',
	'example' => function ($container) {
		return $container->get('name');
	}
));

$factory = new Platter(array(
	'name' => 'Michael'
), $parent);

echo $factory->get('name'); // "Michael"
echo $factory->get('example'); // "Joe"
```

The `example` definition does not have access to the `name` definition from the child and so the `name` definition from the parent container is returned instead.

Builder interface
-----------------

[](#builder-interface)

Platter also comes with a builder interface to register items using a friendly and expressive builder interface. Once built the platter is immutable.

```
$builder = new Platter\Builder;
$parent = $builder
	->register('dbuser', 'xyz')
	->register('dbpassword', 'abc')
	->build();

$builder = new Platter\Builder;
$factory = $builder
	->register('DataSource', function ($container) {
		return new DataSource(
			$container->get('dbuser'),
			$container->get('dbpassword')
		);
	})
	->connect($parent)
	->build();
```

To show all available items served by the platter:

```
$factory->available(); // array('DataSource', 'dbpassword', 'dbuser');
```

To show the items that the platter instance itself defines:

```
$factory->defined(); // array('DataSource');
```

To create a singleton use the Singleton definition object:

```
$builder
	->register('DataSource', new Platter\Definition\Singleton(function ($container) {
		return new DataSource(
			$container->get('dbuser'),
			$container->get('dbpassword')
		);
	}))
	->build();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Every ~0 days

Total

2

Last Release

4288d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/014ccb133553300d5da0536a51d9ef49d0e49434bd20ed99c27c46ddb0540b52?d=identicon)[stuartwakefield](/maintainers/stuartwakefield)

---

Top Contributors

[![stuartwakefield](https://avatars.githubusercontent.com/u/664303?v=4)](https://github.com/stuartwakefield "stuartwakefield (24 commits)")

---

Tags

dependency-injectiondiioc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stuartwakefield-platter/health.svg)

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

###  Alternatives

[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437730.3k17](/packages/level-2-dice)[x-wp/di

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)[michaels/data-manager

Simple data manager for nested data, dot notation array access, extendability, and container interoperability.

121.9k2](/packages/michaels-data-manager)

PHPackages © 2026

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