PHPackages                             phly/phly-configfactory - 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. phly/phly-configfactory

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

phly/phly-configfactory
=======================

Factory for pulling nested configuration arrays from the config service

1.4.0(1y ago)321.1k[1 PRs](https://github.com/phly/phly-configfactory/pulls)1BSD-3-ClausePHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0CI passing

Since Jan 14Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/phly/phly-configfactory)[ Packagist](https://packagist.org/packages/phly/phly-configfactory)[ RSS](/packages/phly-phly-configfactory/feed)WikiDiscussions 1.4.x Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (12)Used By (1)

phly-configfactory
==================

[](#phly-configfactory)

[![Build Status](https://camo.githubusercontent.com/83638b02ccb1593e3705328b24a4962d83151c3975ff0fcf6d3f75f43538fc4a/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f70686c792f70686c792d636f6e666967666163746f72792e7376673f6272616e63683d6d6173746572)](https://secure.travis-ci.org/phly/phly-configfactory)[![Coverage Status](https://camo.githubusercontent.com/7cb01d19a4d679bc55890e82753165cbc74d484634d060bf2cc797099feb3ece/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70686c792f70686c792d636f6e666967666163746f72792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/phly/phly-configfactory?branch=master)

This library provides a re-usable factory for pulling configuration from nested keys.

> This library was previously released as [phly/phly-expressive-configfactory](https://github.com/phly/phly-expressive-configfactory). This version is a fork, modified to support [Laminas](https://getlaminas.org).

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

[](#installation)

Run the following to install this library:

```
$ composer require phly/phly-configfactory
```

Usage
-----

[](#usage)

Assign the factory `Phly\ConfigFactory\ConfigFactory` to services named with the following structure:

```
config-

```

As an example, if you have the following structure:

```
return [
    'cache' => [
        'adapters' => [
            'blog' => [
                'connection' => 'tcp://localhost:6349',
                'username'   => 'www-data',
                'prefix'     => 'blog',
            ],
        ],
    ],
];
```

and you wanted the "blog" adapter configuration, you would assign the dependency as follows:

```
return [
    'dependencies' => [
        'factories' => [
            'config-cache.adapters.blog' => \Phly\ConfigFactory\ConfigFactory,
        ],
    ],
];
```

### Return empty or raise exception

[](#return-empty-or-raise-exception)

By default, if no configuration at the expected key is found, the factory returns an empty array. If you want it to instead raise an exception, you can assign the factory as follows:

```
return [
    'dependencies' => [
        'factories' => [
            'config-cache.adapters.blog' => new \Phly\ConfigFactory\ConfigFactory(false),
        ],
    ],
];
```

> This operation is safe, as `ConfigFactory` implements `__set_state()`, allowing it to be serialized safely with `var_export()`.

The exception will indicate the key hierarchy it was attempting to retrieve.

### Using configuration in factories

[](#using-configuration-in-factories)

In your factories, you will refer to the metaname when retrieving the service. Following our example above:

```
use Psr\Container\ContainerInterface;

class BlogCacheFactory
{
    public function __invoke(ContainerInterface $container)
    {
        return new Cache($container->get('config-cache.adapters.blog'));
    }
}
```

### Abstract Factory

[](#abstract-factory)

If you are using [laminas-servicemanager](https://docs.laminas.dev/laminas-servicemanager), you can use the class `Phly\ConfigFactory\ConfigAbstractFactory` as an abstract factory. This allows you to omit adding a factory entry for every configuration segment you want to retrieve. Instead, you can add the following:

```
return [
    'dependencies' => [
        'abstract_factories' => [
            \Phly\ConfigFactory\ConfigAbstractFactory::class,

            // OR

            new \Phly\ConfigFactory\ConfigAbstractFactory(false),
        ],
    ],
];
```

When present, it will handle any services with the prefix `config-`, and operate in the same way as the `ConfigFactory`.

### Caveats

[](#caveats)

You should only specify keys that will return an array. Most containers only allow returning an array or object from factories, and will raise an exception otherwise. For those requiring an object, Mezzio generally casts to an `ArrayObject` instance, making this safe.

Support
-------

[](#support)

- [Issues](https://github.com/phly/phly-configfactory/issues/)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance61

Regular maintenance activity

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97.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 ~197 days

Recently: every ~157 days

Total

10

Last Release

539d ago

PHP version history (5 changes)1.0.0PHP ^7.1

1.1.0PHP ^7.3 || ~8.0.0 || ~8.1.0

1.2.0PHP ~8.0.0 || ~8.1.0 || ~8.2.0

1.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

1.4.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25943?v=4)[Matthew Weier O'Phinney](/maintainers/weierophinney)[@weierophinney](https://github.com/weierophinney)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (34 commits)")[![mkherlakian](https://avatars.githubusercontent.com/u/1141190?v=4)](https://github.com/mkherlakian "mkherlakian (1 commits)")

---

Tags

PSR-11configmezzioexpressive

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phly-phly-configfactory/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[laminas/laminas-servicemanager

Factory-Driven Dependency Injection Container

15955.1M694](/packages/laminas-laminas-servicemanager)[elie29/zend-phpdi-config

PSR-11 PHP-DI autowire container configurator for Laminas, Mezzio, ZF2, ZF3 and Zend Expressive applications

20238.6k7](/packages/elie29-zend-phpdi-config)

PHPackages © 2026

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