PHPackages                             jimbojsb/configulator - 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. jimbojsb/configulator

ActiveLibrary

jimbojsb/configulator
=====================

An extremely lightweight configuration and service manager

v0.3(12y ago)513.1k4[2 issues](https://github.com/jimbojsb/configulator/issues)[1 PRs](https://github.com/jimbojsb/configulator/pulls)MITPHP

Since Jul 21Pushed 10y ago2 watchersCompare

[ Source](https://github.com/jimbojsb/configulator)[ Packagist](https://packagist.org/packages/jimbojsb/configulator)[ RSS](/packages/jimbojsb-configulator/feed)WikiDiscussions master Synced 1mo ago

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

Configulator
============

[](#configulator)

[![Build Status](https://camo.githubusercontent.com/942103578dbbcec8773a68c26b4fc7d4718d26c5ac8a77270857ea43efbcfd74/68747470733a2f2f7472617669732d63692e6f72672f6a696d626f6a73622f636f6e666967756c61746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jimbojsb/configulator)

[![Code Climate](https://camo.githubusercontent.com/89f77c514cced4b13feb5f9dc00c2d10f4ca58c7b833656dca5d564ef84e6eab/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a696d626f6a73622f636f6e666967756c61746f722e706e67)](https://codeclimate.com/github/jimbojsb/configulator)

Configulator is a very lightweight configuation manager and service locator for PHP projects. It is designed to be somewhat of a poor man's dependency injection container in that the service factories are always passed the managed configuration options as well as the service factories themselves, such that one can achieve simple dependency resolution and configuration of common service needs, such as database connections.

Getting Configulator
--------------------

[](#getting-configulator)

Configulator requires [Composer](http://getcomposer.org) and does not provide it's own autoloader. It is available on Packagist [here](https://packagist.org/packages/jimbojsb/configulator). You'll be adding something similar to this to your composer.json file in your project:

```
"require": {
    "jimbojsb/configulator": "dev-master"
}
```

Usage
-----

[](#usage)

Configulator can be used in two ways. You can create a new instance of `Configulator\Manager` directly, and take responsiblity for passing the object around in your existing application code as you see fit and necessary.

```
// assume here you've at some point require composer's autoloader

use Configulator\Manager;
$configulator = new Configulator\Manager;
```

Alternatively, Configulator provides a global-namespaced singleton of the manager that will be available to your entire project. This is exposed via the Configulator() function, which will return the singleton `Configulator\Manager` instance;

```
$configulator = Configulator();
```

All of the remaining examples use this syntax, though the functionality is the same if you're using the raw manager instance yourself.

### Loading config options

[](#loading-config-options)

Configulator supports 4 ways to populate it's internal storage with configuration data. You can either directly pass an array of options, or you can load options from one of the following file formats:

- [PHP Array include](https://github.com/jimbojsb/configulator/blob/master/tests/resources/test_config.php)
- [JSON](https://github.com/jimbojsb/configulator/blob/master/tests/resources/test_config.json)
- [YAML](https://github.com/jimbojsb/configulator/blob/master/tests/resources/test_config.yml)

When loading from a file, you have the option of using "configuration profiles", which would like be tied to your environment, such as "production" or "development". All configuration file types support inheritance of other profiles defined within the file.

```
Configulator()->setOptions(['configItem1' => 'configValue1']);

// or

Configulator()->loadFile("/path/to/myconfig.yml", "production");
```

When using `Configulator()->loadFile()` the second argument is the configuration profile, which is optional. You would likely only use this if you had chosen to structure your config files to take advantage of inheritance. If you do have profiles in your config files and you do *NOT* pass a profile argument, you will be returned the entire option set contained within the file *WITHOUT* the inheritance resolved.

### Accessing config options

[](#accessing-config-options)

`Configulator\Manager` implements ArrayAccess, and all config options are available through array notation. However, all config options are immutable once loaded, so code which attempts to use array notation to set values back into Configulator will throw a `RuntimeException`.

```
$value = Configulator()["configItem1"];
```

### Service Factories

[](#service-factories)

Configulator also manages and locates services within your application. The primary reason to couple this with configuration management is that it becomes trivial to create and configure services with intimiate access to the config options.

Service factories can either be an instance of an object (not really a factory, since this assumes you've pre-bootstrapped this instance), or a callable which returns the service. Generally, this is going to be an anonymous function. If the factory is a callable, `Configulator\Manager` is passed as the last (usually only) argument to the callable, such that you have access to the entire config as well as the easy ability to resolve service dependencies.

Additionally, Configulator has the notion of shared and non-shared services. A shared service is a singleton instance of the service object which is lazy-instantiated on the first request for it and cached for future calls. A non-shared service returns a new instance from the factory callable on every request for it. If you register an pre-fabricated instance instead of a callable as a non-shared service, you will receive a clone of that instance upon request. Services default to shared.

Services are first registered with the `register()` method and then created and retrieved by calling the method corresponding to their name.

```
Configulator()->register('mongodb', function() {
    return new MongoClient;
});

$mongo = Configulator()->mongodb();

Configulator()->register('mailer', function($configulator) {
    $transport = Swift_SmtpTransport::newInstance($configulator["smtp_host"], $configulator["smtp_port"]);
    return Swif_Mailer::newInstance($transport);
}, false);

$mailer = Configulator()->mailer();
```

### Local Override Files

[](#local-override-files)

Often times, it may be necessary to use a local file that isn't committed into source control to override some existing values from the core file. Using a local file will override matching values from any location, regardless of environment. This override is processed before inheritance an environment settings are resolved.

Use the optional 3rd argument for `Configulator()->loadFile()` to pass a local file path.

```
Configulator()->loadFile('/path/to/myconfig.yml', 'development', '/path/to/local_myconfig.yml');
```

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

[](#contributing)

Pull requests are welcome, but should not materially expand the scope of the project.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

4675d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fff234ab9d8ee835e721f4594a9c6521ec0f244bfbd7e700a0d8902e5f22ed1e?d=identicon)[jimbojsb](/maintainers/jimbojsb)

---

Top Contributors

[![jimbojsb](https://avatars.githubusercontent.com/u/107836?v=4)](https://github.com/jimbojsb "jimbojsb (39 commits)")[![unstoppablecarl](https://avatars.githubusercontent.com/u/913047?v=4)](https://github.com/unstoppablecarl "unstoppablecarl (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[getkirby/cms

The Kirby core

1.5k535.5k350](/packages/getkirby-cms)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[neos/flow

Flow Application Framework

862.0M450](/packages/neos-flow)

PHPackages © 2026

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