PHPackages                             treehouselabs/model-config - 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. treehouselabs/model-config

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

treehouselabs/model-config
==========================

Library to configure enums in models

v1.2.0(10y ago)070.9k↓50%MITPHPPHP &gt;=5.5

Since Jun 23Pushed 4y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Model config
============

[](#model-config)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a5263bfa8ed177b2fa447e44ac3ab94eccdb48cd59a665f576bc1236a06aed11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74726565686f7573656c6162732f6d6f64656c2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/treehouselabs/model-config)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6a0a72275763492c305ea2068297b4dc02fc0b899081009829b04c1194c8ede1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f74726565686f7573656c6162732f6d6f64656c2d636f6e6669672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/treehouselabs/model-config)[![Coverage Status](https://camo.githubusercontent.com/f5f570f8a0c9ddee2bd77704df60915329fd5eb26986d26a202bd06f1f96bcef/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f74726565686f7573656c6162732f6d6f64656c2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/treehouselabs/model-config/code-structure)[![Quality Score](https://camo.githubusercontent.com/e7c7b5d15d2f6cb8d78ee591d91950205db276b9987ed8d56d7052a83bc31643/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f74726565686f7573656c6162732f6d6f64656c2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/treehouselabs/model-config)

This library contains functionality to configure your models with predefined configuration values, like enums. It also gives you a nice object-oriented way to handle these.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.5
- The stemmer extension:

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

[](#installation)

```
composer require treehouselabs/model-config
```

Usage
-----

[](#usage)

First, you need to define field configurations. Let's say you have a house model, with a type:

```
# Project\Model\Article

class House
{
    protected $type;
}
```

The available types are "house", "apartment" and "other". Now, we could introduce an `HouseType` entity, but that would mostly contain a name, and nothing more. This is where an enum comes in handy. Enums are classes that have constants pointing to available values. We can create an enum for our type like this:

```
# Project\Model\Config\Field\HouseType

use TreeHouse\Model\Config\Field\Enum;

class HouseType extends Enum
{
    const HOUSE     = 1;
    const APARTMENT = 2;
    const OTHER     = 3;
}
```

Now you can use these constants to set values and make it readable too:

```
$house = new House();
$house->setType(HouseType::APARTMENT);
```

### Multiple values

[](#multiple-values)

Enums can also be denoted as multivalued fields. For example, our house model could have some facilities:

```
# Project\Model\Config\Field\Facilities

use TreeHouse\Model\Config\Field\Enum;

class Facilities extends Enum
{
    const ELEVATOR        = 1;
    const ALARM           = 2;
    const AIRCONDITIONING = 3;
    const ROLLER_BLINDS   = 4;

    protected static $multiValued = true;
}
```

Notice how we defined this configuration to be multivalued. The enum itself doesn't do anything with this information. But it comes in useful in other places, which we'll talk about next.

Configuration
-------------

[](#configuration)

Now that we have a couple of configurations, we can bundle them in a config object. The config object uses the (lowercased) constant names mapped to their values. We can use a builder to do this:

```
$builder = new ConfigBuilder();
$builder->addField('type', HouseType::class);
$builder->addField('facilities', Facilities::class);

$config = $builder->getConfig();
```

The config object provides some convenience methods:

```
$config->isMultiValued('facilities'); // true
$config->hasFieldConfig('foo'); // false
$config->hasFieldConfigKey('type', 2); // true
$config->hasFieldConfigValue('type', 'apartment'); // true
$config->getFieldConfigValueByKey('type', 2); // 'apartment'
$config->getFieldConfigKey('type', 'apartment'); // 2
```

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Credits
-------

[](#credits)

- [Peter Kruithof](https://github.com/treehouselabs)
- [All Contributors](../../contributors)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~285 days

Total

3

Last Release

3776d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/49e70c4936c5121b835d48680dcf4bb57d21724c533dd99591e80101e4a25dd6?d=identicon)[pkruithof](/maintainers/pkruithof)

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

---

Top Contributors

[![pkruithof](https://avatars.githubusercontent.com/u/330828?v=4)](https://github.com/pkruithof "pkruithof (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

configmodel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/treehouselabs-model-config/health.svg)

```
[![Health](https://phpackages.com/badges/treehouselabs-model-config/health.svg)](https://phpackages.com/packages/treehouselabs-model-config)
```

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[mpociot/reanimate

Undo Laravel soft deletes

1221.2k](/packages/mpociot-reanimate)[raoul2000/yii-simple-workflow

A simple workflow engine for Yii 1

278.2k](/packages/raoul2000-yii-simple-workflow)

PHPackages © 2026

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