PHPackages                             monkeyscloud/monkeyslegion-mlc - 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. [Caching](/categories/caching)
4. /
5. monkeyscloud/monkeyslegion-mlc

ActiveLibrary[Caching](/categories/caching)

monkeyscloud/monkeyslegion-mlc
==============================

`.mlc` MonkeysLegion Config format parser &amp; loader - Production-ready configuration management

3.2.5(2mo ago)22.0k↓31.5%8MITPHPPHP ^8.4

Since Jul 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/MonkeysCloud/MonkeysLegion-Mlc)[ Packagist](https://packagist.org/packages/monkeyscloud/monkeyslegion-mlc)[ RSS](/packages/monkeyscloud-monkeyslegion-mlc/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (10)Versions (16)Used By (8)

MonkeysLegion MLC - Configuration Engine
========================================

[](#monkeyslegion-mlc---configuration-engine)

Production-grade `.mlc` configuration engine for PHP 8.4+. High-performance, zero-overhead, and enterprise-secure.

[![PHP Version](https://camo.githubusercontent.com/47e73f07f108dceadfcac76ece08c56f760cbf43a8798f7f396a099a845d0879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e342d3838393262662e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

🚀 Why MLC?
----------

[](#-why-mlc)

MLC is designed for one core task: **parse once, serve from bytecode forever**. It moves configuration beyond simple file loading into a high-performance system for modern PHP environments (RoadRunner, Swoole, or standard FPM).

- ⚡ **Zero-Overhead Production Mode**: Compiles MLC to static PHP arrays for OPcache optimization.
- 🌍 **Deep Environment Integration**: Native `${VAR:-default}` expansion powered by `monkeyslegion-env`.
- 🔒 **Enterprise Security**: Strict permission auditing, path traversal hardening, and circular reference detection.
- 🎯 **Type-Safe DX**: Typed getters (`getString`, `getInt`, etc.) and a dual-layer mutation engine.
- 🪝 **Event-Driven**: Lifecycle hooks (`onLoading`, `onLoaded`) with type-safe enums and proxies.
- 📂 **Multi-Format Support**: Native support for `.mlc`, `.json`, `.yaml`, and `.php` arrays via a composite system.

📦 Installation
--------------

[](#-installation)

```
composer require monkeyscloud/monkeyslegion-mlc
```

🛠️ Basic Usage
--------------

[](#️-basic-usage)

### Loading Configuration (Production-Ready)

[](#loading-configuration-production-ready)

To use the full power of MLC, you need to initialize the environment bootstrapper and the parser.

```
use MonkeysLegion\Mlc\Loader;
use MonkeysLegion\Mlc\Parsers\MlcParser;
use MonkeysLegion\Env\EnvManager;
use MonkeysLegion\Env\Loaders\DotenvLoader;
use MonkeysLegion\Env\Repositories\NativeEnvRepository;

// 1. Initialize environment (MonkeysLegion-Env)
$bootstrapper = new EnvManager(new DotenvLoader(), new NativeEnvRepository());

// 2. Initialize MlcParser with the bootstrapper
$parser = new MlcParser($bootstrapper, $rootPath);

// 3. Initialize Loader
$loader = new Loader(
    parser: $parser,
    baseDir: __DIR__ . '/config'
);

// 4. Load and merge files
$config = $loader->load(['app', 'database']);
```

### Accessing Values

[](#accessing-values)

```
// Type-safe getters
$port  = $config->getInt('database.port', 3306);
$debug = $config->getBool('app.debug', false);
$name  = $config->getString('app.name');

// Dot-notation access
$dbHost = $config->get('database.host', 'localhost');

// Required values (throws if missing)
$secret = $config->getRequired('app.secret');
```

⚡ Zero-Overhead Mode (OPcache)
------------------------------

[](#-zero-overhead-mode-opcache)

In production, use the `CompiledPhpCache` to export your configuration to a static PHP file. This allows OPcache to store the configuration in shared memory.

```
use MonkeysLegion\Mlc\Cache\CompiledPhpCache;

$cache  = new CompiledPhpCache('/var/cache/mlc');
$loader = new Loader($parser, $baseDir, cache: $cache);

// Warm-up cache (run during deployment)
$loader->compile(['app', 'database']);

// Future loads are now instant (bytecode read)
$config = $loader->load(['app', 'database']);
```

🔄 Dual-Layer Overrides
----------------------

[](#-dual-layer-overrides)

Apply non-destructive runtime overrides without touching the compiled base. Perfect for feature flags or multi-tenancy.

```
$config->override('app.debug', true);
$config->get('app.debug'); // true

// Export base ONLY (overrides excluded)
$baseData = $config->all();

// Flatten base + overrides into a fresh isolated instance
$isolated = $config->snapshot();
```

🪝 Component Extensions
----------------------

[](#-component-extensions)

The `Loader` emits lifecycle events that you can hook into for logging or metrics.

```
$loader->onLoading(fn($names) => logger()->info("Loading configs: " . implode(',', $names)));
$loader->onLoaded(fn($config) => logger()->info("Config ready"));
```

📂 Multi-Format Support
----------------------

[](#-multi-format-support)

Use the `CompositeParser` to mix and match different configuration formats.

```
use MonkeysLegion\Mlc\Parsers\CompositeParser;
use MonkeysLegion\Mlc\Parsers\JsonParser;
use MonkeysLegion\Mlc\Parsers\YamlParser;

$composite = new CompositeParser($mlcParser);
$composite->registerParser('json', new JsonParser());
$composite->registerParser('yaml', new YamlParser());

$loader = new Loader($composite, $baseDir);
// Automatically selects parser based on file extension (.mlc, .json, .yaml)
```

📝 MLC Syntax at a Glance
------------------------

[](#-mlc-syntax-at-a-glance)

MLC provides a developer-friendly syntax that combines the best of INI, JSON, and PHP.

```
# This is a comment
app_name = "MonkeysCloud"
debug    true
port     8080

# Sections (Nesting)
database {
    host = localhost

    # Environment expansion with fallback
    pass = ${DB_PASSWORD:-secret}

    # PHP-style arrays (Single or Double quotes)
    users = ['admin', 'manager', "guest"]
}

# Recursively include other files
@include "env/local.mlc"

```

Tip

Visit [SYNTAX.md](SYNTAX.md) for the full language specification.

🛡️ Security Features
--------------------

[](#️-security-features)

- **Path Traversal Prevention**: Strict validation of all relative paths.
- **Permission Auditing**: In-depth check for world-writable files in production.
- **Strict Mode**: `strictSecurity: true` throws exceptions instead of warnings for insecure files.
- **Reference Tracking**: Prevents circular key references and infinite inclusion loops.

🛠️ CLI Tool (`mlc-check`)
-------------------------

[](#️-cli-tool-mlc-check)

Validate your configuration files for syntax, security, and integrity from the terminal.

```
php bin/mlc-check ./config
```

📚 Documentation
---------------

[](#-documentation)

- [MLC Syntax Reference](SYNTAX.md)
- [Full Developer Documentation](documentation.md)
- [Multi-Format Support Guide](multi_format_support.md)
- [Upgrading to v3.0.0](UPGRADE.md)

🧪 Testing
---------

[](#-testing)

```
composer test    # Run PHPUnit suite
composer stan    # Run static analysis (Level 9)
composer ci      # Run full quality pipeline
```

📜 License
---------

[](#-license)

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

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance86

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 65% 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 ~21 days

Recently: every ~1 days

Total

14

Last Release

71d ago

Major Versions

1.0.0 → 2.0.x-dev2025-12-14

2.0.0 → v3.x-dev2026-04-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2913369?v=4)[Jorge Peraza](/maintainers/yorchperaza)[@yorchperaza](https://github.com/yorchperaza)

---

Top Contributors

[![Amanar-Marouane](https://avatars.githubusercontent.com/u/155680356?v=4)](https://github.com/Amanar-Marouane "Amanar-Marouane (26 commits)")[![yorchperaza](https://avatars.githubusercontent.com/u/2913369?v=4)](https://github.com/yorchperaza "yorchperaza (14 commits)")

---

Tags

configurationconfigparsercachemonkeyslegionmlc

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/monkeyscloud-monkeyslegion-mlc/health.svg)

```
[![Health](https://phpackages.com/badges/monkeyscloud-monkeyslegion-mlc/health.svg)](https://phpackages.com/packages/monkeyscloud-monkeyslegion-mlc)
```

###  Alternatives

[corneltek/configkit

Fast config toolkit, which provides super lightweight config accessor and loader.

1314.2k8](/packages/corneltek-configkit)

PHPackages © 2026

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