PHPackages                             thecodingmachine/common-factories - 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. thecodingmachine/common-factories

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

thecodingmachine/common-factories
=================================

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

v0.4.1(7y ago)1192.9k↓40.6%17MITPHPPHP &gt;=5.4

Since May 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/thecodingmachine/common-factories)[ Packagist](https://packagist.org/packages/thecodingmachine/common-factories)[ RSS](/packages/thecodingmachine-common-factories/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (7)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f35bce0aea7fc4714b71920e9fce0cdd67f3abdd982c6a8f791a43ccb9d9dd34/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f636f6d6d6f6e2d666163746f726965732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thecodingmachine/common-factories/?branch=master)[![Build Status](https://camo.githubusercontent.com/1b30c986ce6554bbb80c4d619622b52e69dc525c3731314bf8b78103edbfff0d/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f636f6d6d6f6e2d666163746f726965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/thecodingmachine/common-factories)[![Coverage Status](https://camo.githubusercontent.com/7b057a7bbbe9d358311ab3abff1cc4fde6d9310d38ba083f8fba82c0b5df0f2f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f636f6d6d6f6e2d666163746f726965732f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/common-factories?branch=master)

Utility factories for container-interop/service-provider
========================================================

[](#utility-factories-for-container-interopservice-provider)

**Work in progress.**

This project is part of the [container-interop](https://github.com/container-interop/container-interop) group. It tries to find a solution for cross-framework modules (aka bundles) by the means of container-agnostic configuration.

Goal of this project
--------------------

[](#goal-of-this-project)

This project provides utility factories that can be used directly in service providers complying with the [container-interop/service-provider](https://github.com/container-interop/service-provider) standard.

Those common factories can be detected by compiled/cached containers. The aim of this package is to offer a common set of useful classes that can also be preprocessed by optimized containers for best performance.

Usage
-----

[](#usage)

Simply require this package in your package declaring your service-provider:

**So far, the package has the thecodingmachine vendor name. It will hopefully be migrated to container-interop/common-factories**

```
composer require thecodingmachine/common-factories
```

Then, you can use one of the 3 available classes:

### Creating an alias

[](#creating-an-alias)

Use the `Alias` class to easily create an alias.

```
public function getFactories() {
    return [
        'myAlias' => new Alias('myService')
    ]
}
```

can easily replace:

```
public function getFactories() {
    return [
        'myAlias' => function(ContainerInterface $container) {
            return $container->get('myService');
        }
    ]
}
```

### Creating a parameter

[](#creating-a-parameter)

Use the `Parameter` class to put in the container a scalar (or array of scalar) entry:

```
public function getFactories() {
    return [
        'DB_HOST' => new Parameter('localhost')
    ]
}
```

can easily replace:

```
public function getFactories() {
    return [
        'DB_HOST' => function() {
            return 'localhost';
        }
    ]
}
```

### Appending a service to an array of services

[](#appending-a-service-to-an-array-of-services)

Use the `AddToArray` class to push a new service to an existing array:

```
public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => new AddToArray(MyTwigExtension::class)
    ]
}
```

can easily replace:

```
public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => function(ContainerInterface $container, array $extensions = []) {
            $extensions[] = $container->get(MyTwigExtension::class);
            return $extensions;
        }
    ]
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity51

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

Every ~274 days

Total

4

Last Release

2831d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-common-factories/health.svg)

```
[![Health](https://phpackages.com/badges/thecodingmachine-common-factories/health.svg)](https://phpackages.com/packages/thecodingmachine-common-factories)
```

###  Alternatives

[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/object-mapper

Provides a way to map an object to another object

34885.7k18](/packages/symfony-object-mapper)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)

PHPackages © 2026

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