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

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

aeviiq/factory
==============

Service Factory Component

v3.2.1(4y ago)57.1k2MITPHPPHP ^7.2

Since May 31Pushed 4y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

Dependency Injection Factory Component
======================================

[](#dependency-injection-factory-component)

Why
---

[](#why)

To enable you to create service based factories rapidly, without having to configure anything outside the factory, as the factory itself always knows what it will return, and thus 'requires' in order to do so. This becomes especially useful when combined with the Symfony autowiring functionality, as the only method you will need is the getTargetInterface() for everything to be done automatically.

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

[](#installation)

```
composer require aeviiq/factory

```

##### Symfony &gt;= 4

[](#symfony--4)

```
// src/Kernel.php
namespace App;

use Aeviiq\Factory\FactoryCompilerPass;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    // ...

    protected function build(ContainerBuilder $container): void
    {
        $container->addCompilerPass(new FactoryCompilerPass());
    }
}
```

##### Symfony &lt; 4

[](#symfony--4-1)

```
// src/AppBundle/AppBundle.php
namespace AppBundle;

use Aeviiq\Factory\FactoryCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new FactoryCompilerPass());
    }
}
```

Declaration
-----------

[](#declaration)

```
final class EncoderFactory extends AbstractServiceFactory
{
    public function getEncoder(User $user): Encoder
    {
        // getOneBy ensures 1, and only 1 encoder is returned.
        // In case multiple encoders (or none) are found, a LogicException will be thrown.
        // In case the result is optional, you could use the getOneOrNullBy().
        return $this->getOneBy(static function (Encoder $encoder) use ($user) {
            return $encoder->supports($user);
        });
    }

    protected function getTargetInterface(): string
    {
        // All services with this interface will automatically be wired to the factory
        // without needing any additional service configuration.
        // Using autowire these few lines are all you would need to implement your factory.
        return Encoder::class;
    }
}
```

Usage
-----

[](#usage)

```
final class Foo
{
    /**
     * @var FactoryInterface
     */
    private $encoderFactory;

    public function __construct(FactoryInterface $encoderFactory)
    {
        $this->encoderFactory = $encoderFactory;
    }

    public function authenticateUser(User $user): void
    {
        // ...
        $encoder = $this->encoderFactory->getEncoder($user);
        if (!$encoder->isValidPassword($user->getPassword, $presentedPassword, $user->getSalt())) {
            // ...
        }
        // ...

    }
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% 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 ~50 days

Recently: every ~139 days

Total

16

Last Release

1777d ago

Major Versions

v1.0.2 → v2.02019-07-05

2.0.x-dev → 3.0.x-dev2019-07-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/ddea76b85349ccad7ab6bb0b3e3272482bc0861508f873f4438ccca9d062c14f?d=identicon)[aeviiq](/maintainers/aeviiq)

---

Top Contributors

[![aeviiq](https://avatars.githubusercontent.com/u/34397049?v=4)](https://github.com/aeviiq "aeviiq (35 commits)")[![nusje2000](https://avatars.githubusercontent.com/u/17175959?v=4)](https://github.com/nusje2000 "nusje2000 (2 commits)")[![dbrekelmans](https://avatars.githubusercontent.com/u/9531344?v=4)](https://github.com/dbrekelmans "dbrekelmans (1 commits)")

---

Tags

factory

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aura/dispatcher

Creates objects from a factory and invokes methods using named parameters; also provides a trait for invoking closures and object methods with named parameters.

3695.0k3](/packages/aura-dispatcher)[nikolaposa/cascader

Utility for creating objects in PHP from constructor parameters definitions.

12237.5k3](/packages/nikolaposa-cascader)[illuminatech/array-factory

Allows DI aware object creation from array definition

2159.6k5](/packages/illuminatech-array-factory)[aerni/factory

Quickly whip up fake content

193.5k](/packages/aerni-factory)

PHPackages © 2026

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