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

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

wpfulcrum/config
================

Fulcrum Config Module - a lean configuration component.

3.0.4(8y ago)03736MITPHPPHP ^5.6|^7

Since Nov 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/wpfulcrum/config)[ Packagist](https://packagist.org/packages/wpfulcrum/config)[ Docs](https://github.com/wpfulcrum/config)[ RSS](/packages/wpfulcrum-config/feed)WikiDiscussions develop Synced 3d ago

READMEChangelogDependencies (5)Versions (7)Used By (6)

Config Module
=============

[](#config-module)

[![Build Status](https://camo.githubusercontent.com/a734b4f231f7f9e533ea96c7333c200f46b6b576d287165e786fbe61772ba458/68747470733a2f2f7472617669732d63692e6f72672f777066756c6372756d2f636f6e6669672e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/wpfulcrum/config)[![Latest Stable Version](https://camo.githubusercontent.com/ec09c20662da914881e5d2b1eab40799835aad9c27bfc22828b631b718ea76ec/68747470733a2f2f706f7365722e707567782e6f72672f777066756c6372756d2f636f6e6669672f762f737461626c65)](https://packagist.org/packages/wpfulcrum/config)[![License](https://camo.githubusercontent.com/61857273c31ef370eb8dc3015e87abd8eae49bae9a0c68c3c981b77e2d652de4/68747470733a2f2f706f7365722e707567782e6f72672f777066756c6372756d2f636f6e6669672f6c6963656e7365)](https://packagist.org/packages/wpfulcrum/config)

The Fulcrum Config Module provides a runtime configuration component for your WordPress project. It's minimal and lean.

Using dependency injection via the `ConfigContract`, a PHP interface, you are able to inject a specific implementation's configuration for each object. Forget about hard-coding parameters, as these require you to change them for each implementation or project. Instead, abstract them into a configuration array and then load that file into `Config`, making your code more readable, reusable, testable, and maintainable.

Features
--------

[](#features)

This module provides a clean, reusable method of:

1. Abstracting all of your specific implementation's configuration parameters, organizing them in one file.
2. Converting the implementation's array into a `Config` object.
3. When you want a common set of defaults (such as for shortcodes, post types, taxonomies, widgets, and more), pass in the defaults. Bam, the module handles deeply merging those defaults with each of the implementations.
4. You can get one or more of the parameters when you need them using:
    - standard object notation, such as `$this->config->numOfPosts`
    - using the `get()` method with single or "dot" notation.
5. Pushing additional parameters into a single configuration.
6. and more.

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

[](#installation)

The best way to use this component is through Composer:

```
composer require wpfulcrum/config

```

"Dot" Notation
--------------

[](#dot-notation)

Like all of the Fulcrum modules, we borrow from Laravel's "dot" notation to access deeply nested array elements. What is "dot" notation? Great question.

Dot notation is a clever mechanism to access deeply nested arrays using a string of the keys separated by dots.

Here let me show you. Let's say you have a deeply nested array like this one:

```
$config = new Config([
	'autoload'  => true,
	'classname' => 'YourBrand\YourProject\Shortcode\QA',
	'config'    => [
		'shortcode' => 'qa',
		'view'      => YOURPLUGIN_PATH . 'src/Shortcode/views/qa.php',
		'defaults'  => [
			'id'         => '',
			'class'      => '',
			'question'   => '',
			'type'       => '',
			'color'      => '',
			'open_icon'  => 'fa fa-chevron-down',
			'close_icon' => 'fa fa-chevron-up',
		],
	],
]);

```

To get at shortcode's default open icon, you would do `$config->get('default.open_icon)`. Notice you using "dot" notation you are able to drill down into the array and select the open icon's value.

How? It uses the [Fulcrum Extender's DotArray module](https://github.com/wpfulcrum/extender). Seriously, the Array Module is an awesome PHP extender, making your life much easier when working with deeply nested array.

Common Basic Usage and Functionality
------------------------------------

[](#common-basic-usage-and-functionality)

### Creating a Configuration File

[](#creating-a-configuration-file)

Typically, you will create a PHP file that is stored in a `config/` folder within our theme or plugin. In that file, you'll build and then return an array of all the specific implementation's configuration parameters.

Let's use the configuration example from above, which is for a QA shortcode:

```
