PHPackages                             outglow/community - 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. outglow/community

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

outglow/community
=================

Outglow PSR-0 dependency injection container

251PHP

Since Jan 23Pushed 13y ago3 watchersCompare

[ Source](https://github.com/hazbo/community)[ Packagist](https://packagist.org/packages/outglow/community)[ RSS](/packages/outglow-community/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Community
=========

[](#community)

[![Build Status](https://camo.githubusercontent.com/10c3de3bb631f09899bf5358ee15e22a1080e56e977413fc52e6b05b8f21cb71/68747470733a2f2f7472617669732d63692e6f72672f68617272792d6c617772656e63652f636f6d6d756e6974792e706e67)](https://travis-ci.org/harry-lawrence/community)

Community is a small and simple dependency injection container for PHP 5.3.0 +

- PSR-0 compliant
- Easy to use
- Stable

Installation
------------

[](#installation)

Add `outglow/community` to your composer.json file

```
{
    "require" : {
        "outglow/community" : "dev-master"
    }
}

```

Then run: `php composer.phar install`(NOTE: An update may be required first)

API
---

[](#api)

```
public function set(String $key, Closure $return, [ Bool $newInstance = false ])

public function stack(Array $classes, [ Bool $newInstance = false ])

public function get(String $key)

public function remove(String $key)

```

Usage
-----

[](#usage)

Let's say this is a class you would like to have access to via what will be a community object:

```

```

For quickness, I'll just include this class, but you should really be using a class loader ;)

```
include('vendor/autoload.php');
include('World.php');

use Outglow\Component\Community\Community;

$community = new Community();

$community->set('world', function() {
    return new World();
});

$world = $community->get('world');

echo $world->sayHello();

```

Here, we have created our community object then have used an anonymous function to return an object of our new class `World` using `set`

We have then used `get` to access our new object via the container, and can call method `sayHello()` with it.

This is just a very basic example, but it can be used in all sorts of ways.

### Extended

[](#extended)

We can also choose whether or not, each time we `get` our community object, it creates a new instance of that class, or a shared one, meaning it will only ever create one instance of that class which will be stored in your container.

```
$community->set('world', function() {
    return new World();
}, true);

```

Passing in true (above) will tell community that we want to instantiate a new instance of that class each time we use the `get` method, where as leaving it blank:

```
$community->set('world', function() {
    return new World();
});

```

Will just let us use the same instance of that object each time.

We can now also remove any given object from the container using the `remove` method. Continuing from the example above, this is how we would remove `world` from the container:

```
$community->remove('world');

```

This can be done after assigning/using the world object, maybe you don't need it in the container anymore, and it will free up memory a little bit.

As of version 1.2, we can use the public method, stack. This is if you are storing a few objects with the same configuration. It doesn't however only limit you to classes/objects. Anything can go in there, here is an example of storing an object, and a string:

```
$community->stack(array(
    'myString' => 'Hello',
    'myObject' => '\stdClass'
));

```

We pass the class through as a string, then Community creates a new object from it, if that class is available. However, we can also just store data as a string, aslong as that string doesn't conflict with a class name. It doesn't just have to be a string, it can be any kind of data.

### Tests

[](#tests)

Unit tests have recently been added, along with a build file for ant. You can test by doing the following:

```
$ cd /path/to/community
$ ant

```

Only using phpunit?

```
$ cd /path/to/community
$ phpunit tests

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4755952c71b2d702aaaf3799c3e9b6cbf30f2d1fb959e7de040b0d8e3b5c85ae?d=identicon)[hazbo](/maintainers/hazbo)

---

Top Contributors

[![mkpeacock](https://avatars.githubusercontent.com/u/437037?v=4)](https://github.com/mkpeacock "mkpeacock (1 commits)")

### Embed Badge

![Health badge](/badges/outglow-community/health.svg)

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

PHPackages © 2026

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