PHPackages                             microlib/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. microlib/config

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

microlib/config
===============

A small, PHP, configuration library consisting mostly of functions.

0.1.1(11y ago)1564[1 issues](https://github.com/jeremeamia/microlib-config/issues)MITPHPPHP &gt;=5.4.0

Since Sep 2Pushed 11y ago3 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

MicroLib — Config
=================

[](#microlib--config)

A small, PHP, configuration library consisting mostly of functions. Yep, *functions*, because working with configuration arrays should be simple and fast.

Features
--------

[](#features)

- Small library. No bloat. Easy-to-use functions.
- Supports PHP array, JSON, INI, YAML, and XML config file formats.
- Easy to apply defaults, enforce required settings, and filter out extraneous data.
- Can specify a schema to recursively validate the data. Uses callables for validations and transformations.
- Easily fetch values from nested config structure.

Usage
-----

[](#usage)

### Validating Against a Schema

[](#validating-against-a-schema)

Let's say you have a config file that looks like this:

```
{
    "first_name": "Jeremy ",
    "last_name": "Lindblom",
    "phone": {"number": "5559997777"},
    "gender": "whocares"
}
```

In your PHP script…

Include the Config library.

```
require '/path/to/vendor/autoload.php';

use MicroLib\Config as cfg;
```

Load the config file.

```
$config = cfg\load('config.json');
```

Define a schema for the data. Using the `schema` function is optional but is useful for validating that the schema is defined correctly. (Note: The schema can be placed in a separate file and loaded with the `load` function like other config data.)

```
$schema = cfg\schema([
    'first_name' => [
        'required'  => true,
        'transform' => 'trim',
        'validate'  => 'ctype_alpha'
    ],
    'last_name' => [
        'required'  => true,
        'transform' => 'trim',
        'validate'  => 'ctype_alpha'
    ],
    'phone' => [
        'schema' => [
             'type' => [
                 'default'   => 'mobile',
                 'transform' => 'trim',
                 'validate'  => 'ctype_alpha',
             ],
             'number' => [
                 'required' => true,
                 'validate' => 'ctype_digit',
             ]
        ]
    ],
]);
```

Validate the configuration data with the schema. If no exception is thrown, then the data is valid.

```
$config = cfg\validate($config, $schema);
```

Fetch data from the config using `get`.

```
echo cfg\get($config, 'phone.number');
#> 5559997777

echo cfg\get($config, 'phone.type');
#> mobile
```

### Simple Check for Required Keys

[](#simple-check-for-required-keys)

If you don't need the functionality of the schemas, there is still an easy way to enforce required settings and apply default values.

Let's say you have the following array of configuration data:

```
$config = [
    'class'  => 'rogue',
    'race'   => 'half-elf',
    'level'  => 5,
    'weapon' => 'short sword',
];
```

If you aren't concerned about all of the items, you can use the `keep`function to create a new array of only the items you want.

```
$config = cfg\keep($config, ['class', 'race', 'level']);
```

Then, using the `create` function, you can check requirements and apply defaults.

```
$config = cfg\create(
	$config,
	['class', 'race', 'level'],
	['status' => 'normal']
);

print_r($config);
#> Array
#> (
#>     [class] => rogue
#>     [race] => half-elf
#>     [level] => 5
#>     [status] => normal
#> )
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

4260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/184fbc398ff1b83855ab8289cd8ce20225d0158c66284b458d2d811546606938?d=identicon)[jeremeamia](/maintainers/jeremeamia)

---

Top Contributors

[![jeremeamia](https://avatars.githubusercontent.com/u/107867?v=4)](https://github.com/jeremeamia "jeremeamia (6 commits)")

---

Tags

schemavalidationconfigmicrofunctionconfigurations

### Embed Badge

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

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

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[romaricdrigon/metayaml

Using \[Yaml|Xml|json\] schemas files to validate \[Yaml|Xml|json\]

103306.5k8](/packages/romaricdrigon-metayaml)[evaisse/php-json-schema-generator

A JSON Schema Generator.

20298.5k1](/packages/evaisse-php-json-schema-generator)[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

288.2k](/packages/romegasoftware-laravel-schema-generator)

PHPackages © 2026

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