PHPackages                             switchbox/switchbox - 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. switchbox/switchbox

AbandonedArchivedLibrary

switchbox/switchbox
===================

Quick and extensible configuration library that can load and save in JSON, YAML, INI, and more

v0.1.1(12y ago)217[1 issues](https://github.com/sagebind/switchbox/issues)MPL-2.0PHPPHP &gt;=5.3.0

Since Mar 21Pushed 11y ago1 watchersCompare

[ Source](https://github.com/sagebind/switchbox)[ Packagist](https://packagist.org/packages/switchbox/switchbox)[ RSS](/packages/switchbox-switchbox/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Switchbox
=========

[](#switchbox)

[![Latest Stable Version](https://camo.githubusercontent.com/f01ab1161fd2742087542d6dd53667a271bbe52bd4ada33e081fc206ac126f45/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769746368626f782f737769746368626f782e7376673f7374796c653d666c6174)](https://packagist.org/packages/switchbox/switchbox)[![License](https://camo.githubusercontent.com/6a615134e9a15bbe1c7f739c318dfc0044aaa2d958c632eccd362ceb83102803/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769746368626f782f737769746368626f782e7376673f7374796c653d666c6174)](http://www.apache.org/licenses/LICENSE-2.0)[![Code Quality](https://camo.githubusercontent.com/2098ee80bf36080e11a9bf49068107b00ca4b716849287d7bf62c0f856162108/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f636f6465727374657068656e2f737769746368626f782e7376673f7374796c653d666c6174)](http://scrutinizer-ci.com/g/coderstephen/switchbox)[![Test Coverage](https://camo.githubusercontent.com/9795ee1f73dd16743c0ade9662f31b9bcec0370e8b808f671e1dae948d5c3ff3/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f636f6465727374657068656e2f737769746368626f782e7376673f7374796c653d666c6174)](http://scrutinizer-ci.com/g/coderstephen/switchbox)

Configuration files are a pretty basic, prevalent part of creating software, but PHP doesn't offer a very good toolbox for using them. Switchbox is meant to be that toolbox, to allow developers to quickly and painlessly integrate configuration files into PHP applications.

Switchbox can both load and save configuration from *any source* using an extensible provider architecture. Potential providers include INI, JSON, YAML, XML, and Java-style property files, as well as databases, registries, and any other source you could think of. Providers currently implemented include JSON, YAML, and plain PHP files.

Project status
--------------

[](#project-status)

Switchbox is currently in early development and is not yet production ready.

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

[](#installation)

The best way to install Switchbox is using [Composer](http://getcomposer.org). Just add Switchbox as a dependency to a project in your `composer.json` file:

```
{
    "require": {
        "switchbox/switchbox": "0.1.*"
    }
}
```

You can then install Switchbox using Composer:

```
$ composer install
```

Alternatively, you can add Switchbox as a dependency using the command line:

```
$ composer require switchbox/switchbox:0.1.*
```

Usage
-----

[](#usage)

The `Switchbox\Settings` class is used to manage a single configuration source. To create a `Settings` object, first create a provider object and pass it to the `Settings` constructor. The provider given will be used to load and save configuration data whenever `Settings::load()` or `Settings::save()` are called.

Below is an example of a very simple configuration file in [JSON](http://json.org):

```
{
    "greeting": "Hello",
    "world": "Earth"
}
```

We can use the above settings file with the following code:

```
use Switchbox\Settings;
use Switchbox\Providers\JsonProvider;

// create a settings object
$settings = new Settings(new JsonProvider('settings.json'));

// load config from provider
$settings->load();

// get the values of some properties
echo $settings->get('greeting').', '.$settings->get('world')."!\n";
```

The above code will display the following output:

```
Hello, Earth!

```

The same exact functionality could also be done using a [YAML](http://yaml.org) settings file:

```
# settings.yaml
greeting: Hello
world: Earth
```

We only have to tweak our original code to use the `Switchbox\Providers\YamlProvider` to load the file. The rest works just fine:

```
// ...
// create a settings object
$settings = new Settings(new YamlProvider('settings.yaml'));
// ...
```

Because the process of loading and saving configuration is decoupled from the `Settings` class, you can use any kind of source you want and use the same convenient API for all of them. All that is required is that the provider must implement the [`Switchbox\Providers\ProviderInterface`](src/Providers/ProviderInterface.php) interface, which just asks for `load()` and `save()` methods.

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

[](#documentation)

API documentation is available at .

Running tests
-------------

[](#running-tests)

You can run automated unit tests using [PHPUnit](http://phpunit.de) after installing dependencies:

```
$ vendor/bin/phpunit
```

Where to get help
-----------------

[](#where-to-get-help)

Need help? Just [send me an email](mailto:me@stephencoakley.com) with your questions. Be sure to add "Switchbox" to the message subject line so I know how I can help you out.

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

[](#contributing)

Want to help make Switchbox something usable for the future? Fork this repo and start coding. Switchbox's contribution model is currently very informal, so just submit a pull request. Pull requests will be reviewed and accepted if they fit the goal of the project. Be sure to contact Stephen Coakley () if you have any questions.

License
-------

[](#license)

Switchbox is licensed under the Apache License, Version 2.0 (Apache-2.0). See [LICENSE.md](LICENSE.md) for details.

Inspiration
-----------

[](#inspiration)

Switchbox was inspired by the usability of the .NET Framework's settings API and the flexibility of Apache's [Commons Configuration](http://commons.apache.org/proper/commons-configuration/) library.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.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 ~9 days

Total

2

Last Release

4429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83a82932c24c29b0e68201a359462dcd87f37b20976f1c48e827fd903ffa2284?d=identicon)[sagebind](/maintainers/sagebind)

---

Top Contributors

[![sagebind](https://avatars.githubusercontent.com/u/2192863?v=4)](https://github.com/sagebind "sagebind (71 commits)")[![CoderStephen](https://avatars.githubusercontent.com/u/133134204?v=4)](https://github.com/CoderStephen "CoderStephen (1 commits)")

---

Tags

configurationSettingsconfigini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/switchbox-switchbox/health.svg)

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

###  Alternatives

[hassankhan/config

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

97513.5M170](/packages/hassankhan-config)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

115254.9k1](/packages/dmishh-settings-bundle)[thewunder/conphigure

Framework Agnostic Configuration Library

3115.9k](/packages/thewunder-conphigure)[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)[selective/config

Config component, strictly typed

19185.8k3](/packages/selective-config)[davidepastore/slim-config

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

338.9k1](/packages/davidepastore-slim-config)

PHPackages © 2026

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