PHPackages                             bugadani/factory - 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. [Framework](/categories/framework)
4. /
5. bugadani/factory

ActiveLibrary[Framework](/categories/framework)

bugadani/factory
================

A simple DIC library

v1.0(10y ago)118MITPHPPHP &gt;=5.4

Since May 3Pushed 10y ago2 watchersCompare

[ Source](https://github.com/bugadani/Factory)[ Packagist](https://packagist.org/packages/bugadani/factory)[ RSS](/packages/bugadani-factory/feed)WikiDiscussions master Synced today

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

[![Build Status](https://camo.githubusercontent.com/5f1e0294667265f819b428d180b91b6927f06cd8c7a2bc2b5bf8bcc038f462f2/68747470733a2f2f7472617669732d63692e6f72672f6275676164616e692f466163746f72792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bugadani/Factory)

Factory
=======

[](#factory)

Factory is a simple PHP dependency injection container for PHP 7 and newer.

Usage
-----

[](#usage)

To instantiate an object, simply pass its name to Factory::get(). The instantiated objects are stored and can be retrieved later.

```
$instance = $factory->get(FooClass::class);

```

Class dependencies are resolved automatically.

```
class FooClass {
    public function __construct(BarClass $b){
        //$b will be injected
    }
}
$instance = $factory->get(FooClass::class);

```

Other constructor parameters may be defined by passing an array to either Factory::setParameters(), or as the second argument of Factory::get(). These parameters may be both positional or named. Named parameters have precedence over positional ones and parameters passed to Factory::get() will override the ones set via Factory::setParameters().

```
class FooClass {
    public function __construct($a, $b){
        //$a == 'foobar'
        //$b == 'baz'
    }
}
$factory->setParameters(FooClass::class, ['b' => 'baz', 0 => 'foobar']);
$instance = $factory->get(FooClass::class);

```

Individual parameters can also be set using `$factory->setParameter(FooClass::class, $parameterNameOrPosition, $parameterValue)`

Class names may also be aliased, which may be useful to inject interface implementations or extended classes. Aliased classes use the actual class' parameters.

```
class FooClass {
    public function __construct(SomeInterface $a){
        //$a instanceof SomeInterfaceImpl
    }
}
$factory->addAlias(SomeInterfaceImpl::class, SomeInterface::class);
$instance = $factory->get(FooClass::class);

```

It is possible to set callback functions to be called when an object is instantiated to do some additional initialization. The Factory instance and the object is passed to the callback. This callback will only be called if a new object is created.

```
$factory->addCallback(SomeClass::class, function(Factory $factory, SomeClass $instance){});
$instance = $factory->get(SomeClass::class);

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

3714d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ba12833634c15d1916a7f3f29be4d1a89d40c36e7ebab46a576ff9b6e75caa6?d=identicon)[bugadani](/maintainers/bugadani)

---

Top Contributors

[![bugadani](https://avatars.githubusercontent.com/u/977627?v=4)](https://github.com/bugadani "bugadani (8 commits)")

---

Tags

frameworkdependency-injectiondic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bugadani-factory/health.svg)

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

PHPackages © 2026

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