PHPackages                             davidepastore/slim-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. [Framework](/categories/framework)
4. /
5. davidepastore/slim-config

ActiveLibrary[Framework](/categories/framework)

davidepastore/slim-config
=========================

A slim middleware to read configuration from different files based on hassankhan/config

v0.1.2(4y ago)338.9k7[1 issues](https://github.com/DavidePastore/Slim-Config/issues)1GPL-2.0+PHPPHP &gt;=5.5.0

Since Mar 16Pushed 4y ago4 watchersCompare

[ Source](https://github.com/DavidePastore/Slim-Config)[ Packagist](https://packagist.org/packages/davidepastore/slim-config)[ RSS](/packages/davidepastore-slim-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (1)

Slim Framework Config
=====================

[](#slim-framework-config)

[![Latest version](https://camo.githubusercontent.com/1cde8dcd98b981cea2f5a3f6e322c1cda5832266feb2e890ee33ada578f8e0b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446176696465506173746f72652f536c696d2d436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/davidepastore/slim-config)[![Build Status](https://github.com/DavidePastore/Slim-Config/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/DavidePastore/Slim-Config/actions?query=workflow%3A%22Continuous+Integration%22)[![Coverage Status](https://camo.githubusercontent.com/de19fd68d6018cdebc46cbdc80efaebac6976ca75487a9c01b33751c4b257fb8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f446176696465506173746f72652f536c696d2d436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/Slim-Config/code-structure)[![Quality Score](https://camo.githubusercontent.com/b8181c6108eeb67c72c95f5d29d1f47120c9db95b3075ee6284a7aecfe4edd51/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646176696465706173746f72652f536c696d2d436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/Slim-Config)[![Total Downloads](https://camo.githubusercontent.com/c9c1881b91a976dd85fdf24aae4caa21c613d7c9e034dc7a35ba07710d706197/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646176696465706173746f72652f736c696d2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/davidepastore/slim-config)[![PSR2 Conformance](https://camo.githubusercontent.com/71a8354cd7a9e681fa2db33b9a0ff8262e4f2b82609f62f816a2de3da97b448a/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333038383133302f736869656c64)](https://styleci.io/repos/53088130/)

A file configuration loader that supports PHP, INI, XML, JSON, and YML files for the Slim Framework. It internally uses [hassankhan/config](https://github.com/hassankhan/config).

Install
-------

[](#install)

Via Composer

```
$ composer require davidepastore/slim-config
```

Requires Slim 3.0.0 or newer.

Usage
-----

[](#usage)

In most cases you want to register `DavidePastore\Slim\Config` for a single route, however, as it is middleware, you can also register it for all routes.

### Register per route

[](#register-per-route)

```
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register provider
$container['config'] = function () {
  //Create the configuration
  return new \DavidePastore\Slim\Config\Config('config.json');
};

$app->get('/api/myEndPoint',function ($req, $res, $args) {
    //Here you have your configuration
    $config = $this->config->getConfig();
    $secret = $config->get('security.secret');
})->add($container->get('config'));

$app->run();
```

### Register for all routes

[](#register-for-all-routes)

```
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register provider
$container['config'] = function () {
  //Create the configuration
  return new \DavidePastore\Slim\Config\Config('config.json');
};

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add($container->get('config'));

$app->get('/foo', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $secret = $config->get('security.secret');
});

$app->post('/bar', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $ttl = $config->get('app.timeout', 3000);
});

$app->run();
```

Where are the benefits?
-----------------------

[](#where-are-the-benefits)

The configuration is loaded from the filesystem only when the given route is called in the *per route* usage. In the other case (*all routes*) the config should be general and used in the whole routes, because it's read in every request.

Just the tip of the iceberg!
----------------------------

[](#just-the-tip-of-the-iceberg)

You can read the [hassankhan/config](https://github.com/hassankhan/config) documentation [here](https://github.com/hassankhan/config) for more info.

Testing
-------

[](#testing)

```
$ phpunit
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Davide Pastore](https://github.com/davidepastore)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~1100 days

Total

3

Last Release

1514d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11a9e9c18e06a1827a69e0b5e7c4644e1f937f70463ff88b25b76b172be5e769?d=identicon)[DavidePastore](/maintainers/DavidePastore)

---

Top Contributors

[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (24 commits)")[![jbulava](https://avatars.githubusercontent.com/u/533789?v=4)](https://github.com/jbulava "jbulava (1 commits)")

---

Tags

configinijsonmiddlewarephpslim-frameworkxmlyamlphpjsonmiddlewareframeworkconfigurationxmlconfigyamlslimini

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M353](/packages/php-curl-class-php-curl-class)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[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)

PHPackages © 2026

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