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

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

samsonphp/config
================

SamsonPHP configuration system

1.0.11(11y ago)37.3k2Open Software License (OSL) v 3.0PHP

Since Jan 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SamsonPHP/config)[ Packagist](https://packagist.org/packages/samsonphp/config)[ Docs](http://samsonos.com/)[ RSS](/packages/samsonphp-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (12)Used By (2)

SamsonPHP Configuration system
==============================

[](#samsonphp-configuration-system)

[![Latest Stable Version](https://camo.githubusercontent.com/b4fa236d55cbcb7cc9f225ee753a2de52dde063894f3e06c8bd2f3b327f44267/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f636f6e6669672f762f737461626c652e737667)](https://packagist.org/packages/samsonphp/config)[![Build Status](https://camo.githubusercontent.com/c64fe90bc01c93e2f5ef71ecc554bf009e91600df8617e60dd7488c67ad7622e/68747470733a2f2f7472617669732d63692e6f72672f73616d736f6e7068702f636f6e6669672e706e67)](https://travis-ci.org/samsonphp/config)[![Code Coverage](https://camo.githubusercontent.com/085cdb3574fafdb87cb0f961a659261c0aa9fde63c4bf7da444f370502ded155/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f636f6e6669672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/config/?branch=master)[![Code Climate](https://camo.githubusercontent.com/dd9ebba8397bf72ede375083e8eaafec77cce85f1ba574b03387b4bdcd5d3c1d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73616d736f6e7068702f636f6e6669672f6261646765732f6770612e737667)](https://codeclimate.com/github/samsonphp/config)[![Total Downloads](https://camo.githubusercontent.com/c4925a90351bd56db64b7bf6b505dbbce4cd95a1c1a1b0f2759bab6f6429fb5a/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f636f6e6669672f646f776e6c6f6164732e737667)](https://packagist.org/packages/samsonphp/config)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/79a2ded52d1908e067a49d35069a1e55b4017bff5749a7f3c3848b7d6ab48038/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/config/?branch=master)[![Stories in Ready](https://camo.githubusercontent.com/fd850d6ac7e1783c0f58edcfb7b328e0661904f459e46158b49296e1735e10f3/68747470733a2f2f62616467652e776166666c652e696f2f73616d736f6e7068702f636f6e6669672e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/samsonphp/config)

OOP based configuration system. This approach uses all abilities of PHP OOP for creating configurations based on classes.

Configuration scheme
--------------------

[](#configuration-scheme)

Your project can have any amount of possible configurations, which is usually used for different environments, such as *development, test, deploy, production* stages, for this purposes we have created `Scheme`, each of them corresponds to specific environment. In practice you should have *base configuration folder*, by default it is located at `app/config` folder.

### Global configuration

[](#global-configuration)

In root of your `app/config` folder you should create your default [entity configuration classes](#entity-configuration). If no current configuration environment would be specified, this entity configuration classes would be used automatically.

> IMPORTANT! If you have specified some configuration environment(for example `production`) but you do not have entity configuration class for some module/object in it - Global configuration entity will be used for it instead if present.

### Creating configuration environment

[](#creating-configuration-environment)

To create new configuration environment you should create new folder in your *base configuration folder*(by default it located at `app/config`), for example we want to create `production` environment, new folder path would be: `app/config/production/`. And all entity configuration classes there would correspond to your `production` configuration scheme, which will be created automatically.

Entity configuration
--------------------

[](#entity-configuration)

To configure your project modules\\objects - you should use classes, for correct finding this classes among others, we force you to extend our base entity configuration class `Entity` :

```
namespace project;

class entityIDConfig extends samsonphp\config\Entity
{
}
```

Your entity configuration class name should meet next logic: `[EntityIdentifier]Config`:

- `EntityIdentifier` - configured module/object identifier
- All entity configuration class names must end with `Config`

Your entity configuration class namespace should meet next logic:

- Every class has to have any namespace defined(by default your project name)
- Global entity configuration classes(located at [base configuration folder](#configuration-scheme)), should have name space defined in previous list item.
- Other environments entity configuration classes (located at [other inner folders](#creating-configuration-environment)), should have namespace: `[ParentNamespace]\[EnvironmentName]`, if we extend our previous entity configuration example, but now for `production` environment:

```
namespace project\production;

class entityIDConfig extends samsonphp\config\Entity
{
    public $parameter = 'value';
}
```

> IMPORTANT! As we use PSR-\* standard - Class name must match file name

### Possible configuration parameters

[](#possible-configuration-parameters)

The main beauty of OOP configuration approach is that you can specify any possible by PHP values as predefined class field values, the main limitation is that they have to be `public` accessible:

```
namespace project;

class entityIDConfig extends samsonphp\config\Entity
{
    public $stringParameter = 'I am a string';
    public $integerParameter = 1123;
    public $arrayParameter = array('1', 123);
}
```

### Prohibited operations

[](#prohibited-operations)

Unfortunately you cannot predefine calculations and string concatenations(and perform other operations) in class field values, but you can always perform it in `__construct` method. When [configuration scheme](#configuration-scheme) is created, for every environment all [entity configuration](#entity-configuration) instances are being created - so their `__construct` method is performed, where you can make any possible operation.

```
namespace project;

class entityIDConfig extends samsonphp\config\Entity
{
    public $stringParameter = 'I am a string';
    public $integerParameter = 1123;
    public $arrayParameter = array('1', 123);
    public $complicatedParameter;

    public function __construct()
    {
        // Fill your parameter with what you want
        $this->complicatedParameter = $this->stringParameter . dirname(__DIR__);
    }
}
```

### Extending existing configurations

[](#extending-existing-configurations)

Also extending parent entity configuration is available, if want to add just some little changes to some entity configuration we can just extend it:

```
// Mention - class name is the same, only namespace is different
namespace project\other;

// We are extending global configuration from previous example
class entityIDConfig extends project\entityIDConfig
{
  // We overload only this parameter, as we want all to be the same as parent
  public $integerParameter = 2222;
}
```

Configuration manager
---------------------

[](#configuration-manager)

All project modules/objects configuration is processed via configuration manager `samsonphp\config\Manager`, you must create instance of it, you must specify only one parameter `Path to base configuration folder`, for initialization of manager you should use `init()` method, this methods are specially separated to give ability to load entity configuration classes as you wish.

```
$manager = new \samsonphp\config\Manager('.../path/to/base/folder');
$manager->init();
```

### Loading entity configuration classes

[](#loading-entity-configuration-classes)

We have created special static method for loading entity configuration `samsonphp\config\Manager::import($path)`, this method is used internally when configuration scheme is being created or loaded, for this tasks you should use `init(path)`:

```
$manager = new \samsonphp\config\Manager();
$manager->init('.../path/to/base/folder');
```

### Switching configuration

[](#switching-configuration)

If you want to change current active manager configuration use should use `change($identifier)` method:

- `$identifier` - Environment identifier(Configuration scheme identifier)
-

### Load schemes from different locations

[](#load-schemes-from-different-locations)

If you have separate base configuration folders with different configurations, for example one project inside another, and inner project want to take some configurations from parent object, you can load configuration from other location:

```
$manager = new \samsonphp\config\Manager();
$manager->init('.../path/to/base/folder');
$manager->init('.../path/to/OTHER/folder');
```

> IMPORTANT! Entity configuration for same environments in different locations are ovveritten.

Event system
============

[](#event-system)

This module has only one external dependency - [Event system](https://github.com/samsonos/php_event) and all interoperabily with outside world must me done using this approach. Currently module does not firing any events, but has 2 subscriptions:

- `core.environment.change` - When environment is changing outside
- `core.module.configure` - When some object is being configured

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 98.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 ~1 days

Total

11

Last Release

4143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6510135856527278a1da14ea26ecaa3f016c27604236cec14ee550a8441dec52?d=identicon)[samsonphp](/maintainers/samsonphp)

---

Top Contributors

[![vitalyiegorov](https://avatars.githubusercontent.com/u/586558?v=4)](https://github.com/vitalyiegorov "vitalyiegorov (93 commits)")[![rmolodyko](https://avatars.githubusercontent.com/u/4399482?v=4)](https://github.com/rmolodyko "rmolodyko (1 commits)")

---

Tags

file systemsamsonphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sebastianfeldmann/camino

Path management the OO way

176.4M1](/packages/sebastianfeldmann-camino)

PHPackages © 2026

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