monkeyscloud / monkeyslegion-mlc
`.mlc` MonkeysLegion Config format parser & loader
dev-main / 1.0.x-dev
2025-06-16 01:47 UTC
Requires
- php: ^8.4
- vlucas/phpdotenv: ^5.6
This package is auto-updated.
Last update: 2025-06-16 01:47:22 UTC
README
.mlc
is MonkeysLegion’s simple, dot-notation config format with first-class support for layered .env
files.
Features
- Nested keys via
.
(e.g.db.host
,cache.redis.timeout
) - Type-aware values: strings, ints, floats, booleans, null
env()
helper—pull in environment variables with optional defaults- Merge multiple files in load order, later files override earlier ones
- Layered
.env
support:.env
.env.local
.env.{APP_ENV}
.env.{APP_ENV}.local
- Zero-magic: only requires PHP 8.4+ and
vlucas/phpdotenv
Installation
composer require monkeyscloud/monkeyslegion-mlc
Quick Start
- Create your .mlc files in config/:
# config/app.mlc app.name = "MyApp" app.debug = true features.signup = env("ENABLE_SIGNUP", true)
# config/database.mlc connections.mysql.dsn = env("DB_DSN", "mysql:host=127.0.0.1;dbname=myapp") connections.mysql.username = env("DB_USER", "root") connections.mysql.password = env("DB_PASS", null)
- Bootstrap the loader (e.g. in your DI container):
use MonkeysLegion\Mlc\Parser; use MonkeysLegion\Mlc\Loader; $parser = new Parser(); $loader = new Loader( $parser, base_path('config'), // your config directory base_path() // optional .env directory (defaults to config/) ); // Load & merge `app.mlc` + `database.mlc` $config = $loader->load(['app', 'database']);
- Retrieve values:
$appName = $config->get('app.name', 'Unknown'); $debugMode = $config->get('app.debug', false); $dsn = $config->get('connections.mysql.dsn');
.mlc Syntax
Each line is a key/value pair. Keys use dot-notation for nesting. Values support:
- Strings: either unquoted (foo) or quoted ("foo", 'foo')
- Numbers: integers (42) or floats (3.14)
- Booleans: true / false
- Null: null
- Env helper: env("KEY") or env("KEY", "default")
Example:
service.timeout = 30 service.endpoint = "https://api.example.com" feature.enabled = false logging.level = env("LOG_LEVEL", "info")
Layered .env Loading
By default, Loader will call vlucas/phpdotenv to load:
- .env
- .env.local
- .env.{APP_ENV} (where APP_ENV = $_ENV['APP_ENV'] ?? 'dev')
- .env.{APP_ENV}.local
Later files override earlier ones. This keeps 12-factor best practices while allowing per-environment overrides.
Advanced Usage
- Custom .env directory: pass a different $envDir when constructing Loader.
- Manual parsing: use Parser directly to transform a single .mlc file into an array.
- Inspect all data:
$all = $config->toArray(); // get the full merged config as an array
Contributing
- Fork the repo
- Create your feature branch (git checkout -b feat/foo)
- Commit your changes (git commit -m 'feat: add foo')
- Push to the branch (git push origin feat/foo)
- Open a Pull Request
Please follow PSR-12 and include tests for any new features.
License
Released under the MIT License. See LICENSE for details.