PHPackages                             syberisle/zit - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. syberisle/zit

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

syberisle/zit
=============

Zit is a simple dependency injector based heavily on Pimple. It aims to provide the same simplicity as Pimple while offering a slightly more robust object interface.

3.0.1(5y ago)010[1 PRs](https://github.com/SyberIsle/Zit/pulls)MITPHPPHP &gt;=5.4.0

Since Jul 25Pushed 1y agoCompare

[ Source](https://github.com/SyberIsle/Zit)[ Packagist](https://packagist.org/packages/syberisle/zit)[ Docs](https://github.com/syberisle/Zit)[ RSS](/packages/syberisle-zit/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (0)

Zit
===

[](#zit)

[![Build Status](https://camo.githubusercontent.com/f601d4b0a5bb09ed16db30d1c1e1b493a76bf38facef00ac26b1558f70b6c837/68747470733a2f2f7472617669732d63692e6f72672f737962657269736c652f5a69742e737667)](https://travis-ci.org/syberisle/Zit)[![Packagist Version](https://camo.githubusercontent.com/4e503176f9ca72e571f43cddc6190ca314acf0e3ff9d9b369d35cd6f0d62b0c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737962657269736c652f7a69742e737667)](https://packagist.org/packages/syberisle/zit)[![GitHub Stars](https://camo.githubusercontent.com/b7336c1b56d62d78ba3b31e376cd901de93c7ae8a2e47a0b126e3bcce22f14b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f737962657269736c652f5a69742e737667)](https://github.com/syberisle/Zit/stargazers)[![PHP 5.4+](https://camo.githubusercontent.com/8c0f60d1723a338ee0f3b5b125c850929c83d5a0c48322b0ea62c3c154c2750f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e342d79656c6c6f77677265656e2e737667)](https://secure.php.net/releases/5_4_0.php)

Zit is a simple dependency injector based heavily on Pimple. It aims to provide the same simplicity as Pimple while offering a slightly more robust object interface.

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

[](#installation)

Zit is available via Composer:

```
composer require syberisle/zit
```

Usage
-----

[](#usage)

Zit is simple to use. Like Pimple, objects are defined through anonymous functions that return an instance of the object:

```
$container = new \Zit\Container();
$container->set('auth', function() {
	return new Auth();
});
```

All instantiation functions are passed the container as the first argument, making dependency injection possible:

```
$container->set('auth', function($container) {
	return new Auth($container->get('db'));
});
```

Zit also provides convenient magic methods for setting instantiation functions:

```
$container->setAuth(function() { /* ... */ }); // Or:
$container->set_auth(function() { /* ... */ });
```

Getting Objects
---------------

[](#getting-objects)

Getting objects are as simple as:

```
$container->get('auth');
```

Or, if you prefer the shorthand:

```
$container->getAuth(); // Or:
$container->get_auth();
```

Getting Fresh Objects
---------------------

[](#getting-fresh-objects)

By default, all objects are shared in Zit. That is, once an object is created, that same exact object is returned for each additional `get()`. If you need a fresh object, you can do so with:

```
$container->fresh('auth'); // Or:
$container->freshAuth(); // Or:
$container->fresh_auth(); // Or:
$container->newAuth(); // Or:
$container->new_auth();
```

> Note that because the 'new' keyword is reserved, you can only use it if you're using the magic methods.

Constructor Parameters
----------------------

[](#constructor-parameters)

Sometimes you need to pass parameters to the constructor of an object, while still also injecting dependencies. Zit automatically passes all parameters on to your instantiation function:

```
$container->setUser(function($c, $id)) {
	$user = new User($id);
	$user->setDb($c->getDb());
	return $user;
});

$user = $container->newUser(1);

// Parameters are taken into account when caching results:
$user2 = $container->getUser(1); // $user2 === $user;
```

Storing Static Content
----------------------

[](#storing-static-content)

You can also use Zit to store strings/objects/etc. Just pass it instead of a generator:

```
$container->set('api_key', 'abcd1234567890');
$key = $container->get('api_key');
```

**Please note:** You must wrap callables with an instantiation function if you want the callable returned rather than the return value of the callable.

Custom Container
----------------

[](#custom-container)

Most projects will benefit from a custom container that sets up its own injection rules. This is as simple as extending Zit:

```
namespace MyApp\Di;

class Container extends \Zit\Container
{
	public function __construct()
	{
		$this->setAuth(function() { /* ... */ });
		$this->setUser(function() { /* ... */ });
	}
}
```

Change Log
----------

[](#change-log)

### Version 3.0.0

[](#version-300)

- Implemented [Container Interoperability](https://github.com/container-interop/container-interop). Zit was already `container-interop` compatible, but it now implements the interface and throws an exception that implements `Interop\Container\Exception\NotFoundException` when a item is not found. This exception extends `\InvalidArgumentException`, so 3.0.0 should be nearly 100% backwards-compatible, but I'm bumping the major version just in case.
- Dropped support for PHP 5.3
- Removed deprecated function `setParam`
- `setFactory()` now accepts any `callable` instead of specifically a `Closure`
- Fixed a typo in the exception message thrown from `__call` if a method does not exist
- `set()` is now fluent (returns the container for chaining)
- Switched to md4 hashing for speed improvements (we don't need the security of md5)
- Added DocBlocks throughout the code

### Version 2.0

[](#version-20)

- Removed the `setParam` method in favor of checking whether the parameter passed to `set` is callable.
- Added the "Factory" variant. This could cause backwards compatibility issues if you have set up objects that end with the word "factory".
- Updated the `delete` method so that it clears out objects, callbacks, and factories, which could have some abnormal BC issues as well.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 85.4% 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 ~841 days

Total

4

Last Release

1837d ago

Major Versions

2.0.0 → 3.0.02016-03-11

PHP version history (2 changes)2.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5eb9bc1606754fee81247bf5d4a6a4d7fb7cce1b3769de69a345c5c8e120211e?d=identicon)[dlundgren](/maintainers/dlundgren)

---

Top Contributors

[![inxilpro](https://avatars.githubusercontent.com/u/21592?v=4)](https://github.com/inxilpro "inxilpro (35 commits)")[![jhoughtelin](https://avatars.githubusercontent.com/u/6137941?v=4)](https://github.com/jhoughtelin "jhoughtelin (4 commits)")[![dlundgren](https://avatars.githubusercontent.com/u/1322393?v=4)](https://github.com/dlundgren "dlundgren (2 commits)")

---

Tags

containerdependencydependency-injectiondipimplezit

### Embed Badge

![Health badge](/badges/syberisle-zit/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/packages/php-di-php-di)[league/container

A fast and intuitive dependency injection container.

86894.4M432](/packages/league-container)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

352982.2k60](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3512.7M3](/packages/mrclay-props-dic)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2860.1k2](/packages/capsule-di)[slince/di

A flexible dependency injection container

20272.1k6](/packages/slince-di)

PHPackages © 2026

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