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

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

concept-labs/config
===================

(C)oncept-Labs Config Manager

2.2.7(3mo ago)01888MITPHPPHP &gt;=8.2

Since Dec 29Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Concept-Labs/config)[ Packagist](https://packagist.org/packages/concept-labs/config)[ RSS](/packages/concept-labs-config/feed)WikiDiscussions main Synced 1mo ago

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

Concept/Config
==============

[](#conceptconfig)

A powerful, flexible, and extensible configuration management library for PHP 8.2+.

PHP &gt;= 8.2 | License: MIT | Part of the [Concept Labs](https://github.com/Concept-Labs) ecosystem

Features
--------

[](#features)

- **Dot Notation Access**: Access nested configuration values using intuitive dot notation
- **Multiple Format Support**: JSON, PHP arrays, and extensible to YAML, INI, etc.
- **Plugin System**: Extensible plugin architecture for custom processing
- **Variable Interpolation**: Support for environment variables, references, and context values
- **Import/Include System**: Modular configuration with file imports
- **Context Management**: Flexible context for runtime variable resolution
- **Lazy Resolution**: Efficient lazy evaluation of configuration values
- **Factory Pattern**: Dependency injection support with custom factories
- **SOLID Principles**: Clean architecture following best practices
- **Facade Interface**: Simplified configuration creation with pre-configured plugins
- **Type Safe**: Full PHP 8.2+ type hints and strict typing
- **100% Backward Compatible**: All improvements maintain existing API

Architecture
------------

[](#architecture)

Built with **SOLID principles** in mind:

- **S**ingle Responsibility: Each class has one clear purpose
- **O**pen/Closed: Extensible through factories and plugins without modification
- **L**iskov Substitution: Any factory can replace defaults
- **I**nterface Segregation: Focused interfaces, no fat interfaces
- **D**ependency Inversion: Depends on abstractions, not concrete classes

### Dependency Injection

[](#dependency-injection)

Customize components through optional factory injection:

```
use Concept\Config\Config;
use Concept\Config\Factory\DefaultStorageFactory;
use Concept\Config\Factory\DefaultResourceFactory;
use Concept\Config\Factory\DefaultParserFactory;

// Use custom factories for complete control
$config = new Config(
    data: ['app' => 'MyApp'],
    context: ['env' => 'production'],
    storageFactory: new CustomStorageFactory(),
    resourceFactory: new CustomResourceFactory(),
    parserFactory: new CustomParserFactory()
);

// Or use defaults - factories are optional
$config = new Config(['app' => 'MyApp']);
```

Installation
------------

[](#installation)

Install via Composer:

```
composer require concept-labs/config
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Concept\Config\Config;

// Create a config instance with inline data
$config = new Config([
    'app' => [
        'name' => 'MyApp',
        'debug' => true,
        'version' => '1.0.0'
    ],
    'database' => [
        'host' => 'localhost',
        'port' => 3306
    ]
]);

// Access values using dot notation
echo $config->get('app.name');        // "MyApp"
echo $config->get('database.host');   // "localhost"

// Set values
$config->set('app.version', '2.0.0');

// Check if a key exists
if ($config->has('app.debug')) {
    // ...
}
```

### Loading from Files

[](#loading-from-files)

```
use Concept\Config\Facade\Config;

// Use the Facade for fully-featured configuration with all plugins pre-configured
$config = Config::config('config/app.json', context: [
    'ENV' => getenv()
]);

// Or use the direct class
use Concept\Config\Config;

// Load from a JSON file
$config = new Config();
$config->load('config/app.json', parse: true);

// Or use the static factory
use Concept\Config\StaticFactory;

$config = StaticFactory::fromFile('config/app.json', parse: true);
```

### Using Context and Variables

[](#using-context-and-variables)

```
// Create config with environment variable support
$config = new Config([
    'database' => [
        'host' => '@env(DB_HOST)',
        'user' => '@env(DB_USER)',
        'password' => '@env(DB_PASSWORD)'
    ]
], context: [
    'ENV' => getenv()
]);

// Parse to resolve variables
$config->getParser()->parse($config->dataReference());
```

Documentation
-------------

[](#documentation)

Comprehensive documentation is available in the [docs](./docs) directory:

- [Getting Started](./docs/getting-started.md) - Installation and basic usage
- [Architecture](./docs/architecture.md) - System architecture and design
- [Configuration Guide](./docs/configuration.md) - Configuration methods and options
- [Plugin System](./docs/plugins.md) - Understanding and creating plugins
- [Adapters](./docs/adapters.md) - File format adapters
- [Context &amp; Variables](./docs/context.md) - Variable resolution and context management
- [API Reference](./docs/api-reference.md) - Complete API documentation
- [Examples](./docs/examples.md) - Practical examples and use cases
- [Advanced Topics](./docs/advanced.md) - Custom plugins, adapters, and factories

Key Concepts
------------

[](#key-concepts)

### Dot Notation

[](#dot-notation)

Access nested configuration values using familiar dot notation:

```
$config->get('database.connection.host');
$config->set('cache.drivers.redis.port', 6379);
```

### Plugin System

[](#plugin-system)

Extend functionality through plugins:

```
// Environment variables
'@env(DB_HOST)'

// Config references
'@database.host'

// Custom plugins
$config->getParser()->registerPlugin(MyCustomPlugin::class, priority: 100);
```

### Factories

[](#factories)

Multiple ways to create configurations:

```
// Facade - Simplified interface with pre-configured plugins
use Concept\Config\Facade\Config;

$config = Config::config('config/*.json', context: [
    'env' => 'production',
    'ENV' => getenv()
]);

// Static factory
use Concept\Config\StaticFactory;

$config = StaticFactory::create(['key' => 'value']);
$config = StaticFactory::fromFile('config.json');
$config = StaticFactory::fromGlob('config/*.json');

// Builder factory
use Concept\Config\Factory;

$config = (new Factory())
    ->withFile('config/app.json')
    ->withFile('config/database.json')
    ->withContext(['env' => 'production'])
    ->create();
```

### The Facade Interface

[](#the-facade-interface)

The `Concept\Config\Facade\Config` class provides a simplified, opinionated way to create configurations with all essential plugins pre-configured and ready to use.

```
use Concept\Config\Facade\Config;

// Create config from file(s) with all plugins enabled
$config = Config::config(
    source: 'config/*.json',           // File path or glob pattern
    context: ['env' => 'production'],  // Optional context variables
    overrides: ['debug' => false]      // Optional configuration overrides
);

// The facade automatically configures these plugins in priority order:
// - EnvPlugin (999): @env(VAR_NAME) - Environment variables
// - ContextPlugin (998): ${context.key} - Context values
// - IncludePlugin (997): @include(file) - Include external files
// - ImportPlugin (996): @import directive - Import and merge configs
// - ReferencePlugin (995): @path.to.value - Internal references
// - ConfigValuePlugin (994): Config-specific value resolution
```

**When to use the Facade:**

- You want a quick, fully-featured configuration setup
- You need environment variables, references, imports, and includes
- You prefer convention over configuration
- You're starting a new project and want sensible defaults

**When to use other factories:**

- `StaticFactory`: Simple use cases without plugins
- `Factory`: Custom plugin configuration and advanced control

Advanced Features
-----------------

[](#advanced-features)

### Importing Configurations

[](#importing-configurations)

```
// Import from another file
$config->import('additional-config.json', parse: true);

// Import to a specific path
$config->importTo('database-config.json', 'database', parse: true);
```

### Configuration Nodes

[](#configuration-nodes)

```
// Get a configuration subtree as a new Config instance
$dbConfig = $config->node('database');
echo $dbConfig->get('host'); // Direct access without 'database.' prefix
```

### Exporting

[](#exporting)

Export configuration to files with automatic format detection based on file extension:

```
// Export to JSON (auto-detected from .json extension)
$config->export('output/config.json');

// Export to PHP array (auto-detected from .php extension)
$config->export('output/config.php');
```

The format is automatically determined by the Resource adapter system based on the file extension.

Examples
--------

[](#examples)

### Multi-Environment Configuration

[](#multi-environment-configuration)

```
{
  "app": {
    "name": "MyApp",
    "env": "@env(APP_ENV)",
    "debug": "@env(APP_DEBUG)"
  },
  "database": {
    "host": "@env(DB_HOST)",
    "port": "@env(DB_PORT)",
    "name": "@env(DB_NAME)"
  }
}
```

### Configuration with References

[](#configuration-with-references)

```
{
  "paths": {
    "root": "/var/www",
    "public": "@paths.root/public",
    "storage": "@paths.root/storage"
  }
}
```

### Importing Multiple Files

[](#importing-multiple-files)

```
{
  "@import": [
    "config/database.json",
    "config/cache.json",
    "config/services.json"
  ]
}
```

Development
-----------

[](#development)

### Requirements

[](#requirements)

- PHP 8.2 or higher
- Composer

### Dependencies

[](#dependencies)

- `concept-labs/arrays` - Array manipulation utilities

### Running Tests

[](#running-tests)

This package includes comprehensive test coverage using both PHPUnit and Pest:

```
# Run all tests
composer test

# Run only unit tests
composer test:unit

# Run only feature tests
composer test:feature

# Run tests with coverage
composer test:coverage
```

**Test Statistics:**

- 143 tests covering all functionality
- 259 assertions
- PHPUnit and Pest test styles
- Unit and integration tests

See [tests/README.md](tests/README.md) for detailed testing documentation.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/Concept-Labs/config/issues)
- **Documentation**: [Full Documentation](./docs)

Credits
-------

[](#credits)

Developed and maintained by [Concept Labs](https://github.com/Concept-Labs).

---

Made with care by Concept Labs

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance84

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 72.6% 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

Total

37

Last Release

117d ago

Major Versions

v0.0.1.2 → v1.0.02023-12-31

1.5.2.0 → 2.0.0.02025-07-15

PHP version history (4 changes)0.0.1PHP &gt;=8.0.0

v0.0.1.2PHP ^8.0

1.1.0PHP ^7.2|^7.4|^8.0|^8.2

1.5.0.1PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/39bcfd110a5cc1f2d7ff687193670d00133cf415ad2b9959afaff24ff1e564fd?d=identicon)[vgalitsky](/maintainers/vgalitsky)

---

Top Contributors

[![vgalitsky](https://avatars.githubusercontent.com/u/1241206?v=4)](https://github.com/vgalitsky "vgalitsky (85 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (32 commits)")

---

Tags

phpconfig

###  Code Quality

TestsPest

### Embed Badge

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

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

PHPackages © 2026

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