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

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

vshf/php-config
===============

PHP configuration system to handle app settings

v1.0.5(3y ago)026MITPHPPHP &gt;=7.2.0

Since May 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/VonStroheim/vshf-config-manager)[ Packagist](https://packagist.org/packages/vshf/php-config)[ RSS](/packages/vshf-php-config/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

VSHF PHP Config Manager
-----------------------

[](#vshf-php-config-manager)

VSHF PHP Config Manager is a settings/configuration manager for PHP applications. It provides functionality to handle settings and resources with their properties.

Usage
-----

[](#usage)

To use the VSHF Config Manager, you need to instantiate the `Config` class:

```
$settings = new \VSHF\Config\Config();
```

You can also initialize it with settings:

```
$settings = new \VSHF\Config\Config([
   'setting1' =>'value1',
   'setting2' =>'value2'
]);
```

### Contexts

[](#contexts)

The default setting context is the *app* context. When initializing with settings, they will be added to this context.

You can hydrate different contexts later on:

```
$settings->hydrate(
    [
        'settingA' =>'valueA',
        'settingB' =>'valueB'
    ],
    'myContext'
);
```

This will create an internal settings tree with the following structure:

```
[
    'app' => [
        'setting1' =>'value1',
        'setting2' =>'value2'
    ],
    'myContext' =>[
        'settingA' =>'valueA',
        'settingB' =>'valueB'
    ]
]

```

### Resources and properties

[](#resources-and-properties)

In the case of having a collection of resources and their properties, where the properties can be considered as *settings* for each resource, you can use the Config Manager to handle them.

For example, if you have a collection of *services* with the *isPriced* property, you can observe the value of this property for different services.

```
[
    'service_1' => [
        'isPriced' => FALSE,
        ...
    ],
    'service_2' => [
        'isPriced' => TRUE,
        ...
    ],
    ...
]

```

To hydrate with a resource collection:

```
foreach ($collection as $itemId => $item) {
    $settings->hydrateResource(
        [
             'isPriced' => TRUE,
             // other properties
        ],
        'services', // Context
        $itemId // Resource ID
    );
}
```

Observers
---------

[](#observers)

Each setting must have its corresponding *Observer*, which implements the `ObserverInterface`. An observer can handle one or more settings.

To register an observer:

```
// In the main context:
$settings->registerObserver('settingId', MyObserver::class);

// In a custom context
$settings->registerObserver('settingId', MyObserver::class, 'myContext');

// Observing multiple settings with a single observer:
$settings->registerObserver('settingA', MyObserver::class);
$settings->registerObserver('settingB', MyObserver::class);
```

### Resource property observers

[](#resource-property-observers)

Similarly, each resource property must have its *PropertyObserver*, which implements the `PropertyObserverInterface`. An observer can handle one or more properties.

To register a PropertyObserver:

```
$settings->registerObserver('propertyId', MyPropertyObserver::class, 'services');

// Observing multiple properties with a single observer:
$settings->registerObserver('propertyA', MyPropertyObserver::class, 'services');
$settings->registerObserver('propertyB', MyPropertyObserver::class, 'services');
```

Get and save
------------

[](#get-and-save)

To retrieve a setting:

```
// From the main context:
$settings->get('settingA');

// From a custom context:
$settings->get('settingA', 'myContext');
```

To save a setting:

```
// In the main context:
$settings->save('settingA', 'newValue');

// In a custom context:
$settings->save('settingA', 'newValue', 'myContext');
```

### Resource properties

[](#resource-properties)

To retrieve a property of a given resource:

```
$settings->getProperty('propertyA', 'services', 'resourceId');
```

To save a property of a given resource:

```
$settings->saveProperty('propertyA', 'services', 'resourceId');
```

To retrieve a given resource with all its properties:

```
$settings->getResourceProperties('services', 'resourceId');
```

Setting dependencies
--------------------

[](#setting-dependencies)

A setting or a resource property can depend on one or more other settings, even from different contexts.

To set dependencies, the `dependencies()` method of the observer must return a *Dependency* object.

```
// Inside settingA's observer class
public static function dependencies(){
    $dependency = new \VSHF\Config\Dependency();
    $dependency
        ->on('settingB')
        ->beingEqualTo('certainValue')
        ;
    return $dependency;
}
```

In this example, if *settingB* is equal to *certainValue*, then *settingA* is properly returned. Otherwise, NULL is returned.

It's important to note that NULL should not be a default/proper setting value.

### Complex dependencies

[](#complex-dependencies)

Dependencies can be complex and involve logical operators such as *AND* and *OR*. You can construct complex dependencies using the *Dependency* object.

```
$dependency = new \VSHF\Config\Dependency();

// AND
$dependency
    ->on('settingB')
    ->beingEqualTo('certainValue')
    ->and('settingC')
    ->beingTruthy()
    ;

// OR
$dependency
    ->on('settingB')
    ->beingEqualTo('certainValue')
    ->or('settingC')
    ->beingTruthy()
    ;

//INVALID, triggers an error
$dependency
    ->on('settingB')
    ->beingEqualTo('certainValue')
    ->and('settingC')
    ->beingTruthy()
    ->or('settingD')
    ->beingFalsy()
    ;

/*
 * This is equal to:
 *      settingB === certainValue && (
 *          settingC || !settingD
 *      )
 */
$dependency
    ->on('settingB')
    ->beingEqualTo('certainValue')
    ->andGroup()
    ->on('settingC')
    ->beingTruthy()
    ->or('settingD')
    ->beingFalsy()
    ->endGroup()
    ;

/*
 * This is equal to:
 *      settingB === certainValue || (
 *          settingC && !settingD
 *      )
 */
$dependency
    ->on('settingB')
    ->beingEqualTo('certainValue')
    ->orGroup()
    ->on('settingC')
    ->beingTruthy()
    ->and('settingD')
    ->beingFalsy()
    ->endGroup()
    ;
```

License
-------

[](#license)

This project is open-source software licensed under the [MIT license](https://opensource.org/MIT)

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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 ~8 days

Total

6

Last Release

1114d ago

### Community

Maintainers

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

---

Top Contributors

[![VonStroheim](https://avatars.githubusercontent.com/u/29458049?v=4)](https://github.com/VonStroheim "VonStroheim (1 commits)")

---

Tags

phpconfigurationSettings

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[samrap/gestalt

Gestalt is a simple, elegant PHP package for managing your framework's configuration values.

163.6k3](/packages/samrap-gestalt)

PHPackages © 2026

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