PHPackages                             alopez/php-configuration-loader - 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. alopez/php-configuration-loader

ActiveLibrary

alopez/php-configuration-loader
===============================

A simple PHP Class which aims to make configuration files handling easier.

v1.0.0(9y ago)127GPL-3.0PHPPHP &gt;=7.0

Since Apr 5Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Asakuura/php-configuration-loader)[ Packagist](https://packagist.org/packages/alopez/php-configuration-loader)[ Docs](https://github.com/Asakuura/php-configuration-loader)[ RSS](/packages/alopez-php-configuration-loader/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (1)Used By (0)

Configuration Loader is a class allowing you to browse a config directory and easily get your PHP configuration files values.

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

[](#installation)

Just use the following command line:

```
composer require alopez/php-configuration-loader

```

Basic Usage
-----------

[](#basic-usage)

There are three classes to know in this package:

- `ConfigurationLoader`: the main class, that will load and return your data.
- `SingleConfiguration`: a simple container for your values.
- `GroupConfiguration`: a container which can be named and contain multiple SingleConfiguration objects.

### Configuration Objects

[](#configuration-objects)

Both Single and Group Configurations have two properties: `name` and `value`. The only difference between those two classes is that GroupConfiguration is made for containing multiple SingleConfiguration definitions, see example below:

```
    // A random configuration file lost in your directories

    $name = 'foo';
    $value = 'fooValue';

    return new \ConfigurationLoader\SingleConfiguration($name, $value);
```

If you have multiple settings (ex: many databases access), there will be an interest into declaring a GroupConfiguration:

```
    // Databases definitions

    use ConfigurationLoader\GroupConfiguration;
    use ConfigurationLoader\SingleConfiguration;

    $name = 'db';

    return new GroupConfiguration($name,
        [
            new SingleConfiguration('database1',
                [
                    'host' => 'bla',
                    'user' => 'bla',
                    'password' => 'bla',
                    'bla' => 'bla'
                ]
            ),
            new SingleConfiguration('database2',
                [
                    'host' => 'bla2',
                    'user' => 'bla2',
                    'password' => 'bla2',
                    'bla' => 'bla2'
                ]
            )
        ]
    );
```

### Configuration Loader

[](#configuration-loader)

The configuration loader can easily be declared without any parameters. You can specify your configuration directory, and precise a flag (true by default) to tell the instance to automatically analyze the entire directory. If this flag is set to "false", configuration directory's data will be available through `get()` method (see example below). Otherwise you'll have to load it through the `load` method.

Example with a SingleConfiguration instance:

```
    $loader = new \ConfigurationLoader\ConfigurationLoader($configPath, $lazyOrNot);

    // The path must be considering that the current directory is your conf folder,
    // You must not precise '.php' extension.
    $filepath = 'path/to/your/file/without/.extension';

    // If not lazy you have to load the file (it will also return the values you want to get)
    // Let's say you want to load the file containing our newly created 'foo' SingleConfiguration:
    $data = $loader->load($filepath);

    // will echo 'fooValue'
    var_dump($data);

    // Once data is already load you can use get in order to get the configuration
    // It also will return 'fooValue'
    $data = $loader->get('foo')
```

With a GroupConfiguration instance (assuming loader is already declared as lazy):

```
    $loader->load('dbconf');
    $data = $loader->get('db');

    var_dump($data);

    // var_dump will return a formatted array with the following format:
    array(
        'database1' => array(...),
        'database2' => array(...)
    )
```

**Notice**: If you declared the loader with the lazy flag on `true`, but still want to load data later, you can use the method `loadDirectory` which will load the directory specified in your constructor.

### Handling local files

[](#handling-local-files)

The loader is able to differentiate `.local.php` files from `.php`. If you create `foo.php` and `foo.local.php`, the `load` method will first take the `foo.local.php` content and ignore `foo.php`.

```
    // foo.php
    return new \ConfigurationLoader\SingleConfiguration('foo', 'foo');

    // foo.local.php
    return new \ConfigurationLoader\SingleConfiguration('foo', 'bar');

    // index.php
    $loader = new \ConfigurationLoader\ConfigurationLoader($configPath);
    $loader->load('foo');

    // will return 'bar'
    var_dump($loader->get('foo'));
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

3327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/091e1777f533d1a12c6f8115a1f0628cc3e8b5eb767a9656f409d8d14094b44e?d=identicon)[Asakuura](/maintainers/Asakuura)

---

Tags

confconfigurationloaderphpphp7settingsphpconfigurationloaderserviceconf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alopez-php-configuration-loader/health.svg)

```
[![Health](https://phpackages.com/badges/alopez-php-configuration-loader/health.svg)](https://phpackages.com/packages/alopez-php-configuration-loader)
```

###  Alternatives

[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[sandrokeil/interop-config

Provides interfaces and a concrete implementation to create instances depending on configuration via factory classes and ensures a valid config structure. It can also be used to auto discover factories and to create configuration files.

58446.7k34](/packages/sandrokeil-interop-config)[romanpitak/nginx-config-processor

Nginx configuration files processor.

7235.3k1](/packages/romanpitak-nginx-config-processor)

PHPackages © 2026

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