PHPackages                             thumbtack/ttinjector - 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. thumbtack/ttinjector

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

thumbtack/ttinjector
====================

Construct anything using dependency injection

1.0.4(10y ago)37.2k—9.2%MITPHPPHP &gt;=5.4

Since Feb 13Pushed 9y ago50 watchersCompare

[ Source](https://github.com/thumbtack/ttinjector)[ Packagist](https://packagist.org/packages/thumbtack/ttinjector)[ Docs](https://github.com/thumbtack/ttinjector)[ RSS](/packages/thumbtack-ttinjector/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

ttinjector
==========

[](#ttinjector)

[![Build Status](https://camo.githubusercontent.com/ab9e9851229f2abf116cc034c12d2a372558160d7dfe88f53d7bdff6db608c2a/68747470733a2f2f7472617669732d63692e6f72672f7468756d627461636b2f7474696e6a6563746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/thumbtack/ttinjector)

This is a simple dependency injector.

It works in two stages. First, you register all the dependencies and describe how they relate to each other. Then, you build an injector out of those dependencies that can inject the values you have added.

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

[](#installation)

To install, use [composer](https://getcomposer.org/) and run:

```
composer require thumbtack/ttinjector

```

How to use the injector:
------------------------

[](#how-to-use-the-injector)

### 1. Create a Dependencies object:

[](#1-create-a-dependencies-object)

```
use TT\injector\Dependencies;

$dependencies = new Dependencies();
```

### 2. Add some dependencies:

[](#2-add-some-dependencies)

```
// Use register_value() to add constant values.
$dependencies->register_value('current_user_id', 12345);

// Use register_factory() to add things you don't want to construct unless used...
$dependencies->register_factory('db_connection', [], function() {
   return Database::Connect();
});

// ...Or things that have dependencies of their own.
$dependencies->register_factory(
   'users_source'
   ['db_connection'],
   function ($db) {
       return function($user_id) use ($db) {
          return $db->query('users')->where_equals('user_id', $user_id);
       };
   }
);
```

### 3. Build the injector:

[](#3-build-the-injector)

```
$injector = $dependencies->build_injector();
```

The `build_injector()` function will check to make sure there aren't any errors in the dependencies you've set up (missing dependencies or dependency cycles).

Injector objects are immutable.

### 4. Inject your dependencies!

[](#4-inject-your-dependencies)

```
function current_user($current_user_id, $users_source) {
   return $users_source($current_user_id);
}

$user = $injector->inject('current_user', ['current_user_id', 'users_source']);
```

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~198 days

Total

3

Last Release

3807d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ab1782535df3a8bd3d8cd7eac5fc510bf4a53e5daac6c1d3168312ad1a7fc17?d=identicon)[jmikkola](/maintainers/jmikkola)

---

Top Contributors

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

---

Tags

foundationdependency-injection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thumbtack-ttinjector/health.svg)

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

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26767.4M70](/packages/php-di-invoker)[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.

436818.0k21](/packages/level-2-dice)[matthiasnoback/symfony-service-definition-validator

Library for validating service definitions created with the Symfony Dependency Injection Component

90362.2k7](/packages/matthiasnoback-symfony-service-definition-validator)[respect/config

A powerful, small, deadly simple configurator and dependency injection container made to be easy.

10212.3k1](/packages/respect-config)[arokettu/phpstorm-metadata-export

Export PhpStorm Advanced Metadata from DI containers

1240.1k1](/packages/arokettu-phpstorm-metadata-export)[x-wp/di

The dependency injection container for WordPress

314.6k16](/packages/x-wp-di)

PHPackages © 2026

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